Created
April 7, 2012 09:37
-
-
Save tkmtmkt/2326853 to your computer and use it in GitHub Desktop.
Create Command Template with Credential
This file contains 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
Get-Credential | %{ | |
$user = $_.UserName | |
$pass = ConvertFrom-SecureString $_.Password | |
@" | |
<# | |
.SYNOPSIS | |
command with credential | |
#> | |
`$user = "$user" | |
`$pass = ConvertTo-SecureString "$pass" | |
`$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList `$user,`$pass | |
`$cmd = "cmd" | |
`$args = "/?" | |
Start-Process `$cmd `$args -Credential `$cred | |
# vim: set ft=ps1 ts=4 sw=4 et: | |
"@ | |
} | Out-File CommandTemplate.ps1 -Encoding OEM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment