Using DBA Tools to gather a variety of information from a list of SQL Servers, particularly their patch level. I have a larger Powershell script that allows for selecting a set of options by entering their relevant number (1,2,3,4,5). I have been able to get database backups working on a single SQL server through this tool, but I cannot get a list of patch levels using DBA Tools. Specifically, the commands run but I don't receive any output through the tool. Interestingly, the same command does output when I use it via terminal on a single instance of SQL Server.
The option I am working to fix in my larger script is '3' - Check Patches. I verified the basic DBA Tools syntax works on a single instance via terminal as well as receiving a simple text output when option '3' is selected (just to confirm it is running as expected). The command below works and outputs in terminal like I want, but the larger function below it using the same syntax does not. The only difference being operating on a list of servers instead of a single instance:
WORKS:
Get-DBAInstalledPatch -ComputerName SQLINSTANCENAME
Unfortunately when I plug this same logic into a function, the output I receive is the following:
DOESN'T WORK: Function Input:
# Define a list of SQL Server instances
$instances = @(
"Server1",
"Server2"
)
# Iterate through the list of instances
foreach ($instance in $instances) {
Write-Host "Checking patch level for instance: $instance"
# Retrieve the latest patch level for the instance
$patchLevel = Get-DbaInstalledPatch -ComputerName $instance
# Output the patch level
if ($patchLevel) {
Write-Host "Latest patch level: $patchLevel"
} else {
Write-Host "Unable to retrieve patch level for instance: $instance"
}
}
Output:
Select Operation...: 3
Checking patch level for instance: Server1
Latest patch level:
Checking patch level for instance: Server2
Latest patch level:
Why does no data populate for the $patchLevel variable when used in the script?