Hi,
I am trying to create PowerShell code to allow me to automate logging in and updating a custom list on a SharePoint site. I've been looking at the forums and I found a way to log in to the site and get to the list, but I can't seem to get the import from csv and update the list. I was wondering if anyone else knows of a way and could help me out. Below I have listed my code as it currently is. Thank you!
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $siteUrl = “my website goes here" $username = "my email here" $password = Read-Host -Prompt "Enter password" -AsSecureString $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials = $credentials $web = $ctx.Web $lists = $web.Lists $ctx.Load($lists) $ctx.Load($web) $ctx.ExecuteQuery() Set-Variable -Name "clientContext" -Value $ctx -Scope Global Set-Variable -Name "rootSiteUrl" -Value $siteURL -Scope Global $listName = "Test List" $list = $clientContext.Web.Lists.GetByTitle($listName) #$list = $clientContext.Web.Lists.GetByTitle("Test List") $csv = Import-Csv "my website goes here" foreach($item in $csv){ $item["Title"] = $csv.Title $item["Created"] = $csv.Created $item["Text"] = $csv.Text $item["Level"] = $csv.Level $item.Update() $spoContext.Load($item) $spoContext.ExecuteQuery(); }