0

I have inherited this script from the previous developer and I am having trouble executing query.

Any ideas how to fix this?

    $site = "https://site.sharepoint.com/sites/fulltest2"
    $listName = "Show Calendar"
    $user = "[email protected]"   
    $pwd =ConvertTo-SecureString "password" -AsPlainText -Force  

    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($site)
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$pwd)
    $ctx.Credentials = $credentials
    $siteColl = $ctx.Web
    $ctx.Load($siteColl)
    $ctx.ExecuteQuery()

    $list = $ctx.Web.Lists.GetByTitle($listName)
    $ctx.Load($list)
    $ctx.ExecuteQuery()

2 Answers 2

1

I have just tried the exact same script on one of my site's and it worked(Replaced Site URL, List name, ID, Password). Please make sure your Site URL, List name, ID, Password are correct. If MFA is enabled in your tenant make sure you are VPN'd in.

1

You have to invoke TLS 1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Past the code line in the firs line of PS script.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.