-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGet-DiskInventory.ps1
More file actions
64 lines (60 loc) · 3.88 KB
/
Get-DiskInventory.ps1
File metadata and controls
64 lines (60 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
Get-DiskInventory retrieves logical disk information from one or
more computers.
.DESCRIPTION
Get-DiskInventory uses WMI to retrieve the Win32_LogicalDisk
instances from one or more computers. It displays each disk's
drive letter, free space, used space, total size, and percentage of free
space.
.NOTES
Created by: Jason Wasser @wasserja
Modified: 1/10/2017 11:05:17 AM
.PARAMETER ComputerName
The computer name, or names, to query. Default: Localhost.
.PARAMETER drivetype
The drive type to query. See Win32_LogicalDisk documentation
for values. 3 is a fixed disk, and is the default.
.EXAMPLE
Get-DiskInventory
Get the logical disk inventory from the local computer.
.EXAMPLE
Get-DiskInventory -ComputerName SERVER-R2
Get the logical disk inventory from the remote server SERVER-R2.
.LINK
https://gallery.technet.microsoft.com/scriptcenter/Get-DiskInventory-2d09f3f7
#>
function Get-DiskInventory
{
[CmdletBinding()]
[Alias()]
Param
(
# ComputerName
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]$ComputerName=$env:COMPUTERNAME,
# DriveType 3 is fixed disk (excludes USB Drives and CD ROM)
[int]$DriveType=3
)
Begin
{
}
Process
{
foreach ($Computer in $ComputerName) {
Get-WmiObject -class Win32_LogicalDisk -computername $Computer `
-filter "drivetype=$DriveType" |
Sort-Object -property DeviceID |
Select-Object -Property PSComputerName,DeviceID,VolumeName,
@{l='FreeSpace(GB)';e={$_.FreeSpace / 1GB -as [int]}},
@{l='Capacity(GB)';e={$_.Size / 1GB -as [int]}},
@{l='UsedSpace(GB)';e={($_.Size - $_.FreeSpace) / 1GB -as [int]}},
@{l='%Free';e={$_.FreeSpace / $_.Size * 100 -as [int]}}
}
}
End
{
}
}