Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetAutomationPSCredentialProxy ($Name) {
- #requires -module CredentialManagement
- try {
- Get-StoredCredentials -target $name -erroraction stop
- } catch [Management.Automation.RuntimeException] {
- $NotFoundErrorRegex = '-2147023728$'
- #Prompt to store if not found
- if ($PSItem -match $NotFoundErrorRegex) {
- $newCred = Get-Credential -UserName $name -Message 'Credential Not Found, please enter password to store it'
- Add-StoredCredentials -ErrorAction stop -UserName $Name -Password $newcred.GetNetworkCredential().Password
- return $newCred
- } else {
- write-error $PSItem
- }
- }
- }
- Set-Alias -Name 'Get-AutomationPSCredential' -Value 'GetAutomationPSCredentialProxy'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement