【问题标题】:How do I include computername in output如何在输出中包含计算机名
【发布时间】:2013-09-05 15:43:07
【问题描述】:

PS新手在这里...

如何让远程计算机名称出现在输出中?

$computer = "PC3090-121","APCD02" 
Get-WmiObject Win32_Printer -ComputerName $computer |
  Select-Object SystemName,Name,Local |
  Format-Table -AutoSize

我尝试在 Select 和 format-table -properties 中包含 -computername, computername, %computername% - 不高兴...

我的搜索结果为空,或者我无法理解。

------------------ 答案:

$computer = "PC3090-121","APCD02" 
Get-WmiObject Win32_Printer -ComputerName $computer |
  Select-Object  __Server, Name, Local |
  Format-Table -AutoSize

【问题讨论】:

    标签: powershell wmi wmi-query


    【解决方案1】:

    简单点怎么样

    Get-WmiObject Win32_Printer -ComputerName $computer |
      Select-Object SystemName,Name,Local |
      Format-Table -AutoSize
    

    结果对象上没有computername 属性,也没有%computername% 属性。存在的是SystemName

    【讨论】:

    • SystemName 返回打印机/打印服务的主机名。如果远程 PC 使用打印服务器,则返回打印服务器主机的名称。
    • __SERVER 那么,也许吧。否则,您可以围绕调用循环:foreach ($c in $computer) { gwmi Win32_printer -computername $c | select @{l='ComputerName';e={$c}},Name,Local } 或类似的东西。
    • 您可以使用 Format-List -Force * 或 (fl -fo *) 检查对象及其所有属性(和值)。这通常有助于找到您需要选择的属性。
    • @Joey 我们可以使用 $Env:ComputerName 变量吗?
    猜你喜欢
    • 2013-06-21
    • 1970-01-01
    • 2016-03-03
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多