通过PowerShell查询分区样式

avwztpqn  于 2023-08-05  发布在  Shell
关注(0)|答案(1)|浏览(141)

通常情况下,我一直通过我的脚本检查磁盘信息。我想在我的输出中添加PartitionStyle列,如下所示。我怎么能这么做呢?
我的输出:

Server Name   Drive Letter
-----------   ------------
server01        C:          
server01        D:          
server01        F:          
server01        K:

字符串
我想要的输出:

Server Name   Drive Letter  PartitionStyle
-----------   ------------  ------------
server01        C:               MBR
server01        D:               MBR
server01        F:               GPT
server01        K:               GPT


脚本:

$Servernames = "localhost"

$DiskReport = Get-WmiObject win32_logicaldisk `
-ComputerName $Servernames | Where {$_.Drivetype -eq "3"}  `
-ErrorAction SilentlyContinue

#create reports
$DiskReport | 
Select-Object @{Label = "Server Name";Expression = {$_.SystemName}},
@{Label = "Drive Letter";Expression = {$_.DeviceID}}

6uxekuva

6uxekuva1#

试试下面的脚本

Get-Disk | ForEach-Object {
    $disk = $_
    Get-Partition -DiskNumber $disk.Number | ForEach-Object {
        [PSCustomObject]@{
            DiskName = $disk.FriendlyName
            PartitionStyle = $disk.PartitionStyle
            DriveLetter = $_.DriveLetter
        }
    }
} | Where-Object { $_.DriveLetter } | Format-Table DiskName, DriveLetter, PartitionStyle

字符串
它确实告诉我在我的个人电脑上哪个驱动器是在哪个类型。
我的PS版本是

PSVersion                      5.1.19041.1682

相关问题