无法在cmd中通过管道传递cmdlet对象 [英] Unable to pipe cmdlet objects in cmd

查看:85
本文介绍了无法在cmd中通过管道传递cmdlet对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此powershell命令来获取特定的用户个人资料

i am using this powershell command to fetch a particular user profile

"Get-WmiObject -Win32_UserProfile类| Where-Object {$ _.LocalPath -eq'C:\ Users \ Pela'}""

"Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela'}"

但是当我通过调用powershell在cmd中使用相同的命令时无法将对象识别为内部或外部命令,可操作程序或批处理文件"

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'

我在cmd中运行的命令如下:-"powershell Get-WmiObject -Class Win32_UserProfile | Where-Object {$ _.LocalPath -eq'C:\ Users \ Pela'}""

The command i am running in cmd is as follows :- "powershell Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela'}"

我只需要从cmd运行此命令,我没有其他选择.所以请给我一个"Where-Object"的替代方法

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"

推荐答案

所以,请给我一个"Where-Object"的替代方法

powershell Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq 'C:\Users\Pela

您不需要其他选择.上面的命令失败,因为管道 | 是由 cmd 外壳而不是 PowerShell 解释的.

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.

如果您转义管道 ^ | ,则管道由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

示例:

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


进一步阅读

  • Windows CMD命令行的AZ索引-与Windows cmd行相关的所有内容的绝佳参考.
  • 语法-转义字符,分隔符和引号.

  • Further Reading

    • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
    • syntax - Escape Characters, Delimiters and Quotes.
    • 这篇关于无法在cmd中通过管道传递cmdlet对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆