SOLVED

Connect-PnPOnline credential: can it use SharePointOnlineCredentials object

%3CLINGO-SUB%20id%3D%22lingo-sub-78403%22%20slang%3D%22en-US%22%3EConnect-PnPOnline%20credential%3A%20can%20it%20use%20SharePointOnlineCredentials%20object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78403%22%20slang%3D%22en-US%22%3E%3CP%3E%24UserName%3D%22%3CUSERNAME%3E%22%3C%2FUSERNAME%3E%3C%2FP%3E%3CP%3E%24pwd%20%3D%22%3CPASSWORD%3E%22%3C%2FPASSWORD%3E%3C%2FP%3E%3CP%3E%24Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24UserName%2C(ConvertTo-SecureString%20%24pwd%20-AsPlainText%20-Force))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecan%20we%20use%20the%20above%20credentials%20inside%20the%20bracket%20below%3C%2FP%3E%3CP%3E%26nbsp%3BConnect-PnPOnline%20%E2%80%93Url%20%24SiteUrl%20%E2%80%93Credentials%20(Get-Credential)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78405%22%20slang%3D%22en-US%22%3ERe%3A%20Connect-PnPOnline%20credential%3A%20can%20it%20use%20SharePointOnlineCredentials%20object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78405%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20either%20do%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24cred%20%3D%20Get-Credential%20-UserName%20%24username%20-Message%20%22Please%20enter%20password%20for%20%24username%22%3C%2FPRE%3E%3CP%3Eor%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24encpassword%20%3D%20convertto-securestring%20-String%20%24password%20-AsPlainText%20-Force%0A%24cred%20%3D%20new-object%20-typename%20System.Management.Automation.PSCredential%20-argumentlist%20%24username%2C%20%24encpassword%3C%2FPRE%3E%3CP%3Eand%20then%20connect%20with%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EConnect-PnPOnline%20-Url%20%24destinationTenantUrl%20-Credentials%20%24cred%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

$UserName="<username>"

$pwd ="<password>"

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $pwd -AsPlainText -Force))

 

can we use the above credentials inside the bracket below

 Connect-PnPOnline –Url $SiteUrl –Credentials (Get-Credential)

1 Reply
Highlighted
Solution

You can either do this:

 

$cred = Get-Credential -UserName $username -Message "Please enter password for $username"

or this:

 

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

and then connect with:

 

Connect-PnPOnline -Url $destinationTenantUrl -Credentials $cred