SHOW:
|
|
- or go back to the newest paste.
| 1 | #https://www.reddit.com/r/PowerShell/comments/4fp0ut/what_are_you_using_in_your_powershell_profile/ | |
| 2 | ||
| 3 | ## Create Credential Out-Files | |
| 4 | Function Set-CredentialFile {
| |
| 5 | Param ( | |
| 6 | [parameter(Position=0, ParameterSetName="PrivilegedAccount")] | |
| 7 | [switch]$PrivilegedAccount, | |
| 8 | [parameter(Position=0, ParameterSetName="CloudAccount")] | |
| 9 | [switch]$CloudAccount | |
| 10 | ) | |
| 11 | ||
| 12 | If ($PrivilegedAccount) {Read-Host -Prompt "Enter your privileged account password" -AsSecureString | ConvertFrom-SecureString | Out-File "$($env:userprofile)\filename_priv.txt"}
| |
| 13 | ElseIf ($CloudAccount) {Read-Host -Prompt "Enter your cloud admin account password" -AsSecureString | ConvertFrom-SecureString | Out-File "$($env:userprofile)\filename.txt"}
| |
| 14 | If (!$PrivilegedAccount -and !$CloudAccount) {
| |
| 15 | Write-Warning "You must use '-PrivilegedAccount' or '-CloudAccount' to update a credential file(s)." | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | ## Start Explorer As Admin | |
| 20 | Function Start-ExplorerAsAdmin {
| |
| 21 | $Credential = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList "domain\username",(Get-Content "$($env:userprofile)\filename_priv.txt" | ConvertTo-SecureString) | |
| 22 | Start-Process Explorer -LoadUserProfile -Credential $Credential | |
| 23 | } | |
| 24 | ||
| 25 | ## Start PowerShell As Admin | |
| 26 | Function Start-PowerShellAsAdmin {
| |
| 27 | $Credential = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList "domain\username",(Get-Content "$($env:userprofile)\filename_priv.txt" | ConvertTo-SecureString) | |
| 28 | Start-Process PowerShell -LoadUserProfile -Credential $Credential | |
| 29 | } | |
| 30 | ||
| 31 | ## Start PowerShell As Admin | |
| 32 | Function Start-ADUC {
| |
| 33 | Param ( | |
| 34 | [parameter(Position=0, ParameterSetName="AsAdmin")] | |
| 35 | [switch]$AsAdmin | |
| 36 | ) | |
| 37 | If ($AsAdmin) {
| |
| 38 | $Credential = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList "domain\username",(Get-Content "$($env:userprofile)\filename_priv.txt" | ConvertTo-SecureString) | |
| 39 | Start-Process powershell -Credential $Credential -ArgumentList "Start-Process -FilePath $env:SystemRoot\System32\mmc.exe -ArgumentList $env:SystemRoot\System32\dsa.msc -Verb RunAs" | |
| 40 | } | |
| 41 | Else {Start-Process dsa.msc}
| |
| 42 | } |