I have this PowerShell command:
Get-WmiObject -Query "Select * from CIM_DataFile Where Extension = 'ost'" |
Select-Object 'Name' |
Out-File C:\temp\ost.txt -Append
But I need to run it form a command prompt. I'm running it like this:
powershell.exe -ExecutionPolicy ByPass -Command "Get-WmiObject -Query "Select * from CIM_DataFile Where Extension = 'ost'" | Select-Object 'Name' | Out-File C:\temp\ost.txt -Append"
I'm getting this error:
Get-WmiObject : A positional parameter cannot be found that accepts argument '*'. At line:1 char:1 + Get-WmiObject -Query Select * from CIM_DataFile Where Extension = 'os ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand
How do I run this correctly?