#!/usr/bin/env pwsh # Exit immediately if a command exits with a non-zero status $ErrorActionPreference = 'Stop' # Exit if an undefined variable is referenced Set-StrictMode -Version Latest # OS Detection $UNAME_OS = [System.Environment]::OSVersion.Platform.ToString() switch ($UNAME_OS) { 'Linux' { if (Test-Path '/etc/os-release') { $OS_TYPE = (Get-Content '/etc/os-release' | Select-String -Pattern "^ID=" | ForEach-Object { $_.ToString().Split('=')[1].Trim('"') }) -join '' } elseif ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT) { try { $reg = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop $OS_TYPE = 'windows' } catch { $OS_TYPE = 'unknown' } } else { $OS_TYPE = try { $u = (uname -s 2>$null); if ($u -eq 'Darwin') { 'darwin' } else { 'unknown' } } catch { 'unknown' } } } 'Darwin' { $OS_TYPE = 'darwin' } 'Unix' { if (Test-Path '/etc/os-release') { $OS_TYPE = (Get-Content '/etc/os-release' | Select-String -Pattern "^ID=" | ForEach-Object { $_.ToString().Split('=')[1].Trim('"') }) -join '' } elseif ([System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT) { try { $reg = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop $OS_TYPE = 'windows' } catch { $OS_TYPE = 'unknown' } } else { $OS_TYPE = try { $u = (uname -s 2>$null); if ($u -eq 'Darwin') { 'darwin' } else { 'unknown' } } catch { 'unknown' } } } 'Win32NT' { $OS_TYPE = 'windows' } default { $OS_TYPE = 'unknown' } } switch ($OS_TYPE) { 'ubuntu' { $OS_TYPE_NAME = 'Ubuntu' } 'debian' { $OS_TYPE_NAME = 'Debian' } 'fedora' { $OS_TYPE_NAME = 'Fedora' } 'centos' { $OS_TYPE_NAME = 'CentOS' } 'rhel' { $OS_TYPE_NAME = 'Red Hat Enterprise Linux' } 'alpine' { $OS_TYPE_NAME = 'Alpine Linux' } 'arch' { $OS_TYPE_NAME = 'Arch Linux' } 'darwin' { $OS_TYPE_NAME = 'macOS' } 'windows' { $OS_TYPE_NAME = 'Windows' } default { $OS_TYPE_NAME = 'Unknown' } } Write-Output "Detected OS Type: $OS_TYPE" Write-Output "OS Name: $OS_TYPE_NAME" # Disk Space Check $drive = Get-PSDrive | Where-Object { $_.Root -eq '/' } | Select-Object -First 1 if ($null -eq $drive) { $drive = Get-PSDrive -Name (Get-Location).Drive.Name -ErrorAction SilentlyContinue | Select-Object -First 1 } if ($null -eq $drive) { $TOTAL_SPACE_GB = 0; $AVAILABLE_SPACE_GB = 0 } else { $TOTAL_SPACE_GB = [math]::Round(($drive.Used + $drive.Free) / 1GB, 0); $AVAILABLE_SPACE_GB = [math]::Round($drive.Free / 1GB, 0) } Write-Host -ForegroundColor Cyan "Total Disk Space: $TOTAL_SPACE_GB GB" Write-Host -ForegroundColor Cyan "Available Disk Space: $AVAILABLE_SPACE_GB GB"