0

I would like to connect to Exchange online using my cred like this :

$Username = "[email protected]"
$PasswordPath = "C:\PowerShell\password.txt"

#Read the password from the file and convert to SecureString
$SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword

But I got an issue while tryign to Convert to String as Below

enter image description here

I used .txt file only

enter image description here

1
  • Add -Asplaintext -Force Commented Oct 31, 2020 at 20:27

1 Answer 1

2

Simply add -AsPlainText -Force

$Username = "[email protected]"
$PasswordPath = "C:\PowerShell\password.txt"

#Read the password from the file and convert to SecureString
$SecurePassword = Get-Content $PasswordPath | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.