38 lines
1.4 KiB
PowerShell
38 lines
1.4 KiB
PowerShell
function Get-AlkamiCredential {
|
|
<#
|
|
.SYNOPSIS
|
|
Creates a new PSCredential object from a given username and password.
|
|
|
|
.DESCRIPTION
|
|
Get-AlkamiCredential will create a credential for you from a username and password, converting a password stored as a String into a SecureString.
|
|
|
|
.OUTPUTS
|
|
System.Management.Automation.PSCredential
|
|
|
|
.EXAMPLE
|
|
Get-AlkamiCredential -User ENTERPRISE\picard -Password 'earlgrey'
|
|
Creates a new credential object for Captain Picard.
|
|
#>
|
|
[CmdletBinding()]
|
|
[OutputType([Management.Automation.PSCredential])]
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingUserNameAndPassWordParams","")]
|
|
param(
|
|
[Alias('User')]
|
|
[string]
|
|
# The username. Beginning with Carbon 2.0, this parameter is optional. Previously, this parameter was required.
|
|
$UserName,
|
|
|
|
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
|
|
# The password. Can be a `[string]` or a `[System.Security.SecureString]`.
|
|
$Password
|
|
)
|
|
|
|
if($Password -is [string]) {
|
|
$Password = ConvertTo-SecureString -AsPlainText -Force -String $Password
|
|
} elseif($Password -isnot [securestring]) {
|
|
Write-Error "Value for Password parameter must be a [string] or [System.Security.SecureString]. You passed a [$($Password.GetType())]."
|
|
return
|
|
}
|
|
|
|
return New-Object 'Management.Automation.PsCredential' $UserName,$Password
|
|
} |