Last active
March 2, 2020 16:20
-
-
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
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
# 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 | |
} | |
} | |
} |
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
# 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