This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL-INFO.ps1
More file actions
41 lines (35 loc) · 1.84 KB
/
SQL-INFO.ps1
File metadata and controls
41 lines (35 loc) · 1.84 KB
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
31
32
33
34
35
36
37
38
39
40
41
#////////////////////////////////////////////
# SQL-INFO.ps1 by Tim Fischbach
#////////////////////////////////////////////
$hostname = $env:COMPUTERNAME
$instances = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
$Output = @()
# Only proceed with system info gathering if instances are found
if ($instances) {
# Get CPU Count from Registry
$CPUDetails = (Get-ItemProperty "HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor\0").ProcessorNameString
$CPUCores = (Get-ChildItem "HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor").Count
# Get RAM in GB from Registry
$TotalRAM = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
# Add system info as first line
$Output += "System Info: CPU: $CPUDetails, Cores: $CPUCores, RAM: $TotalRAM GB"
$Output += "----------------------------------------"
# Process SQL instances
foreach ($i in $instances) {
$instanceRegPath = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
$Edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceRegPath\Setup").Edition
$Version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceRegPath\Setup").Version
$Output += "Instance: $i, Edition: $Edition, Version: $Version"
}
}
# Only create file if we have data
if ($Output.Count -gt 0) {
$TimeStamp = Get-Date -Format "HHmmss"
$filename = $hostname + "_" + (Get-Date).ToString("yyyyMMdd") + "_" + $TimeStamp + ".txt"
$FilePath = "\\MY\NETWORK\DRIVE\txt\$filename"
$Output | Out-File -FilePath $FilePath
# Output statistics
Write-Output "[INFO] SQL Server instances found!"
} else {
Write-Output "[INFO] No SQL Server instances found."
}