Hi Rising Flight,
It seems like you're encountering an issue with converting the content of 'c:\windows\temp\pwd.txt' to a secure string. The ConvertTo-SecureString
cmdlet expects the input to be a secure string, and if the content of your text file is not in the correct format, it will throw an error.
Make sure that the content of 'c:\windows\temp\pwd.txt' is a secure string. If you have saved the password using ConvertTo-SecureString
previously, you should use ConvertTo-SecureString
when reading the password from the file.
Here's an example:
$un = "******@mydomain.com"
$pw = Get-Content 'c:\windows\temp\pwd.txt' | ConvertTo-SecureString
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $un, $pw
If the content of 'c:\windows\temp\pwd.txt' is not a secure string, you should use ConvertTo-SecureString
to convert the plain text password to a secure string before creating the PSCredential object.
$un = "******@mydomain.com"
$plainTextPassword = Get-Content 'c:\windows\temp\pwd.txt'
$securePassword = ConvertTo-SecureString -String $plainTextPassword -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $un, $securePassword
This way, you ensure that the content of the text file is correctly converted to a secure string before creating the PSCredential object.
Regards.