如何在Powershell中列出网络上的所有计算机操作系统

nat*_*ate 2 windows powershell domain query

我正在寻找一个脚本来显示我域中的所有机器、主机名和操作系统版本。我找到了一些脚本,但是我找到的脚本中没有一个可以同时执行这两项操作。

这是我发现的一个例子:

$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
  $colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
  {$objComputer = $objResult.Properties; $objComputer.name}
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何为powershell创建一个脚本来列出主机名和操作系统版本吗?

Hop*_*00b 9

获取操作系统版本

 Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap –Auto
Run Code Online (Sandbox Code Playgroud)

Get-ADComputer 默认情况下也返回计算机名称。