如何在PowerShell中的networking上列出所有计算机操作系统

我正在寻找一个脚本来显示我的名上的所有机器,主机名和操作系统版本。 我find了几个脚本,但是我find的脚本都不会做这两个脚本。

这是我发现的一个例子:

$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} 

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

获取操作系统版本 :

  Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap –Auto 

Get-ADComputer也会默认返回计算机名称。

不知道这是否正是你正在寻找,但它适用于我。 您需要知道您传入该函数的计算机名称。 它会给你在返回string的操作系统。 我相信它可以修改以适应其他需求。

 function global:Get-OSInfo { param([string]$computer) [string] $strReturn = '' if([string]::IsNullOrEmpty($computer) -eq $false) { # Create the connection to Active directory. $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $root = $dom.GetDirectoryEntry() $search = [System.DirectoryServices.DirectorySearcher]$root # Search the directory for our user. $search.Filter = "(&(objectclass=Computer)(sAMAccountName=$computer$))" $result = $search.FindOne() if ($result -ne $null) { $system = $result.GetDirectoryEntry() $strReturn = $system.Properties["operatingSystem"] } } return $strReturn }