Skip to content

Instantly share code, notes, and snippets.

@rezarahimian
Last active December 18, 2019 17:56
Show Gist options
  • Save rezarahimian/1a0dd65b6f11deade01a7250a7cdf03a to your computer and use it in GitHub Desktop.
Save rezarahimian/1a0dd65b6f11deade01a7250a7cdf03a to your computer and use it in GitHub Desktop.
#Exporting PSCredential to XML
$Password = ConvertTo-SecureString 'XXX' -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential('svc_prd', $Password)
$Credential | Export-Clixml -Path 'C:\PS\Cred.xml'
#Importing PSCredential from XML
#$Credential = [System.Management.Automation.PSCredential](Import-Clixml -Path 'C:\PS\Cred.xml')
#Converting password to PlainText (e.g., API Payload)
#$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment