1

I have a power shell command line where i am trying to import a txt file filled with serial numbers (example. "123","456", etc.) into SCCM to create a device collection. I am trying to import within parameters so it only create 1 Query using List of Values, but I keep getting an error "A Positional paramter cannot be found that accepts argument .\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"`)""

Expected Results

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 ("9876","6543",12345")

Actual Results

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
Razo559
  • 23
  • 3

1 Answers1

0

$Process is being specified as .\Process.txt, which looks like it expands to '(C:\Users\Owner\Desktop\Process.txt)'. This is what you are passing to your membership query rule.

Try changing to

$process = Get-Content ".\Process.txt"

This will read the items in the file and pass that to the query

Shamus Berube
  • 466
  • 3
  • 12
  • Thank you, I feel like i'm getting closer, But now I am receiving this error – Razo559 Feb 13 '19 at 16:28
  • Add-CMDeviceCollectionQueryMembershipRule : A positional parameter cannot be found that accepts argument '"5CG4444","5CG1111"'. At C:\Users\Owner\Desktop\Add2Sccm_Works SerialNumber - Copy.ps1:43 char:1 + Add-CMDeviceCollectionQueryMembershipRule -Collection $collection -Ru ... + CategoryInfo : InvalidArgument: (:) [Add-CMDeviceCol...yMembershipRule], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Collections.Comman ds.AddDeviceCollectionQueryMembershipRuleCommand – Razo559 Feb 13 '19 at 16:32
  • What does your process.txt look like? Can you show the first few lines? – Shamus Berube Feb 13 '19 at 17:06
  • yea, the txt file looks like this "5CG4444","5CG1111","5CG3333" and so on – Razo559 Feb 13 '19 at 19:32
  • Does the error change if you specify "`($Process`)"` without the double quotes instead of "`("$Process"`)" – Shamus Berube Feb 13 '19 at 20:05