如何显示PowerShellinput作为输出的一部分

我正在尝试获取我的域上的计算机select的操作系统版本。 我创build了一个PowerShell命令,但是输出中缺less计算机名称。

这是命令
Get-ADComputer -Filter {name -Like "test"} | select "name" | foreach {$_.name} {Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_.name} | Select-Object Description, Caption,SevicePackMajorVersion | out-gridview

我试过添加addtionalselect对象,但它们都是空白的。 我想这是因为这个wmiobject根本不包含机器名称。

所以我的问题是,因为我用$_.namepipe道,它有可能也是输出的一部分。 我试过在select-object命令中使用($_.name)变体,但无济于事。

当您使用Get-WmiObject -Class Win32_OperatingSystem您可以看到使用命令Get-WmiObject -Class Win32_OperatingSystem | select-object * Get-WmiObject -Class Win32_OperatingSystem | select-object * 。 这样做会给你一个属性和值的表。 可能对您有帮助的属性是PSComputerName属性。

所以像这样的东西应该包括你想要的细节。

 Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | select-object PSComputerName,Description,Caption,SevicePackMajorVersion