-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-DriveSpace.ps1
More file actions
43 lines (40 loc) · 1.75 KB
/
Get-DriveSpace.ps1
File metadata and controls
43 lines (40 loc) · 1.75 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
function Get-DriveSpace {
[CmdletBinding()]
param(
[Parameter(Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[Alias('cn', 'host', 'hostname')]
$ComputerName,
[Parameter(Mandatory=$false)]
[Alias('cred', 'login', 'runas')]
[System.Management.Automation.Credential()]$Credential =
[System.Management.Automation.PSCredential]::Empty
)
ForEach ($Server in $Computername) {
if ($Credential)
{
$GetVolume = Get-WmiObject –ComputerName $Server –Class Win32_Volume -filter "DriveType=3" -Credential $Credential -ErrorAction SilentlyContinue | Where-Object {$_.Label -ne 'System Reserved'}
}
else
{
$GetVolume = Get-WmiObject –ComputerName $Server –Class Win32_Volume -filter "DriveType=3" -ErrorAction SilentlyContinue | Where-Object {$_.Label -ne 'System Reserved'}
}
try
{
$GetVolume | `
Format-Table –auto @{Label="Server";Expression={$Server}}, `
@{Label="Drive Letter";Expression={$_.DriveLetter}}, `
@{Label="Volume Label";Expression={$_.Label}}, `
@{Label="Free(GB) ";Expression={"{0:N3}" –F ($_.FreeSpace/1GB)};alignment="right"}, `
@{Label="Size(GB) ";Expression={"{0:N3}" –F ($_.Capacity/1GB)};alignment="right"}, `
@{Label=" % Free";Expression={"{0:P2}" –F ($_.FreeSpace/$_.Capacity)};alignment="right"}
}
catch
{
Write-Warning "Connecting to $Server failed. ($_.Exeption.Message)"
}
}
}