If you need a credential object, you can use Get-Credential to ask for credentials and use them in your script. But what if your only need a password? For example, when you need a password during installation of software. You’ll need a password in plain text most of the times. If you use Read-Host the password will be visible in your screen without the -AsSecureString parameter. The solution would be to save it as encrypted variable and decrypt it when you need it in a commandline or something:

$EncryptedPassword = Read-Host -AsSecureString -Prompt "What is your password?"

$DecryptedPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($EncryptedPassword))

I hope this helps you out! This blog is dedicated to Mr. Avinesh