Скрипт получает список БД и делает json для последующего использования в zabbix.
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 |
[string] $server = $env:COMPUTERNAME $pServerBLLogin = "login" $pServerBLPass = "pwd" $securePassword = $pServerBLPass | ConvertTo-SecureString -AsPlainText -Force; $credential = New-Object System.Management.Automation.PSCredential($pServerBLLogin, $securePassword); $discoverDB = Invoke-Command -ComputerName $server -Credential $credential -ScriptBlock { $res=Invoke-Sqlcmd -ServerInstance $server -Database master -Query 'SELECT name, database_id, create_date FROM sys.databases; ' return $res } [string]$jsonBody= "" foreach ($DbName in $discoverDB.name) { $jsonBody += '{"{#DBName}":"' + $DbName + '"},' } $jsonBody = $jsonBody.Substring(0,$jsonBody.Length-1) $jsonFull = '{"data":[' + $($jsonBody -replace ',\s$') + ']}' $jsonFull |