This is from the PsCustom Object - Hitchikers GUID(e) to Automation
https://pscustomobject.github.io/powershell/howto/PowerShell-Create-Credential-Object/
$SecureStringPassword = ConvertTo-SecureString -String 'supersecretPassword' -AsPlainText -Force
[pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $SecureStringPassword)