I have written a powershell script to loop through all projects on our PWA instance and when it gets to a specific one I would like to check it out. the checkout() fails with an error:
format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
The script works perfect if I remove the CheckOut() line. Any ideas what I am doing wrong?
Add-Type -Path ‘C:\dll\microsoft.sharepointonline.csom.16.1.6906.1200\lib\net40-full\Microsoft.ProjectServer.Client.dll’ Add-Type -Path ‘C:\dll\microsoft.sharepointonline.csom.16.1.6906.1200\lib\net40-full\Microsoft.SharePoint.Client.dll’
$ PWAInstanceURL = “https://mycorp.sharepoint.com/sites/pwa” $ PWAUserName = “My User” $ password = “My Password” $ securePass = ConvertTo-SecureString $ password -AsPlainText -Force
$ projContext = New-Object Microsoft.ProjectServer.Client.ProjectContext($ PWAInstanceURL) [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$ spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($ PWAUserName, $ securePass);
$ projContext.Credentials = $ spocreds
$ projects = $ projContext.Projects
$ projContext.Load($ projects) $ projContext.ExecuteQuery()
Write-Host ‘Loaded ProjContext ‘ $ projects.Count
foreach ($ project in $ projects){
if ($ project.Name -eq "Name of Project to Stop On"){ Write-Host $ project.Name $ project.Id $ existingProj = $ projContext.Projects.GetByGuid($ project.Id) Write-Host 'New Proj ' $ existingProj $ newProj.CheckOut() }
}