You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PnP PowerShell导出MS Planner Bucket ID至CSV遇数组显示异常

解决PnP PowerShell导出Planner Bucket ID到CSV时显示System.Object[]的问题

你遇到的System.Object[]是因为$bucketids是数组类型,Export-Csv无法直接将数组序列化为可读文本,只会输出其类型名称。下面提供两种可行的解决方式:

方案1:将Bucket ID数组转为逗号分隔的字符串(单条计划对应一行)

修改创建自定义对象的部分,用-join把数组拼接成可读性强的字符串:

$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
   $plannerName = Get-PnPPlannerPlan -Group $Group.groupname -Identity $Group.planTitle | Select-Object -ExpandProperty Title
   $bucketIds = Get-PnPPlannerBucket -Group $Group.groupname -Plan $Group.planTitle | Select-Object -ExpandProperty Id

   $newRow = [pscustomobject]@{
           GroupName = $groupname
           PlannerName = $plannerName
           BucketIds = $bucketIds -join ', '  # 将数组转为逗号分隔的字符串
   }
   $table.Add($newRow) | Out-Null 
}
$table | Export-Csv -Path "$filesystempath\Pull Plan IDs\output-buckets.csv" -NoTypeInformation

方案2:每个Bucket ID单独生成一行(更适合后续处理单个ID)

如果需要每个Bucket ID对应独立的表格行,遍历每个ID并单独添加到集合:

$table = [System.Collections.ArrayList]::new()
foreach ($Group in $Groups) {
   Connect-PnPOnline -Url $Group.siteurl -Interactive

   $groupname = Get-PnPMicrosoft365Group -identity $Group.groupname | Select-Object -ExpandProperty DisplayName
   $plannerName = Get-PnPPlannerPlan -Group $Group.groupname -Identity $Group.planTitle | Select-Object -ExpandProperty Title
   $bucketIds = Get-PnPPlannerBucket -Group $Group.groupname -Plan $Group.planTitle | Select-Object -ExpandProperty Id

   # 遍历每个Bucket ID,单独添加行
   foreach ($id in $bucketIds) {
       $newRow = [pscustomobject]@{
               GroupName = $groupname
               PlannerName = $plannerName
               BucketId = $id
       }
       $table.Add($newRow) | Out-Null 
   }
}
$table | Export-Csv -Path "$filesystempath\Pull Plan IDs\output-buckets.csv" -NoTypeInformation

额外优化建议

  • 将Connect-PnPOnline移到循环外,避免重复交互式登录(如果所有组都在同一个租户且权限覆盖);
  • 变量名保持大小写一致,原脚本中$group.groupname应改为$Group.groupname。

内容的提问来源于stack exchange,提问作者Justin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:29:55