forked from MikeFal/PowershellToolbox-SSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-Freespace.ps1
30 lines (22 loc) · 870 Bytes
/
Get-Freespace.ps1
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
#Basic function example
function Invoke-Message{
Write-Host -ForegroundColor Yellow 'Hello World!'
}
Invoke-Message
#basic Function example with parameter
function Invoke-Message{
param([string] $message)
Write-Host -ForegroundColor Yellow $message
}
Invoke-Message 'Hello World!'
#our first Powershell Tool, Get-FreeSpace
function Get-FreeSpace{
param([string] $HostName = ($env:COMPUTERNAME))
Get-WmiObject win32_volume -computername $hostname | `
Where-Object {$_.drivetype -eq 3} | `
Sort-Object name | `
Format-Table name,@{l="Size(GB)";e={($_.capacity/1gb).ToString("F2")}},`
@{l="Free Space(GB)";e={($_.freespace/1gb).ToString("F2")}},`
@{l="% Free";e={(($_.Freespace/$_.Capacity)*100).ToString("F2")}}
}
Get-FreeSpace -HostName localhost