【问题标题】:get-content issue获取内容问题
【发布时间】:2011-08-31 12:07:48
【问题描述】:

这里的基本 powershell 问题 - 我在 c:\temp\servers.txt 文件中有两台计算机,并且想要查询 tcpip.sys 文件版本信息。我不断收到错误,但它似乎也有效....

PS C:\Windows\System32\drivers> 获取内容 C:\temp\servers.txt | ForEach-Object (Get-ChildItem c:\windows\system32\drivers\tcpip.sys).Versioninfo

我收到以下错误:

ForEach-Object :> 无法绑定参数“进程”。无法转换“文件:
C:\windows\system32\drivers\tcpip.sys 内部名称:tcpip.sys 原始文件名:tcpip.sys.mui 文件版本:6.1.7600.16385 (win7_rtm.090713-1255) 文件描述:TCP/IP 驱动产品:
Microsoftr Windowsr 操作系统产品版本:6.1.7600.16385 调试:错误 已修补:错误 预发布:
错误 PrivateBuild:错误 SpecialBuild:错误语言:
英语(美国)"值类型 “System.Diagnostics.FileVersionInfo”键入 “System.Management.Automation.ScriptBlock”。在行:1 字符:49 + 获取内容 C:\temp\servers.txt | ForEach-对象

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您需要为每个服务器构建一个 UNC 路径:

    Get-Content C:\temp\servers.txt | ForEach-Object {
        (Get-ChildItem \\$_\c$\windows\system32\drivers\tcpip.sys).Versioninfo 
    }
    

    您还需要使用大括号,而不是括号,这就是您出错的原因。

    【讨论】:

    • 谢谢。当我执行代码时,我得到“文件版本”为 6.1.7600.138..... => 你能告诉我如何查看整个数字吗?我试过 fromat-table - 不太确定如何分隔结果 - 谢谢。
    • 您要显示哪个属性?您是否尝试过管道到格式列表?也可以试试: ...Versioninfo.FileVersion
    • 想通了 - 我使用了 Format-table -Autosize。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 2013-09-15
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多