Reputation: 1998
I'm using Get-WmiObject
to dynamically query an SCCM namespace using the following construct:
$wmi = Get-WmiObject -ComputerName <SCCM Server> -Namespace Root\SMS\SITE_<ID> -Query $query -Credential $credential
Is there a way to allow the Select-Object
details to be specified at runtime? I tried the following with no luck:
$properties = Read-Host 'Set Select-Object Properties'
...
$wmi | select $select | Export-Csv ${ENV:USERPROFILE}\Desktop\$filename.csv
All it does is return exactly what I typed into the second row of the CSV with no results. Whenever I hard code the properties into the select statement, it works without issues.
Here is a Gist with the full script signature
Upvotes: 0
Views: 81
Reputation: 4240
You need Properties to be an array. You could do this which would allow the user to specify either a space or comma separated list.
$properties = (Read-Host 'Set Select-Object Properties') -split ' +|, *'
Upvotes: 2