unable to checkout project from Powershell
-
09-01-2021 - |
Frage
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()
}
}
Lösung
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()
Andere Tipps
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.
$existingProj.CheckOut()