# VPS inventory check
$ErrorActionPreference = 'Continue'

Write-Host "=== OS ===" -ForegroundColor Cyan
$os = Get-WmiObject Win32_OperatingSystem
$os | Select Caption, Version, OSArchitecture | Format-List
"Memory: $([math]::Round($os.TotalVisibleMemorySize / 1MB, 2)) GB"

Write-Host "=== CPU ===" -ForegroundColor Cyan
Get-WmiObject Win32_Processor | Select Name, NumberOfCores | Format-List

Write-Host "=== Disks ===" -ForegroundColor Cyan
Get-PSDrive -PSProvider FileSystem | Where-Object Used -gt 0 | ForEach-Object {
    "Drive $($_.Name): Used $([math]::Round($_.Used / 1GB, 2)) GB, Free $([math]::Round($_.Free / 1GB, 2)) GB"
}

Write-Host "=== IIS ===" -ForegroundColor Cyan
$iis = Get-WindowsFeature Web-Server -ErrorAction SilentlyContinue
if ($iis) { "IIS: $($iis.InstallState)" } else { "IIS: Not available via WindowsFeature" }
$w3svc = Get-Service W3SVC -ErrorAction SilentlyContinue
if ($w3svc) { "W3SVC service: $($w3svc.Status)" }

Write-Host "=== .NET SDKs ===" -ForegroundColor Cyan
try { dotnet --list-sdks } catch { "dotnet not found" }

Write-Host "=== Node.js ===" -ForegroundColor Cyan
try { node --version } catch { "node not found" }
try { npm --version } catch { "npm not found" }

Write-Host "=== Git ===" -ForegroundColor Cyan
try { git --version } catch { "git not found" }

Write-Host "=== SQL Server services ===" -ForegroundColor Cyan
Get-Service MSSQL* -ErrorAction SilentlyContinue | Select Name, Status, StartType | Format-Table -AutoSize
Get-Service SQL* -ErrorAction SilentlyContinue | Select Name, Status, StartType | Format-Table -AutoSize

Write-Host "=== PowerShell ===" -ForegroundColor Cyan
$PSVersionTable.PSVersion

Write-Host "=== Listening ports ===" -ForegroundColor Cyan
Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue |
    Where-Object { $_.LocalPort -in 22,80,443,1433,3000,3389,5443,5985,8080,8082 } |
    Select-Object LocalAddress, LocalPort |
    Sort-Object LocalPort |
    Get-Unique -AsString |
    Format-Table -AutoSize

Write-Host "=== ASP.NET Core Module ===" -ForegroundColor Cyan
$hb = Test-Path 'HKLM:\SOFTWARE\Microsoft\ASP.NET Core\Hosting Bundle\v10.0'
"ASP.NET Core 10 Hosting Bundle: $(if ($hb) {'Installed'} else {'NOT installed'})"
$hb9 = Test-Path 'HKLM:\SOFTWARE\Microsoft\ASP.NET Core\Hosting Bundle\v9.0'
"ASP.NET Core 9 Hosting Bundle: $(if ($hb9) {'Installed'} else {'NOT installed'})"

Write-Host "=== URL Rewrite ===" -ForegroundColor Cyan
$ur = Test-Path 'HKLM:\SOFTWARE\Microsoft\IIS Extensions\URL Rewrite'
"URL Rewrite: $(if ($ur) {'Installed'} else {'NOT installed'})"
