Skip to content

Commit

Permalink
Merge pull request #13 from PluginsOCSInventory-NG/reworkDBInstancesPW
Browse files Browse the repository at this point in the history
Add rework in powershell of client script
  • Loading branch information
charleneauger authored Mar 17, 2020
2 parents 69697ae + 1a7804a commit 5eb071e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions agent/Windows/runningDatabaseInstances.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
$computerName = $env:computername

$edition = "Unknown"
$version = "Unknown"

$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
$xml = ""

foreach ($i in $inst)
{
$instanceFullName = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
$instanceName = $instanceFullName

if($instanceFullName.Contains(".")){
$instanceSplitted = $instanceFullName.Split(".")
$instanceName = $instanceSplitted.Get(1)
}

$publisher = "Microsoft Corporation"
$edition = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Edition
$version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceFullName\Setup").Version

if($version.StartsWith("10")){
$serverName = "Microsoft SQL Server 2008"
}elseif($version.StartsWith("10.5")){
$serverName = "Microsoft SQL Server 2008 R2"
}elseif($version.StartsWith("11")){
$serverName = "Microsoft SQL Server 2012"
}elseif($version.StartsWith("12")){
$serverName = "Microsoft SQL Server 2014"
}elseif($version.StartsWith("13")){
$serverName = "Microsoft SQL Server 2016"
}elseif($version.StartsWith("14")){
$serverName = "Microsoft SQL Server 2017"
}elseif($version.StartsWith("15")){
$serverName = "Microsoft SQL Server 2019"
}else{
$serverName = "Microsoft SQL Server " + $version
}

$xml += "<DBINSTANCES>`n"
$xml += "<NAME>" + $serverName + "</NAME>`n"
$xml += "<VERSION>" + $version + "</VERSION>`n"
$xml += "<EDITION>" + $edition + "</EDITION>`n"
$xml += "<INSTANCE>" + $instanceName + "</INSTANCE>`n"
$xml += "</DBINSTANCES>`n"

$xml += "<SOFTWARES>`n"
$xml += "<PUBLISHER>Microsoft Corporation</PUBLISHER>`n"
$xml += "<NAME>" + $serverName + "</NAME>`n"
$xml += "<VERSION>" + $version + "</VERSION>`n"
$xml += "<COMMENTS>DBInstances plugin</COMMENTS>`n"
$xml += "</SOFTWARES>`n"

}

echo $xml

0 comments on commit 5eb071e

Please sign in to comment.