|
ここでは、PowerShell Check Disk Space - Win32_LogicalDisk のサンプルを紹介します。
- Get-Help Get-WmiObject
次の事例を実行してみよう。
# http://www.computerperformance.co.uk/powershell/powershell_wmi_disk.htm
# Help with PowerShell WMI object:
Get-Help Get-WmiObject
Get-WmiObject のヘルプを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
" > パイプ問題(?)" 関連で、下記のファイルを差し替えました。
表示内容は、086_PS_WMI-Object_01.txt にほぞんしました。
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-Help: Get-Help could not find Get-WmiObject in a help file in this session.
To download updated help topics type: "Update-Help". To get help online,
search for the help topic in the TechNet library at
https://go.microsoft.com/fwlink/?LinkID=107116.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -List | Where-Object {$_.name -Match $Type}
次の事例を実行してみよう。
# Check WmiObject Classes
Clear-Host
$Type = "Disk"
Get-WmiObject -List | Where-Object {$_.name -Match $Type}
3行目で、"Disk" を $Type に格納します。
4行目で、WMI オブジェクトリストを取得して、.name が $Type にマッチするものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
Name Methods Properties
---- ------- ----------
CIM_DiskDrive {SetPowerState, R... {Availability, Capabilities, CapabilityDescriptions, ...
Win32_DiskDrive {SetPowerState, R... {Availability, BytesPerSector, Capabilities, Capabili...
CIM_DisketteDrive {SetPowerState, R... {Availability, Capabilities, CapabilityDescriptions, ...
CIM_LogicalDisk {SetPowerState, R... {Access, Availability, BlockSize, Caption...}
Win32_LogicalDisk {SetPowerState, R... {Access, Availability, BlockSize, Caption...}
Win32_MappedLogicalDisk {SetPowerState, R... {Access, Availability, BlockSize, Caption...}
CIM_DiskPartition {SetPowerState, R... {Access, Availability, BlockSize, Bootable...}
Win32_DiskPartition {SetPowerState, R... {Access, Availability, BlockSize, Bootable...}
CIM_DiskSpaceCheck {Invoke} {AvailableDiskSpace, Caption, CheckID, CheckMode...}
Win32_LogicalDiskRootDirectory {} {GroupComponent, PartComponent}
Win32_DiskQuota {} {DiskSpaceUsed, Limit, QuotaVolume, Status...}
Win32_LogonSessionMappedDisk {} {Antecedent, Dependent}
CIM_LogicalDiskBasedOnPartition {} {Antecedent, Dependent, EndingAddress, StartingAddress}
Win32_LogicalDiskToPartition {} {Antecedent, Dependent, EndingAddress, StartingAddress}
CIM_LogicalDiskBasedOnVolumeSet {} {Antecedent, Dependent, EndingAddress, StartingAddress}
Win32_DiskDrivePhysicalMedia {} {Antecedent, Dependent}
CIM_RealizesDiskPartition {} {Antecedent, Dependent, StartingAddress}
Win32_DiskDriveToDiskPartition {} {Antecedent, Dependent}
Win32_OfflineFilesDiskSpaceLimit {} {AutoCacheSizeInMB, TotalSizeInMB}
Win32_PerfFormattedData_Counters... {} {Caption, Description, FileSystemBytesRead, FileSyste...
Win32_PerfRawData_Counters_FileS... {} {Caption, Description, FileSystemBytesRead, FileSyste...
Win32_PerfFormattedData_PerfDisk... {} {AvgDiskBytesPerRead, AvgDiskBytesPerTransfer, AvgDis...
Win32_PerfRawData_PerfDisk_Logic... {} {AvgDiskBytesPerRead, AvgDiskBytesPerRead_Base, AvgDi...
Win32_PerfFormattedData_PerfDisk... {} {AvgDiskBytesPerRead, AvgDiskBytesPerTransfer, AvgDis...
Win32_PerfRawData_PerfDisk_Physi... {} {AvgDiskBytesPerRead, AvgDiskBytesPerRead_Base, AvgDi...
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject Win32_logicaldisk | Format-Table -auto
次の事例を実行してみよう。
# PowerShell cmdlet to display Logical Disk information
Clear-Host
Get-WmiObject Win32_logicaldisk | Format-Table -auto
Win32_logicaldisk の WMI オブジェクトを取得して、テーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceID DriveType ProviderName FreeSpace Size VolumeName
-------- --------- ------------ --------- ---- ----------
A: 2
C: 3 90948247552 249584152576
D: 3 308351717376 500103639040
E: 5
F: 3 114140078080 500105736192 ボリューム
G: 3 538432401408 2000398872576 HD-LSU2
H: 3 1208513372160 2000263573504 Seagate Expansion Drive
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -query "Select * from Win32_logicaldisk" |Ft
次の事例を実行してみよう。
# PowerShell cmdlet to display Logical Disk information
Clear-Host
Get-WmiObject -query "Select * from Win32_logicaldisk" |Ft
-query "Select * from Win32_logicaldisk" を指定して、WMI オブジェクトを取得して、テーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceID DriveType ProviderName FreeSpace Size VolumeName
-------- --------- ------------ --------- ---- ----------
A: 2
C: 3 90948247552 249584152576
D: 3 308351717376 500103639040
E: 5
F: 3 114140078080 500105736192 ボリューム
G: 3 538432401408 2000398872576 HD-LSU2
H: 3 1208513372160 2000263573504 Seagate Expansion Drive
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject Win32_logicaldisk | Get-Member
次の事例を実行してみよう。
# Properties for PowerShell logical disk object:
Get-WmiObject Win32_logicaldisk | Get-Member
Win32_logicaldisk の WMI オブジェクトを取得して、メンバーを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
TypeName: System.Management.ManagementObject#root\cimv2\Win32_LogicalDisk
Name MemberType Definition
---- ---------- ----------
PSComputerName AliasProperty PSComputerName = __SERVER
Chkdsk Method System.Management.ManagementBaseObject Chkdsk(System.Boolean FixErr...
Reset Method System.Management.ManagementBaseObject Reset()
SetPowerState Method System.Management.ManagementBaseObject SetPowerState(System.UInt16 ...
Access Property uint16 Access {get;set;}
Availability Property uint16 Availability {get;set;}
BlockSize Property uint64 BlockSize {get;set;}
Caption Property string Caption {get;set;}
< 省略 >
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject Win32_logicaldisk | Format-Table DeviceId, MediaType, Size, FreeSpace -auto
次の事例を実行してみよう。
# PowerShell command disk space
Get-WmiObject Win32_logicaldisk `
| Format-Table DeviceId, MediaType, Size, FreeSpace -auto
Win32_logicaldisk の WMI オブジェクトを取得して、DeviceId, MediaType, Size, FreeSpace のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
A: 5
C: 12 249584152576 90947346432
D: 12 500103639040 308351717376
E: 11
F: 12 500105736192 114140078080
G: 12 2000398872576 538432401408
H: 12 2000263573504 1208513372160
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -query "Select * from Win32_logicaldisk" | Format-Table $Item -auto
次の事例を実行してみよう。
# PowerShell cmdlet to display a disk's free space
$Item = @("DeviceId", "MediaType", "Size", "FreeSpace")
# Next follows one command split over two lines by a backtick `
Get-WmiObject -query "Select * from Win32_logicaldisk" | Format-Table $Item -auto
-query "Select * from Win32_logicaldisk" を指定して、WMI オブジェクトを取得して、DeviceId, MediaType, Size, FreeSpace のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
A: 5
C: 12 249584152576 90947346432
D: 12 500103639040 308351717376
E: 11
F: 12 500105736192 114140078080
G: 12 2000398872576 538432401408
H: 12 2000263573504 1208513372160
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- @{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}
次の事例を実行してみよう。
# ---- Controlling the Decimals ----
# Clear-Host
Get-WmiObject Win32_logicaldisk -ComputerName LocalHost `
| Format-Table DeviceID, MediaType, `
@{Name="Size(GB)";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}, `
@{Name="Free Space(GB)";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}, `
@{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}} `
-AutoSize
Win32_logicaldisk の WMI オブジェクトを取得して、Size(GB) , Free Space(GB) , Free (%) のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceID MediaType Size(GB) Free Space(GB) Free (%)
-------- --------- -------- -------------- --------
A: 5 0 0
C: 12 232 85 36%
D: 12 466 287 62%
E: 11 0 0
F: 12 466 106 23%
G: 12 1863 501 27%
H: 12 1863 1126 60%
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -computer LocalHost -query "Select $([string]::Join(',', $Item)) from Win32_logicaldisk"
次の事例を実行してみよう。
# PowerShell Get-WmiObject disk space
# Clear-Host
$Item = @("DeviceId", "MediaType", "Size", "FreeSpace")
# Next follows one command, which is split over three lines by the backtick `
Get-WmiObject -computer LocalHost -query `
"Select $([string]::Join(',', $Item)) from Win32_logicaldisk" `
| Sort MediaType, DeviceID | Format-Table $item -auto -groupby MediaType
3行目で、@("DeviceId", "MediaType", "Size", "FreeSpace") を $Item に格納します。
5〜7行で、-query "Select $([string]::Join(',', $Item)) from Win32_logicaldisk" を指定して、WMI オブジェクトを取得して、MediaType, DeviceID で並び変えて、$item のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
MediaType: 5
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
A: 5
MediaType: 11
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
E: 11
MediaType: 12
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
C: 12 249584152576 90949132288
D: 12 500103639040 308351717376
F: 12 500105736192 114140078080
G: 12 2000398872576 538432401408
H: 12 2000263573504 1208513372160
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- "Select $([string]::Join(',',$Item)) from Win32_logicaldisk Where MediaType=12"
次の事例を実行してみよう。
# PowerShell check disk space
$Item = @("DeviceId", "MediaType", "Size", "FreeSpace")
# Clear-Host
# Next follows one command split over four lines by a backtick `
Get-WmiObject -computer LocalHost -query `
"Select $([string]::Join(',',$Item)) from Win32_logicaldisk `
Where MediaType=12" | Sort-Object MediaType, DeviceID `
| Format-Table $item -auto
2行目で、@("DeviceId", "MediaType", "Size", "FreeSpace") を $Item に格納します。
5〜8行で、-query "Select $([string]::Join(',', $Item)) from Win32_logicaldisk" を指定して、WMI オブジェクトを取得して、MediaType が 12 であるものを MediaType, DeviceID で並び変えて、$item のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
DeviceId MediaType Size FreeSpace
-------- --------- ---- ---------
C: 12 249584152576 90947952640
D: 12 500103639040 308351717376
F: 12 500105736192 114140078080
G: 12 2000398872576 538432401408
H: 12 2000263573504 1208513372160
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -query "Select * from Win32_DiskPartition" | Format-Table $item -auto
次の事例を実行してみよう。
# PowerShell cmdlet to display a disk's partition information.
# Clear-Host
$Item = @("Name","DiskIndex", "StartingOffset", "Bootable", "BlockSize", "NumberOfBlocks")
Get-WmiObject -query "Select * from Win32_DiskPartition" | Format-Table $item -auto
3行目で、@("Name","DiskIndex", "StartingOffset", "Bootable", "BlockSize", "NumberOfBlocks") を $Item に格納します。
4行目で、-query "Select * from Win32_DiskPartition" を指定して、WMI オブジェクトを取得して、$item のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
Name DiskIndex StartingOffset Bootable BlockSize NumberOfBlocks
---- --------- -------------- -------- --------- --------------
ディスク #3, パーティション #0 3 135266304 False 512 3906764800
ディスク #1, パーティション #0 1 1048576 False 512 976764928
ディスク #2, パーティション #0 2 1048576 False 512 976769024
ディスク #4, パーティション #0 4 32768 False 512 3907029056
ディスク #0, パーティション #0 0 1048576 True 512 487469056
ディスク #0, パーティション #1 0 249585205248 False 512 921600
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject Win32_DiskPartition | Get-member
次の事例を実行してみよう。
# ---- Learning Points ----
Get-WmiObject Win32_DiskPartition | Get-member
Win32_DiskPartition の WMI オブジェクトを取得して、メンバーを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
TypeName: System.Management.ManagementObject#root\cimv2\Win32_DiskPartition
Name MemberType Definition
---- ---------- ----------
PSComputerName AliasProperty PSComputerName = __SERVER
Reset Method System.Management.ManagementBaseObject Reset()
SetPowerState Method System.Management.ManagementBaseObject SetPowerState(System.UInt16 P...
Access Property uint16 Access {get;set;}
Availability Property uint16 Availability {get;set;}
BlockSize Property uint64 BlockSize {get;set;}
Bootable Property bool Bootable {get;set;}
BootPartition Property bool BootPartition {get;set;}
Caption Property string Caption {get;set;}
< 省略 >
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
|