返回列表 发帖

[系统增强] powershell 获取 磁盘信息

Function zFormat_sizereadable() {
param(
[int64]$num
)
$unit =@("B","K","M","G","T")
$i = 0
while ($num -gt 1024 ) { $i++; $num = $num /1024 }
return "{0} {1}" -f $num , $unit[$i]
}
function Init-Formatting()
{
$script:ftToTalSize = @{label="ToTalSize" ; expression={(zFormat_sizereadable($_.Size))} ; alignment = "right" }
$script:ftAllocatedSize = @{label="Allocated" ; expression={zFormat_sizereadable($_.AllocatedSize)} ; alignment = "right" }
$script:ftOffset = @{label="Offset" ; expression={ zFormat_sizereadable($_.Offset) } ; alignment = "right"}
$script:ftdDisk = @{label="Disk" ; expression={$_.Number}}
$script:ftdName = @{label="Name" ; expression={$_.FriendlyName}}
$script:ftdBus = @{label="Bus" ; expression={$_.BusType}}
$script:ftdMedia = @{label="Media" ; expression={$_.MediaType}}
$script:ftdStyle = @{label="Style" ; expression={$_.PartitionStyle}}
$script:ftpDisk = @{label="Disk" ; expression={$_.DiskNumber}}
$script:ftpPart = @{label="Part" ; expression={$_.PartitionNumber}}
$script:ftpPartType = @{label="PartType" ; expression={$_.Type}}
$script:ftpLetter = @{label="Ltr" ; expression={$L = ($_.DriveLetter).tostring();if ($L -match "[B-Z]") {$L} else {"-"}} ; alignment = "right" }
$script:ftpIsActive = @{label="Active" ; expression={ switch ($_.IsActive) { True {"A"} } } ; alignment ="center"}
$script:ftpIsBoot = @{label="Boot" ; expression={ switch ($_.IsBoot) { True {"B"} } }}
$script:ftpAB = @{label="A-B" ; expression={ switch ($_.IsActive) { True {"Active"} } ; switch ($_.IsBoot) { True {"Boot"} } }}
$script:ftFSLabel = @{label="FSLabel" ; expression={"'" + $_.FSLabel + "'"} ; alignment = "left" }
}
function Get-DiskPartitions() {
$diskPhy = @(Get-PhysicalDisk)
$disk = @( get-disk | sort-object { $_.DiskNumber } )
$disk | add-member -NotePropertyName "MediaType" -NotePropertyValue ""
foreach ( $x in $diskPhy ) {
$disk | Where-Object { if ($_.UniqueId -eq $x.UniqueId) {$_.MediaType = $x.MediaType} }
}
# $vol = @(Get-WmiObject win32_volume)
$vol =@(get-volume)
$part = @( Get-Partition | sort-object { $_.DiskNumber , $_.PartitionNumber } )
$part | add-member -NotePropertyName "FSType" -NotePropertyValue ""
$part | add-member -NotePropertyName "FSLabel" -NotePropertyValue ""
$part | foreach-object {
$pAccessPaths = $_.AccessPaths
$v =  $vol | Where-Object { $pAccessPaths -contains $_.Path }
if ( $v ) {
$_.FSType = $v.FileSystem
$_.FSLabel = $v.FileSystemLabel
}
}
return $disk,$part
}
function List-DiskPartitions() {
$disk | Format-Table $ftdDisk,$ftdBus,$ftdMedia,$ftdStyle,$ftToTalSize,$ftAllocatedSize,$ftdName
$part | Format-Table $ftpDisk,$ftpPart,$ftpLetter,FSType,$ftToTalSize,$ftpPartType, $ftFSLabel #,$ftpIsActive,$ftOffset
}
Init-Formatting
$disk,$part = Get-DiskPartitions
List-DiskPartitions
return
$dpv = read-host "select disk,part or vol"
$dpv = $dpv.trim()
switch -Regex ($dpv)
{
'^([c-z])$' { $selvol = $matches[1] ; break }
'(\d+)\D+(\d+)' { $seldisk = $matches[1] ; $selpart = $matches[2] ; break }
}
$part | where-object { ($_.DiskNumber -eq $seldisk -and $_.PartitionNumber -eq $selpart) -or ($_.DriveLetter -eq $selvol) } |
Format-Table $ftpDisk,$ftpPart,$ftpLetter,$ftpIsActive,$ftToTalSize,FSType,ftFSLabelCOPY

没有
Get-PhysicalDisk
get-disk
命令的系统用不了

TOP

bat批处理里面,如何调用代码并显示磁盘信息?谢谢

TOP

TOP

返回列表