Reputation: 1395
I have a server list that feeds into a function. I'm looking to query each machine and get an entire list of all files and folders. Id like to write a file to my local machine, the file name will be the the targets ip ($computer
) and append all the data from $userdata
into the file.
I keep getting the following error:
Get-WmiObject : Invalid query
foreach ($computer in $Server_List)
{
$userdata = Get-WmiObject -Credential -Computer $computer -Query "SELECT * from CIM_Data File WHERE Drive = 'C:'"
echo "$computer" | Out-File -FilePath $File_path + $computer +".txt" -Append $userdata
}
Upvotes: 0
Views: 501
Reputation: 200523
You have a spurious space in your query. The class name is CIM_DataFile
, not CIM_Data File
.
This:
"SELECT * from CIM_Data File WHERE Drive = 'C:'"
^
needs to look like this:
"SELECT * from CIM_DataFile WHERE Drive = 'C:'"
Upvotes: 1