dev*_*ted 1 powershell wmi list sccm import-csv
如何将CSV文件的对象传递到Get-CMUserDeviceAffinity的DeviceName参数?
我有一份电脑清单.我想为此列表中的每台计算机生成一个主要用户列表.我正在使用PowerShell和SCCM模块,到目前为止,我已经尝试了一个单行程以及更多罗嗦的东西无济于事.
One-Liner失败:
Import-CSV C:\temp\computerlist.csv | Get-CMUserDeviceAffinity -DeviceName $($_.Name)
Run Code Online (Sandbox Code Playgroud)
脚本失败:
$Computers = C:\computers.CSV
ForEach ($Computer in $Computers) {
Get-CMUserDeviceAffinity -DeviceName $_.Name
Run Code Online (Sandbox Code Playgroud)
结果都失败了:
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
Run Code Online (Sandbox Code Playgroud)
您正在使用自动管道变量,$_而您的foreach循环中没有管道对象.只需使用$Computer:
$Computers = C:\computers.CSV
ForEach ($Computer in $Computers) {
Get-CMUserDeviceAffinity -DeviceName $Computer.Name
}
Run Code Online (Sandbox Code Playgroud)