Skip to content

Instantly share code, notes, and snippets.

@quonic
Last active April 28, 2017 13:33
Show Gist options
  • Select an option

  • Save quonic/c5d8f8950e06ccd5732327db97992d96 to your computer and use it in GitHub Desktop.

Select an option

Save quonic/c5d8f8950e06ccd5732327db97992d96 to your computer and use it in GitHub Desktop.
$StoredCredential = "$PSScriptRoot/Credential.xml"
if($Crediential){
$mycreds = $Crediential
Export-Clixml -Path $StoredCredential -InputObject $mycreds
}elseif($Username -and $Password){
$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)
Export-Clixml -Path $StoredCredential -InputObject $mycreds
}else{
if($PSScriptRoot -and $(Test-Path -Path $StoredCredential)){
$mycreds = Import-Clixml -Path $StoredCredential
}else{
$mycreds = Get-Credential -Message "Username and API Key as the APIKey"
Export-Clixml -Path $StoredCredential -InputObject $mycreds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment