I have a script that I want to ask the user who runs it to type in credentials - I don’t want to use pscredential - because it prompts for a username - which I DON’T need:
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline = $True, Mandatory = $False)]
[ValidateNotNull()]
[SecureString]$Credential,
)
if (-not $Credential) {
Write-Host "Please enter a password for the new user:"
$Credential = Read-Host -AsSecureString
}
Is this bad practice? Is there a better way to ask for credentials - the only ways I know are with pscredential which relies on Get-Credential. Is this not secure?