Code backup
This commit is contained in:
2026-05-10 16:59:01 +02:00
commit 368d6fafea
796 changed files with 315310 additions and 0 deletions
@@ -0,0 +1,43 @@
$Devices = @()
$Resultes = @()
$LogOutPut = @()
$DeviceCount = 0
$exitState = 0
$Devices = Get-ADComputer -Properties * -Filter { OperatingSystem -like "Windows*"} |
Where-Object { $_.Enabled -eq $true } | Select-Object Name, DNSHostName, OperatingSystem, OperatingSystemVersion | Sort-Object Name
foreach ($Device in $Devices){
if (Test-Connection -ComputerName $Device.DNSHostName -Quiet){
$DeviceCount += 1
$Resultes = Get-WmiObject Win32_LogicalDisk -ComputerName $Device.DNSHostName -Filter "DriveType=3" -ErrorAction SilentlyContinue | Select-Object DeviceID, Size, Freespace
foreach ($Result in $Resultes | Where-Object {$_.DeviceID -like "C:"}){
$Percentage = "{0:P0}" -f ($Result.Freespace / $Result.Size)
if(($Result.DeviceID -eq "C:") -and ([int]$Percentage.Split("%")[0] -cle 10)){
$LogOutPut += [PSCustomObject]@{
HostName = $Device.DNSHostName
TotCapacity = "{0:N1}" -f ($Result.Size / 1gb) + " GB"
FreeSpace = "{0:N1}" -f ($Result.Freespace / 1gb ) + " GB"
FreePercentage = $Percentage
}
}
}
}
}
if ($LogOutPut.Count -eq 0){
Write-Output "OK - All devices are in range!"
Write-Output " Devices found: $($Devices.Count)"
Write-Output " Analyzed devices: $($DeviceCount)"
} else {
$exitState = 2
Write-Output "CRITICAL! - $($LogOutPut.Count) Devices with space issue!"
Write-Output " Devices found: $($Devices.Count)"
Write-Output " Analyzed devices: $($DeviceCount)"
$LogOutPut | Format-Table
}
Exit $exitState
@@ -0,0 +1,59 @@
<#
.SYNOPSIS
Get-DiskSpaceReport.ps1
.DESCRIPTION
Export all enabled Windows Servers disk space to CSV file.
.LINK
www.alitajran.com/check-free-disk-space-windows-powershell-script
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 02/17/2022 - Initial version
V1.10, 11/03/2023 - Added OS name and OS version
#>
Import-Module ActiveDirectory
# Delete reports older than 60 days
$OldReports = (Get-Date).AddDays(-60)
# Location for disk reports
Get-ChildItem "C:\Temp\*.*" |
Where-Object { $_.LastWriteTime -le $OldReports } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
# Create variable for log date
$LogDate = Get-Date -Format yyyyMMddhhmm
# Get all systems
$Systems = Get-ADComputer -Properties * -Filter { OperatingSystem -like "Windows 11 Enterprise" } |
Where-Object { $_.Enabled -eq $true } | Select-Object Name, DNSHostName, OperatingSystem, OperatingSystemVersion | Sort-Object Name
# Loop through each system
$DiskReport = ForEach ($System in $Systems) {
$OperatingSystem = $System.OperatingSystem
$OperatingSystemVersion = $System.OperatingSystemVersion
Get-WmiObject Win32_LogicalDisk `
-ComputerName $System.DNSHostName -Filter "DriveType=3" `
-ErrorAction SilentlyContinue |
Select-Object `
@{Label = "HostName"; Expression = { $_.SystemName } },
@{Label = "DriveLetter"; Expression = { $_.DeviceID } },
@{Label = "DriveName"; Expression = { $_.VolumeName } },
@{Label = "Total Capacity (GB)"; Expression = { "{0:N1}" -f ($_.Size / 1gb) } },
@{Label = "Free Space (GB)"; Expression = { "{0:N1}" -f ($_.Freespace / 1gb ) } },
@{Label = 'Free Space (%)'; Expression = { "{0:P0}" -f ($_.Freespace / $_.Size) } },
@{Label = "Operating System"; Expression = { $OperatingSystem } },
@{Label = "Operating System Version"; Expression = { $OperatingSystemVersion } }
}
# Create disk report
$DiskReport |
Export-Csv -Path "C:\Temp\DiskReport.csv" -NoTypeInformation #-Delimiter ";"