【问题标题】:Get-WmiObject to combine to outputsGet-WmiObject 组合到输出
【发布时间】:2021-01-25 04:29:23
【问题描述】:

我正在执行以下脚本以获取 Skype for business 服务器的服务器补丁版本。

我需要作为服务器补丁名称、版本和计算机名的输出。

$x = Get-Content "E:\temp\servers.txt" 
foreach ($y in $x) 
{
Invoke-Command -ComputerName $y -scriptblock {Get-WmiObject -query ‘select name, version from win32_product’ | where {$_.name -like “*Skype for Business server 2015, core*”}} | Select-object name, Version, @{Name='ComputerName';Expression={$y}} | ft -AutoSize
}

但我收到如下输出

Name                                            Version      ComputerName   
----                                            -------      ------------   
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx

Name                                            Version      ComputerName   
----                                            -------      ------------   
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxxx

Name                                            Version      ComputerName   
----                                            -------      ------------   
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx



Name                                            Version      ComputerName   
----                                            -------      ------------   
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxx


Name                                            Version      ComputerName   
----                                            -------      ------------   
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx

我不需要在每一行输出中使用我的标题图块。有什么建议吗?

【问题讨论】:

  • 您好,您不必调用该命令。 Get-WmiObject 有自己的 -ComputerName 参数。此外,您需要做的是扩展属性。只是输出会有点棘手
  • @Abraham 你能帮我重写脚本行吗

标签: powershell get-wmiobject


【解决方案1】:
  • 您正在获取每台计算机的标题,因为选择 语句在 foreach 循环内。

  • Invoke-command 接受多个 计算机,因此您不需要 foreach 循环。

  • 使用服务器端过滤 在可能的情况下。

    $x = Get-Content "E:\temp\servers.txt" 
    Invoke-Command -ComputerName $x -scriptblock {Get-WmiObject -query "select name, version from win32_product where name like 'Skype for Business server 2015, Core%'"} | 
     Select-object PSComputerName,name, Version
    

未来:

  • 使用 Get-CimInstance,因为 Get-wmiobject 已被弃用。
  • 不要使用 win32_product,因为它可能会导致 msi 损坏。采用 而是注册表。

https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/find-installed-software

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2011-03-14
    • 2023-03-12
    • 2021-07-02
    相关资源
    最近更新 更多