I need to work with password in a powershell function. I am getting the password using the below code
$credentials=Get-Credential $p=$credentials.GetNetworkCredential().Password
This way the password is not visible while entering it and I can use it later inside the script.
However, later when I try to use it in the function, it does not work, says password is empty and even when I use Write-Host to display the contents of $p it does not work. I need to use this password multiple times in the function.