- function init()
- {
- $script:ftToTalSize = @{label="ToTalSize" ; expression={(zFormat-HrSize($_.Size))} ; alignment = "right" }
- $script:ftAllocatedSize = @{label="Allocated" ; expression={(zFormat-HrSize($_.AllocatedSize))} ; alignment = "right" }
- $script:ftOffset = @{label="Offset" ; expression={ [string]::format("{0:N0}",$_.Offset) } ; alignment = "right" ; Width = 20 }
- $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={$_.DriveLetter}}
- $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"} } }}
- }
-
- Function zFormat-HrSize() {
- Param ( [Double]$size )
- $a = "BKMGT"
- for ($i = 0 ; $i -lt $a.length -and $size -ge 1024 ; $i++) {
- $size = $size / 1024
- }
- return ( [string]::Format("{0:0.0}", $size) + " " + $a.Substring($i,1) )
- }
-
- function get-DiskPart() {
- [Object[]] $diskPhy = Get-PhysicalDisk
- [Object[]] $disk = get-disk | sort-object { $_.DiskNumber }
- $disk | add-member -NotePropertyName "MediaType" -NotePropertyValue ""
- for ($i = 0 ; $i -le $disk.GetUpperBound(0) ; $i++){
- $disk[$i].mediatype = ($diskPhy | Where-Object {$_.deviceid -eq $i} ).mediatype
- }
- [Object[]] $vol = Get-Volume
- [Object[]] $part = Get-Partition | sort-object { $_.DiskNumber , $_.PartitionNumber }
- $part | add-member -NotePropertyName "FSType" -NotePropertyValue ""
- $part | add-member -NotePropertyName "FSLabel" -NotePropertyValue ""
- for ($i = 0 ; $i -le $part.GetUpperBound(0) ; $i++) {
- $part[$i].FSType = ( Get-Volume -Partition $part[$i] ).FileSystemType
- $part[$i].FSLabel = ( Get-Volume -Partition $part[$i] ).FileSystemLabel
- }
- return $disk,$part
- }
-
- function list-diskpart() {
- $disk | Format-Table $ftdDisk,$ftdName,$ftdBus,$ftdMedia,$ftdStyle,$ftToTalSize,$ftAllocatedSize
- $partStr = $part | Format-Table $ftpDisk,$ftpPart,$ftpLetter,$ftpIsActive,FSType,FSLabel,$ftToTalSize,$ftOffset,$ftpPartType | out-string
- $partStr = $partStr -replace "`r","" -replace "`n+$","`n" -split "`n"
- for ( $i = 0 ; $i -le $partstr.GetUpperBound(0) ; $i++)
- {
- if ( $partstr[$i-1] -match "^\s+(\d+)" ) { $n1 = $matches[1] }
- if ( $partstr[$i] -match "^\s+(\d+)" ) { $n2 = $matches[1] }
- if ( [int]$n1 + 1 -eq [int]$n2 )
- {
- $partstr[2]
- }
- $partstr[$i]
- }
- }
-
- init
- $disk,$part = get-DiskPart
- list-diskpart
-
- $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,FSLabel
复制代码
|