如何將CSV文件的對象傳送到Get-CMUserDeviceAffinity的DeviceName參數中?如何檢索計算機的主要用戶列表
我有一個電腦列表。我想爲此列表中的每臺計算機生成一個主要用戶列表。我正在使用PowerShell和SCCM模塊,到目前爲止,我嘗試了一個單線程以及更羅嗦一些無濟於事的東西。
一行代碼失敗:
Import-CSV C:\temp\computerlist.csv | Get-CMUserDeviceAffinity -DeviceName $($_.Name)
腳本失敗:
$Computers = C:\computers.CSV
ForEach ($Computer in $Computers) {
Get-CMUserDeviceAffinity -DeviceName $_.Name
兩者的結果失敗:
Cannot validate argument on parameter 'DeviceName'. The argument is null or empty. Provide
an argument that is not null or empty, and then try the command again.
At line:1 char:77
+ ... p\computerlist.csv | Get-CMUserDeviceAffinity -DeviceName $($_.Name)
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-CMUserDeviceAffinity], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ConfigurationManagement.Cmdlets.Collections.C
ommands.GetUserDeviceAffinityCommand
'Import-CSV C:\ temp \ computerlist.csv | ForEach-Object {Get-CMUserDeviceAffinity -DeviceName $ _。Name}' – sodawillow