Skip to content

Instantly share code, notes, and snippets.

@jplindgren
Last active October 13, 2016 18:34
Show Gist options
  • Save jplindgren/a3aefc76b1667e4fefa6a47f9974974e to your computer and use it in GitHub Desktop.
Save jplindgren/a3aefc76b1667e4fefa6a47f9974974e to your computer and use it in GitHub Desktop.
My Powershell Profile
# 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