Last active
October 13, 2016 18:34
-
-
Save jplindgren/a3aefc76b1667e4fefa6a47f9974974e to your computer and use it in GitHub Desktop.
My Powershell Profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if Running as Admin | |
$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") | |
if (-not $IsAdmin) { | |
if ($MyInvocation.ScriptName -ne "") { | |
try { | |
Write-Host "Relanuching Script as Admin" | |
$arg = "-file `"$($MyInvocation.ScriptName)`"" | |
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList $arg -ErrorAction 'stop' | |
} catch { | |
Write-Warning "Error - Failed to restart script with runas" | |
break | |
} | |
} else { | |
try | |
{ | |
Write-Host "Relanuching Shell as Admin" | |
Start-Process "$psHome\powershell.exe" -Verb Runas -ErrorAction 'stop' | |
} catch { | |
Write-Warning "Error - Failed to restart script with runas" | |
break | |
} | |
} | |
Write-Host "Exiting" | |
Stop-Process -Id $PID | |
} | |
# Add Aliases | |
new-item alias:np -value "C:\Program Files (x86)\Notepad++\notepad++.exe" | |
new-item alias:chrome -value "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" | |
new-item alias:subl -value "C:\Program Files\Sublime Text 3\sublime_text.exe" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment