Skip to content

Instantly share code, notes, and snippets.

@tkmtmkt
Created April 7, 2012 09:37
Show Gist options
  • Save tkmtmkt/2326853 to your computer and use it in GitHub Desktop.
Save tkmtmkt/2326853 to your computer and use it in GitHub Desktop.
Create Command Template with Credential
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