Get-MsolDevice RegisteredOwners导出到CSV失败



我写了一个简单的脚本,试图使用来自列中包含ObjectID的源CSV文件的输入,然后导出以下信息;使用Get-MsolDevice命令的DisplayNameDeviceTrustTypeRegisteredOwnersApproximateLastLoginTimeStamp。这是我目前掌握的代码:

Connect-MsolService
Connect-AzureAD
Get-AzureADDevice -All $True | Select ObjectID | Export-Csv "C:tempProjectIntuneDevicesAllAADObjectIDs.csv" -noType
$allobjects = Import-Csv "C:tempProjectIntuneDevicesAllAADObjectIDs.csv"
ForEach ($line in $allobjects)
{
Get-MsolDevice -ObjectID $line.ObjectId | Select DisplayName,DeviceTrustType,RegisteredOwners,ApproximateLastLogonTimestamp| Export-Csv -Path "C:tempProjectIntuneDevicesFinal.csv" -Append -NoTypeInformation
}

问题是,当我打开Final.csv时,RegisteredOwners的条目显示为System.Collections.Generic.List`1[System.String]

当我只是从终端运行命令而不导出到CSV时,屏幕上会显示oputput,它看起来很好,我会看到RegisteredOwner列在大括号中,如{username@domain.org}

我读到这是因为RegisteredOwners的输出是一个列表项,而不是像其他输出那样的简单文本,但我在内联转换它时花了很多时间。我试过插入之类的东西

Select -Property DisplayName,@{ n='RegisteredOwners'; e={ $_.RegisteredOwners -join ';' } }

但无论我尝试过什么变化,运行过程中都会出现错误。

如果有任何帮助,我将不胜感激,因为我已经搜索并尝试了多种解决方案,但都不适合我。TIA-

感谢你把我推向正确的方向Bender,事实证明我一定有一些不理解的语法错误。这是最后的代码,它正在按预期工作。

## Script to collect all AzureAD registered devices, their trust type, and their owner.
## Connect to AzureAD and MSOL
Connect-MsolService
Connect-AzureAD
## Get all devices filtering their ObjectID
Get-AzureADDevice -All $True | Select ObjectID | Export-Csv "C:tempProjectIntuneDevicesAllAADObjectIDs.csv" -noType
## Create the variable from the expoted Csv
$allobjects = Import-Csv "C:tempProjectIntuneDevicesAllAADObjectIDs.csv"
## Create a new file using Column 1 of allobjects.csv entries to suss the information required for each device
ForEach ($line in $allobjects)
{
Get-MsolDevice -ObjectID $line.ObjectId | Select DisplayName,DeviceTrustType,@{ n='RegisteredOwners'; e={ $_.RegisteredOwners -join ';' } },ApproximateLastLogonTimestamp | Export-Csv -Path "C:tempProjectIntuneDevicesFinal.csv" -Append -NoTypeInformation
}

最新更新