Skip to content

Instantly share code, notes, and snippets.

@jkavanagh58
Created March 29, 2017 11:08
Show Gist options
  • Save jkavanagh58/dceb9d9ae0535de68ba2d3aaa0ea8cca to your computer and use it in GitHub Desktop.
Save jkavanagh58/dceb9d9ae0535de68ba2d3aaa0ea8cca to your computer and use it in GitHub Desktop.
Function Publish-admcred {
Begin{
$path = "$home\Desktop\mycred.json"
# Remove existing cred file if exists
if (test-path $path){Remove-Item $path -force}
}
Process{
$cred = Get-Credential
$cred |
Select Username,@{n="Password"; e={$_.password | ConvertFrom-SecureString}} |
ConvertTo-Json |
Set-Content -Path $path -Encoding UTF8
}
}
Function set-admcreds {
Begin{$path = "$home\Desktop\mycred.json"}
Process{
$o = Get-Content -Path $path -Encoding UTF8 -Raw | ConvertFrom-Json
$cred = New-Object -TypeName PSCredential $o.UserName, ($o.Password | ConvertTo-SecureString)
}
End{Return $cred}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment