# --- CONFIGURATION --- $WebAppUrl = "https://script.google.com/macros/s/AKfycbyY0lOe7KwDWNEwbDlNhMkQJud2_TnxvsANu__ytF6WanUczKOGoWLw1CLe6TtWSI2A/exec" $SheetUrl = "https://docs.google.com/spreadsheets/d/11xSI_od8n4mldtFFsEClCliyu-PUCf4_W9zlqE_K8QU/edit?gid=0#gid=0" $SecretKey = "OpenSesame" # --- 1. INTERACTIVE FORM --- Add-Type -AssemblyName Microsoft.VisualBasic $PreferredName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your Full Name:", "Inventory Identity", "$env:USERNAME") $Department = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your Department:", "Inventory Identity", "General") if ([string]::IsNullOrWhiteSpace($PreferredName)) { exit } # --- 2. LOADING MESSAGE --- Clear-Host Write-Host "------------------------------------------------" -ForegroundColor Cyan Write-Host " V2 SYSTEM INVENTORY IN PROGRESS... PLEASE WAIT " -ForegroundColor White -BackgroundColor Blue Write-Host "------------------------------------------------" -ForegroundColor Cyan Write-Host "Checking OS and Permissions..." -NoNewline # --- 3. DATA EXTRACTION --- # 1. Admin & Elevation Check (More robust SID lookup) $IsAdminUser = "No" try { # Get current user's SID directly from the identity object $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() $UserSid = $currentUser.User.Value # Check local Administrators group members $Admins = Get-LocalGroupMember -Group "Administrators" -ErrorAction SilentlyContinue if ($Admins.SID -contains $UserSid) { $IsAdminUser = "Yes" } } catch { $IsAdminUser = "Unknown (Lookup Error)" } # Check if current process is actually elevated $currentPrincipal = New-Object Security.Principal.WindowsPrincipal($currentUser) $IsElevated = if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { "Yes" } else { "No" } $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $IsElevated = if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { "Yes" } else { "No" } # TPM Check (Using tpmtool) $TPMStatus = "Unknown" try { $TPMCheck = tpmtool getdeviceinformation | Out-String if ($TPMCheck -match "TPM Present: True") { $TPMStatus = "Ready" } elseif ($TPMCheck -match "TPM Present: False") { $TPMStatus = "Not Found" } } catch { $TPMStatus = "Error Reading TPM" } # BitLocker Check (Advanced String Match) $BitlockerStatus = "Not Configured" try { $BdePath = Join-Path $env:SystemRoot "System32\manage-bde.exe" $BLCheck = & $BdePath -status C: | Out-String if ($BLCheck -match "Percentage Encrypted:\s+100") { $BitlockerStatus = "Fully Encrypted" } elseif ($BLCheck -match "Percentage Encrypted:\s+[1-9]\d?(\.\d+)?%") { $BitlockerStatus = "Encryption in Progress" } elseif ($BLCheck -match "Percentage Encrypted:\s+0") { $BitlockerStatus = "Not Encrypted" } elseif ($BLCheck -match "Protection On") { $BitlockerStatus = "Protected" } } catch { $BitlockerStatus = "Access Denied/Error" } # OS Version info $OS = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" $WinVersion = "$($OS.ProductName) $($OS.DisplayVersion) (Build $($OS.CurrentBuild))" Write-Host " Done." -ForegroundColor Green Write-Host "Checking Hardware and Storage..." -NoNewline # Hardware & Storage $Sys = Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue $Bios = Get-CimInstance Win32_Bios -ErrorAction SilentlyContinue $CPU = Get-CimInstance Win32_Processor -ErrorAction SilentlyContinue $Drive = Get-PSDrive C $MakeModel = "$($Sys.Manufacturer) $($Sys.Model)" $Serial = $Bios.SerialNumber $BiosAge = if ($Bios.ReleaseDate) { $Bios.ReleaseDate.ToString("yyyy-MM-dd") } else { "Unknown" } $RAM = "$([Math]::Round($Sys.TotalPhysicalMemory / 1GB, 0)) GB" $DiskFree = "$([Math]::Round(($Drive.Free / 1GB), 2)) GB Free" Write-Host " Done." -ForegroundColor Green Write-Host "Scanning Profiles and Software..." -NoNewline $IP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.InterfaceAlias -ne 'Loopback' }).IPAddress[0] $OtherProfiles = Get-ChildItem "C:\Users" -ErrorAction SilentlyContinue | Where-Object { $_.PSIsContainer -and $_.Name -notmatch "Public|Default|All Users" -and $_.Name -ne $env:USERNAME } | Select-Object -ExpandProperty Name $RegPaths = @("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*") $Programs = Get-ItemProperty $RegPaths -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName } | Select-Object -ExpandProperty DisplayName | Sort-Object -Unique Write-Host " Done." -ForegroundColor Green # --- 4. CONSOLIDATE PAYLOAD --- $PayloadData = @{ key = $SecretKey PreferredName = $PreferredName SystemUserName = $env:USERNAME IsAdmin = "$IsAdminUser (Elevated: $IsElevated)" Department = $Department Domain = $env:USERDOMAIN PC_Name = $env:COMPUTERNAME IP_Address = $IP OS_Version = $WinVersion Hardware = "$MakeModel ($($CPU.Name), $RAM)" Serial = $Serial BiosAge = $BiosAge DiskFree = $DiskFree TPM = $TPMStatus BitLocker = $BitlockerStatus OtherProfiles = @($OtherProfiles) Programs = @($Programs) } $PayloadJson = $PayloadData | ConvertTo-Json -Depth 10 # --- 5. UPLOAD & FINAL STATUS --- Write-Host "`nSending data to Google Sheets..." -ForegroundColor Cyan try { $Response = Invoke-RestMethod -Uri $WebAppUrl -Method Post -Body $PayloadJson -ContentType "application/json" if ($Response -eq "Success") { Write-Host "SUCCESS: Inventory uploaded correctly." -ForegroundColor Green Write-Host "`nView the spreadsheet here: " -NoNewline Write-Host $SheetUrl -ForegroundColor Cyan # Optional: Uncomment the line below to automatically open the browser when finished # Start-Process $SheetUrl } else { Write-Host "SERVER ERROR: $Response" -ForegroundColor Yellow } } catch { Write-Host "NETWORK ERROR: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "`n------------------------------------------------" -ForegroundColor Cyan Write-Host "Inventory Scan Finished." -ForegroundColor White Read-Host "Press ENTER to close this window"