Private/ConvertTo-KB4SecureString.ps1
|
function ConvertTo-KB4SecureString { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNull()] [object] $InputObject ) if ($InputObject -is [securestring]) { return $InputObject } if ($InputObject -is [pscredential]) { return $InputObject.Password } if ($InputObject -is [string]) { if ([string]::IsNullOrWhiteSpace($InputObject)) { throw 'The KnowBe4 Reporting API token cannot be empty.' } return ConvertTo-SecureString -String $InputObject -AsPlainText -Force } throw "Unsupported API token type '$($InputObject.GetType().FullName)'. Provide a string, SecureString, or PSCredential." } |