Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andreberg/1319a23607258e871dd1169a81c71c74 to your computer and use it in GitHub Desktop.
Save andreberg/1319a23607258e871dd1169a81c71c74 to your computer and use it in GitHub Desktop.
[From WeakShell to PowerShell] Fixing the broken mess that is 'PowerShell' so it resembles something actually worthy of its name. #powershell #weakshell #fixes #tips
# Reconnect PSDrives for network connections when running with elevated privileges
$elevated = (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
if( $elevated ) {
net use | ?{ $_ -match ":\s+\\\\" -and !$_.StartsWith("Unavailable") } | %{
$tokens = $_.split(":")
$psdrivename = $tokens[0][$tokens[0].length-1]
$path = $tokens[1].trim().split(" ")[0].trim()
if( !(get-psdrive | ?{ $_.Name -eq $psdrivename } )) {
write-host ( "Restoring PSDrive for {0}: {1}" -f $psdrivename, $path )
new-psdrive $psdrivename FileSystem $path | out-null
}
}
}
# PowerShell 5 - add to $profile
function GoAdmin { Start-Process PowerShell –Verb RunAs }
# New-Item Alias:sudo -Value 'GoAdmin' | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment