powershellsharepointmicrosoft365microsoft-planner

Exporting list of specific Planner IDs to a CSV


We just deployed a specific M365 Planner to 385 SharePoint sites and I need to pull a csv of all those site names and the planner ID for that specific plan. I modified the script I used to add a Navigation link to each site to that plan, but exporting to a CSV is new territory so I'm not sure what I need to add to accomplish this.

The input CSV has 3 columns: SiteUrl, GroupName, PlanTitle

#Constants
$fileSystemPath = "C:\Users\xxxxx\xxxxxxxx\xxxx"
$Groups = Import-Csv -Path "$fileSystemPath\xxxx\input.csv"
$AdminUrl = "https://xxxxx-admin.sharepoint.com"

# Connect
Import-Module PnP.PowerShell
Connect-PnPOnline -Url $AdminUrl -Interactive

#Connect to Specific Site
foreach ($Group in $Groups) {
Connect-PnPOnline -Url $Group.siteurl -Interactive

# Pull Plan ID
$groupname = Get-PnPMicrosoft365Group -identity $Group.groupname | Select-Object -ExpandProperty DisplayName
$plannerid = Get-PnPPlannerPlan -Group $Group.groupname -Identity $Group.planTitle | Select-Object -ExpandProperty Id
}

Trying to export to a CSV with the group name, the plan name, and the plan id


Solution

  • Build a table and then use Export-Csv

    $table = [System.Collections.ArrayList]::new()
    foreach ($Group in $Groups) {
       Connect-PnPOnline -Url $Group.siteurl -Interactive
    
       # Pull Plan ID
       $groupname = Get-PnPMicrosoft365Group -identity $Group.groupname | Select-Object -ExpandProperty DisplayName
       $plannerid = Get-PnPPlannerPlan -Group $Group.groupname -Identity $Group.planTitle | Select-Object -ExpandProperty Id
    
       $newRow = [pscustomobject]@{
               Groupname = $groupname
               Plannerid = $plannerid
       }
       $table.Add($newRow) | out-null 
    }