|
2#
楼主 |
发表于 2019-3-22 16:51:08
|
只看该作者
本帖最后由 dos时代菜鸟 于 2019-3-23 16:46 编辑
win10 powershell 测试通过
源码在此:
- #获取硬盘分区序列 分区所属硬盘的名称,接口,大小,分区类型;分区的序号,类型,文件系统类型,盘符,大小,卷标......
- $disks=get-disk
- $parts0=get-partition
- $vols0=get-volume
- $parts=@()
- if ($host.UI.RawUI.WindowSize.width -lt $host.ui.rawui.maxphysicalwindowsize.width) {
- $host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size($host.ui.rawui.maxphysicalwindowsize.width,20000)
- $host.UI.RawUI.WindowSize = new-object System.Management.Automation.Host.Size($host.ui.rawui.maxphysicalwindowsize.width,$host.ui.rawui.maxphysicalwindowsize.Height)
- }
- function size_x ($size0) {
- switch($size0.tostring().length)
- {
- {$_ -ge 15} { return ([math]::truncate($size0/1Tb).tostring()+" TB").padleft(8," ")}
- {$_ -ge 10} { return ([math]::truncate($size0/1gb).tostring()+" GB").padleft(8," ")}
- {$_ -ge 5 } { return ([math]::truncate($size0/1Mb).tostring()+" MB").padleft(8," ")}
- default { return ($size0.tostring() +" KB").padleft(8," ")}
- }
- }
- foreach($disk in $disks) {
- $part_x=""|select-object -property Disk_Name,Disk_size,Disk_free,BusType,Style,Disk,Part,Part_type,Ltr,FS,Offset,Part_size,Part_Free,Label,Boot,Active,System,Hidden,Offline,ReadOnly
- $part_x.Disk_name=$disk.FriendlyName
- $part_x.disk_size=size_x($disk.size)
- $part_x.disk_free=size_x($disk.LargestFreeExtent)
- $part_x.Style=$disk.PartitionStyle
- $part_x.disk=$disk.Number
- $part_x.BusType=$disk.bustype
- $part_x.Part="."
- $part_x.Boot=$disk.IsBoot
- $part_x.System=$disk.IsSystem
- $part_x.Offline=$disk.IsOffline
- $part_x.ReadOnly=$disk.IsReadOnly
- $parts+=$part_x
-
- ($parts0|where {$_.diskNumber -eq $disk.number})| % {
- $part_x=""|select-object -property Disk_Name,Disk_size,Disk_free,BusType,Style,Disk,Part,Part_type,Ltr,FS,Offset,Part_size,Part_Free,Label,Boot,Active,System,Hidden,Offline,ReadOnly
- $part_x.disk=$disk.number
- $part_x.part=$_.PartitionNumber.tostring().padright(3," ")
- $part_x.Ltr=$_.driveletter.ToString().trim()
- if ($part_x.ltr -eq "") { $part_x.ltr="*"}
- $part_x.part_type=$_.type
- $part_x.Offset=size_x($_.offset)
- $part_x.Part_size=size_x($_.size)
- $part_x.Active=$_.isActive
- $part_x.Boot=$_.IsBoot
- $part_x.System=$_.IsSystem
- $part_x.Hidden=$_.IsHidden
- $part_x.Offline=$_.IsOffline
- $part_x.ReadOnly=$_.IsReadOnly
- if ($_.accesspaths -ne $null) {
- $part_path=$_.AccessPaths[$_.AccessPaths.count-1]
- $part_x.FS = ($vols0|where {$_.uniqueid -eq $part_path}).filesystem
- $part_x.part_free = size_x(($vols0|where {$_.uniqueid -eq $part_path}).sizeRemaining)
- $part_x.Label = ($vols0|where {$_.uniqueid -eq $part_path}).filesystemLabel
- }
- $parts+=$part_x
- }
- }
- cls
- ""
- ""
- "-----------------------------------------------------------------------"
- ($parts|where {$_.part -eq "." })|format-table -property disk,disk_name,bustype,disk_size,disk_free,Style,Boot,System,Offline,hidden,readonly
- ($parts|where {$_.part -ne "." })|format-table -property disk,part,part_type,fs,LTR,Offset,part_size,part_free,label,Boot,Active,System,Offline,hidden,readonly
- "-----------------------------------------------------------------------"
- pause
复制代码
|
|