【问题标题】:How to find a file location by file name, and file name only, using get_ciminstance in powershell?如何在powershell中使用get_ciminstance通过文件名和文件名查找文件位置?
【发布时间】:2020-01-08 21:24:40
【问题描述】:

我正在尝试编写一个脚本,该脚本将在多台计算机上检索特定文件的属性。我正在使用 get-childitem 来执行此操作,直到我意识到只能在本地检索。我读过 get-ciminstance 可用于为远程机器执行此操作,但是,我看到的所有示例都使用完整路径来查找文件。我的脚本假定该位置可以在 C 驱动器上的任何位置,因此它仅根据文件名查找位置。到目前为止,我已经使用 get-ciminstance 尝试了几种代码变体,但都没有产生任何结果或查询结构错误。

这是我现在所拥有的,这是我认为最接近正确的,但我不确定:

Get-CimInstance -ComputerName $PC -ClassName CIM_DataFile | select Name | Where-Object { $_.Name -like  "install.properties"}

如果有人能指出我正确的方向,将不胜感激。谢谢。

【问题讨论】:

    标签: powershell file filter directory


    【解决方案1】:

    这是一个不错的链接。 https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/accessing-individual-files-and-folders-remotely-via-wmi 名称是完整路径,带有双反斜杠。过滤器语言类似于 sql。不能使用invoke-command?

    Get-CimInstance CIM_DataFile -Filter 'name = "c:\\users\\admin\\foo\\file.json"'
    

    【讨论】:

    • 感谢您的回复。我之前查看过该链接,但如果 Name 实际上是完整路径,那么我想我正在尝试做其他事情。由于文件路径未知,我需要使用文件的实际名称作为过滤器值。这可能吗?
    猜你喜欢
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    相关资源
    最近更新 更多