【问题标题】:Get OS Name of a Remote Computer with Powershell使用 Powershell 获取远程计算机的操作系统名称
【发布时间】:2021-10-31 00:50:54
【问题描述】:

我知道有很多命令可以通过 PowerShell 获取 Windows 版本,但我想获取远程计算机(在我的域中)的操作系统名称(例如可以是 Linux)。我如何在 PowerShell 中做到这一点?

【问题讨论】:

  • @Sceptalist 否。它只显示我本地计算机上的操作系统版本,而不是远程计算机上的。
  • 您将如何连接到远程非 Windows 机器?如果远程机器在域中没有计算机帐户怎么办? (您的问题比您想象的要复杂。)
  • 然后在远程计算机上使用 PSRemoting/Invoke 它 - 你可以使用 WMI 但它不会检索 Linux
  • @Bill_Stewart 每台远程机器在域中都有一个帐户,这是肯定的

标签: powershell operating-system


【解决方案1】:

#又快又脏

Get-WmiObject -Class win32_operatingsystem -Property * -ComputerName anyhost |格式列表标题、名称、版本

【讨论】:

    【解决方案2】:

    #quick and dirty for Active Directory

    Get-ADComputer -Filter * -Properties OperatingSystem   | select Name,OperatingSystem
    

    【讨论】:

      【解决方案3】:
      $ttl = Test-Connection $Computer -BufferSize 16 -Count 1 -ea 0 | select -exp ResponseTimeToLive
      
      if($ttl -lt 65){$system = "Linux"} elseif($ttl -gt 126){$system = "Windows"}
      

      【讨论】:

      • 作为参考,我在 PS 7 中遇到了 TTL 问题。我尝试使用 TTL,但并不总是 100%
      猜你喜欢
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      • 2021-12-12
      相关资源
      最近更新 更多