1 2 |
$PROFILE C:\Users\MyUser\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
Creating Powershell Profile:
I say “profiles” as we have four profiles for each shell, but we won’t dive there. To create our profile, first we need to check if we have one already:
1 2 |
Test-Path $PROFILE False |
1 2 3 4 5 6 7 |
New-Item -Type File -Path $PROFILE -Force Directory: C:\Users\administrator\Documents\WindowsPowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 8/24/2018 11:36 AM 0 Microsoft.PowerShell_profile.ps1 |
1 2 |
Test-Path $PROFILE True |
1 2 3 4 5 6 |
## Open with Powershell ISE ISE $Profile ## Open with VS Code code $Profile ## open with notepad notepad $Profile |
Here some ideas to add to your profile:
1.Change the prompt, and add [Admin] if its elevated session:
1 2 3 4 5 6 7 8 9 10 |
function prompt { $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = [Security.Principal.WindowsPrincipal] $identity $(if (test-path variable:/PSDebugContext) { '[DBG]: ' } elseif($principal.IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) { "[ADMIN]: " } else { '' } ) + 'Saggie Haim PS ' + $(Get-Location) + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> ' } |
1 2 3 4 |
## Background Color $host.UI.RawUI.BackgroundColor = "black" ## Font color $host.UI.RawUI.ForegroundColor = "red" |
1 2 |
## Keep the default title and add my name $host.ui.RawUI.WindowTitle += " Saggie Haim" |
1 2 3 4 5 6 7 8 9 10 11 |
## Test-Port function function Test-Port { param ( [Parameter(Mandatory=$true)]$hostname, [Parameter(Mandatory=$true)]$port ) $result =(New-Object System.Net.Sockets.TcpClient($hostname, $port)).Connected return $result } ## Import Modules Import-Module ActiveDirectory |
