列出域中远程计算机上的硬盘信息(List hard Disk Information on remote computers within a domain)

编程入门 行业动态 更新时间:2024-10-10 12:24:51
列出域中远程计算机上的硬盘信息(List hard Disk Information on remote computers within a domain)

我正在尝试获取硬盘信息列表。 目前我只希望列表显示每台计算机包含的硬盘的型号。

我有以下

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | Select model | Export- CSV "C:\Temp\DiskDrives\Machines.csv"

computers.txt文件包含代码逐个执行的计算机列表。 上面的工作到它将列出它可以找到一台机器的驱动器,但csv文件格式不太好。

可以格式化csv以包含来自txt文件的计算机名称吗? 也只挑出硬盘,而不是USB,SD设备等?

欣赏任何想法/建议。

非常感谢,克里斯

I am trying to get a list of hard disk information. At the moment I would only want the list to show the model of the hard disk that each computer contains.

I have the below

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | Select model | Export- CSV "C:\Temp\DiskDrives\Machines.csv"

The computers.txt file contains a list of computers that the code goes through one by one. The above works to a point it will list the drives that it can find for a machine but the csv file is not formatted too well.

Can the csv be formatted to include the computer name from the txt file? also to only pick out hard disks and not usb, sd devices etc?

Appreciate any thoughts / advice.

Many Thanks, Chris

最满意答案

只需选择SystemName属性,就可以得到像这样的结果。

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | ` Select SystemName,model >SystemName Model Size(GB) ---------- ----- -------- BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH JetFlash Transcend 32GB USB Device 29 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795 BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH JetFlash Transcend 32GB USB Device 29 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795

只要对多台计算机运行WMI查询,您也可以获得SystemName参数,这样可以轻松实现!

请注意,在上面的结果中,我有一个名为Transcend的小驱动器,它是一个32 GB的USB 3 FlashDrive。 你提到只想包含Fixed磁盘,而不是USB,所以为此我们只需在Where声明中添加如下内容:

PS C:\> Get-WMIObject win32_diskdrive -ComputerName behemoth,localhost | Where-Object MediaType -eq 'Fixed hard disk media' | Select SystemName,Model >SystemName Model Size(GB) ---------- ----- -------- BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795 BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795

奖励点数,如果你想以GB为单位显示磁盘的大小,把你的select语句改成这个,它使用一个计算的属性来创建一个名为Size(GB)的新列,并用$ _.Size属性除以1GB整数(整数)格式:

Select SystemName,Model,@{Name='Size(GB)';Exp={$_.Size /1gb -as [int]}}`

完成单线

只需将您的Export-CSV添加到管道的末尾,就可以像这样完成一行,这样可以为您提供所需的结果:

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | Where-Object MediaType -eq 'Fixed hard disk media' | Select SystemName,Model,@{Name='Size(GB)';Exp={$_.Size /1gb -as [int]}} | Export- CSV "C:\Temp\DiskDrives\Machines.csv"

啊,PowerShell的力量。

Just pick out the SystemName property as well, and you'll get a result like this.

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | ` Select SystemName,model >SystemName Model Size(GB) ---------- ----- -------- BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH JetFlash Transcend 32GB USB Device 29 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795 BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH JetFlash Transcend 32GB USB Device 29 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795

As soon as you run a WMI query against more than one machine, you also get the SystemName parameter too, which makes this easy!

Note that in my above result, I've got a small drive called Transcend, which is a 32 GB USB 3 FlashDrive. You mentioned wanting to include only Fixed disks, not USB, so to do that we just add in a Where Statement, like this:

PS C:\> Get-WMIObject win32_diskdrive -ComputerName behemoth,localhost | Where-Object MediaType -eq 'Fixed hard disk media' | Select SystemName,Model >SystemName Model Size(GB) ---------- ----- -------- BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795 BEHEMOTH OCZ-VERTEX PLUS R2 58 BEHEMOTH INTEL SSDSC2CT180A3 168 BEHEMOTH SAMSUNG HD103SJ 932 BEHEMOTH OCZ-VERTEX 60 BEHEMOTH ST3000DM001-1CH166 2795

Bonus points, if you want to show the size of the disk in GB, change your select statement to this, which uses a calculated property to make a new column called Size(GB) and populate it with the $_.Size property divided by 1GB in integer (whole number) form :

Select SystemName,Model,@{Name='Size(GB)';Exp={$_.Size /1gb -as [int]}}`

Completed One-Liner

Simply add your Export-CSV to the end of the pipeline to have a completed one- liner like this which should give you the results you're looking for:

Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | Where-Object MediaType -eq 'Fixed hard disk media' | Select SystemName,Model,@{Name='Size(GB)';Exp={$_.Size /1gb -as [int]}} | Export- CSV "C:\Temp\DiskDrives\Machines.csv"

Ahh, the Power of PowerShell.

更多推荐

本文发布于:2023-08-05 14:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435167.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机上   硬盘   信息   List   hard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!