-1

I use this code to connect to the SharePoint online environment:

$username = "xxxxxxxx" 
$password = "xxxxxxxx"
$credential = New-Object System.Management.Automation.PSCredentials ($username, $password)
connect-pnponline -url xxxxxxxxxxxxxxx -Credential $credential

But I get the error: The remote server returned an error (403) Forbidden

How can I solve this?

Gr, P

1 Answer 1

3

PSCredential needs a SecureString rather than a plain string.

$encpassword = convertto-securestring -String $password -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword

connect-pnponline -url xxxxxxxxxxxxxxx -Credential $credential
2
  • Still receive the message: "the remote server returned an error (403) forbidden
    – user78519
    Jan 6, 2019 at 16:53
  • Got it :) the url wasn't correct. Thanks for the help.
    – user78519
    Jan 6, 2019 at 17:00

Your Answer

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