Scripts/Set-StoredCredential.ps1
Function Set-StoredCredential { If (!(Test-Path env:StoredCredentialPath)) { Write-Error "env:StoredCredentialPath does not exist. Run Set-StoredCredentialPath to setup" -ErrorAction Stop } $Credential = Get-Credential -Message "Enter a user name and password" $Credential.Password | ConvertFrom-SecureString | Out-File "$($env:StoredCredentialPath)\$($Credential.Username).cred" -Force # Return a PSCredential object (with no password) so the caller knows what credential username was entered for future recalls New-Object -TypeName System.Management.Automation.PSCredential($Credential.Username,(new-object System.Security.SecureString)) } |