ps/Modules/Alkami.PowerShell.Common/Public/Get-PasswordFromCredential.ps1
2023-05-30 22:51:22 -07:00

27 lines
798 B
PowerShell

Function Get-PasswordFromCredential {
<#
.SYNOPSIS
Gets the password from a credential object. Allows us to regulate when and where we get passwords and to pass credentials around the application.
.PARAMETER Credential
[PSCredential] The credential with username and password configured.
#>
[CmdletBinding()]
Param (
[Parameter(Position = 0, ValueFromPipeline = $true, Mandatory = $true)]
[PSCredential]$Credential
)
$tValue1 = $null
$bstr1 = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password);
try
{
$tValue1 = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr1)
}
finally
{
[Runtime.InteropServices.Marshal]::FreeBSTR($bstr1);
}
return $tValue1
}