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


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

The 'format-default' error message means that PowerShell encountered an error trying to print the output to the console. To avoid this try storing the output of CheckOut() in a junk variable:

$gulp = $project.CheckOut()
  • Wow, brilliant. Thank you for the answer. Not obvious at all from the error. – Mark Feb 20 '18 at 15:05

It looks like permission issue. Can you please include the user(User being used to run the code) in Administrator group and try?


Isn't it should be?It don't see initialization of $newProj in your existing code.

  • Ha, you are right, but this was not the problem. The same thing happens when I use $existingProj or $project. – Mark Feb 19 '18 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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