我有一个power shell命令行,我试图将填充了序列号的txt文件(例如“123”,“456”等)导入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_G_System_COMPUTER_SYSTEM_PRODUCT.ResourceId = SMS_R_System.ResourceId中的SMS_G_System_COMPUTER_SYSTEM_PRODUCT.IdentifyingNumber(“9876”,“6543”,12345“
实际结果
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
$ Process被指定为。\ Process.txt,看起来像是扩展为'(C:\ Users \ Owner \ Desktop \ Process.txt)'。这是您传递给您的会员资格查询规则的内容。
尝试改为
$process = Get-Content ".\Process.txt"
这将读取文件中的项目并将其传递给查询