#Let the user fill in their admin url, username and password $adminUrl = Read-Host "Enter the Admin URL of 0365 (eg. https://-admin.sharepoint.com)" $userName = Read-Host "Enter the username of 0365 (eg. admin@.onmicrosoft.com)" $password = Read-Host "Please enter the password for $($userName)" -AsSecureString $credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $password $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password) #connect to to Office 365 try{ Connect-SPOService -Url $adminUrl -Credential $credentials write-host "Info: Connected to Office 365 Succesfully " -foregroundcolor green } catch{ write-host "Error: Could not connect to Office 365" -foregroundcolor red } $siteUrl = Read-Host "Enter the Site URL" $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $ctx.Credentials = $SPOCredentials $ctx.Load($ctx.Web.Lists) $ctx.Load($ctx.Web) try { $ctx.ExecuteQuery() $_lists = $ctx.Web.Lists $_list = $_lists.GetByTitle("Documents") $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery() $items = $_list.GetItems($qry) $ctx.Load($items) $ctx.ExecuteQuery() Write-Host "Retreving Number of items : " $items.Count -foregroundcolor green foreach($listItem in $items) { Write-Host "Updating value for Lookup field" $listItem["ProjectID"] = $listItem["TempProjectID"] # Update Field Value Here $listItem.Update(); $Ctx.ExecuteQuery(); Write-Host "Updated." } } catch { $ErrorMessage = $_.Exception.Message write-host "Error : " $ErrorMessage -foregroundcolor red }