Reputation: 311
i am using this powershell command to fetch a particular user profile
"Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela'}"
But when i am using this same command in cmd by invoking powershell i am getting 'Where-Object is not recognized as an internal or external command,operable program or batch file'
The command i am running in cmd is as follows :- "powershell Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela'}"
I need to run this command from cmd only , i don't have any other options . So please give me an alternative to "Where-Object"
Upvotes: 2
Views: 2802
Reputation: 7921
powershell Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela
You don't need an alternative. The above command is failing because the pipe |
is being interpreted by the cmd
shell and not by PowerShell
.
If you escape the pipe ^|
then the piping is done by the PowerShell command as expected:
powershell Get-WmiObject -Class Win32_UserProfile ^| Where-Object {$_.LocalPath -eq 'C:\Users\Pela
Example:
F:\test>powershell Get-WmiObject -Class Win32_UserProfile ^| Where-Object {$_.LocalPath -eq 'C:\Users\DavidPostill'}
__GENUS : 2
__CLASS : Win32_UserProfile
__SUPERCLASS :
__DYNASTY : Win32_UserProfile
__RELPATH : Win32_UserProfile.SID="S-1-5-21-1699878757-1063190524-3119395976-1000"
__PROPERTY_COUNT : 12
__DERIVATION : {}
__SERVER : HAL
__NAMESPACE : root\cimv2
__PATH : \\HAL\root\cimv2:Win32_UserProfile.SID="S-1-5-21-1699878757-1063190524-3119395976-1000"
LastDownloadTime :
LastUploadTime :
LastUseTime : 20160822200129.697000+000
Loaded : True
LocalPath : C:\Users\DavidPostill
RefCount : 146
RoamingConfigured : False
RoamingPath :
RoamingPreference :
SID : S-1-5-21-1699878757-1063190524-3119395976-1000
Special : False
Status : 0
PSComputerName : HAL
Upvotes: 5