如何将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
您正在使用自动管道变量,$_
而您的foreach循环中没有管道对象。只需使用$Computer
:
$Computers = C:\computers.CSV
ForEach ($Computer in $Computers) {
Get-CMUserDeviceAffinity -DeviceName $Computer.Name
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句