none
How to get all projects sites with PowerShell? RRS feed

  • שאלה

  • Hello, i trying to use the 2 dlls bellow to get the site url of each project:

    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files (x86)\Microsoft SDKs\Project 2013\REDIST\Microsoft.ProjectServer.Client.dll"

    I can get all the projects create in PWA, but the propertie ProjectSiteUrl is not loaded by default. I am able to load this propertie with javascript csom and c#, but i am failing to do in powershell. What am i missing? I tried in many ways, but a always get a error:

    $projContext.Load($projContext.Projects[0],"ProjectSiteUrl")
    

    $projContext.Load($projContext.Projects[0],ProjectSiteUrl)

    foreach($i in $projContext.Projects){
       $projContext.Load($i.ProjectSiteUrl)
       $projContext.ExecuteQuery()
    } 

    $projContext.Load($projContext.Projects,ProjectSiteUrl)

    $projContext.Load($projContext.Projects,c => c.Include(qr => qr.ProjectSiteUrl))

    $projContext.Load($projContext.Projects,c => c.IncludeWithDefaultProperties(pr => pr.CustomFields)


    יום שני 30 ספטמבר 2019 17:42

תשובות

  • Hello,

    I was able to do it with the Load-CSOMProperties.ps1 from Gary Lapointe (glapointe) from GitHub. 

    https://gist.github.com/glapointe/cc75574a1d4a225f401b#file-load-csomproperties-ps1


    Here is my example:

    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.ProjectServer.Client.dll")
    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.SharePoint.Client.Runtime.dll")
    
    $UserName = "xxx@test.com"
    $Password = Read-Host -Prompt "Enter password" -AsSecureString    
    $Url = "https://xxx.sharepoint.com/sites/pwa"
    
    $Context = New-Object Microsoft.ProjectServer.Client.ProjectContext($Url)
    $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password) #SecurePassword
    
    $projects = $Context.Projects
    $Context.load($projects)
    $Context.executeQuery()
    
    $projects | ForEach-Object {
        Load-CSOMProperties -object $($_) -propertyNames @("ProjectSiteUrl")
        $Context.ExecuteQuery()
        Write-Host $_.ProjectSiteUrl
    }
    Max

    יום ראשון 20 אוקטובר 2019 00:25

כל התגובות

  • Hello,

    I was able to do it with the Load-CSOMProperties.ps1 from Gary Lapointe (glapointe) from GitHub. 

    https://gist.github.com/glapointe/cc75574a1d4a225f401b#file-load-csomproperties-ps1


    Here is my example:

    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.ProjectServer.Client.dll")
    Add-Type -Path (Resolve-Path "C:\Users\xxx\Desktop\Microsoft.SharePoint.Client.Runtime.dll")
    
    $UserName = "xxx@test.com"
    $Password = Read-Host -Prompt "Enter password" -AsSecureString    
    $Url = "https://xxx.sharepoint.com/sites/pwa"
    
    $Context = New-Object Microsoft.ProjectServer.Client.ProjectContext($Url)
    $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password) #SecurePassword
    
    $projects = $Context.Projects
    $Context.load($projects)
    $Context.executeQuery()
    
    $projects | ForEach-Object {
        Load-CSOMProperties -object $($_) -propertyNames @("ProjectSiteUrl")
        $Context.ExecuteQuery()
        Write-Host $_.ProjectSiteUrl
    }
    Max

    יום ראשון 20 אוקטובר 2019 00:25