我有一个Power Shell命令行,我试图在其中将填充有序列号(例如“ 123”,“ 456”等)的txt文件导入SCCM以创建设备集合。我正在尝试在参数中导入,因此它仅使用值列表创建1个查询,但我不断收到错误消息“找不到接受参数。\ process.txt的位置参数”
$Process = ".\process.txt
Add-CMDeviceCollectionQueryMembershipRule -Collection $collection -RuleName "Membership $collectionName" -QueryExpression "select * from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM_PRODUCT on SMS_G_System_COMPUTER_SYSTEM_PRODUCT.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM_PRODUCT.IdentifyingNumber in "`("$Process"`)""
预期结果
从SMS_R_System内部选择*,在SMS_G_System_COMPUTER_SYSTEM_PRODUCT上的SMS_G_System_COMPUTER_SYSTEM_PRODUCT
实际结果
Add-CMDeviceCollectionQueryMembershipRule : A positional parameter cannot be found that accepts argument
'(C:\Users\Owner\Desktop\Process.txt)'.
At C:\Users\Owner\Desktop\Add2Sccm_Works SerialNumber - Copy.ps1:42 char:1
+ Add-CMDeviceCollectionQueryMembershipRule -Collection $collection -Ru ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-CMDeviceCol...yMembershipRule], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Collections.Comman
ds.AddDeviceCollectionQueryMembershipRuleCommand
答案 0 :(得分:0)
$ Process被指定为。\ Process.txt,看起来它扩展为'(C:\ Users \ Owner \ Desktop \ Process.txt)'。这就是您要传递给成员资格查询规则的内容。
尝试更改为
$process = Get-Content ".\Process.txt"
这将读取文件中的项目并将其传递给查询