Hi,I want to extract the list of good servers where the SQL Server services are running to execute a .SQL file across the list of servers using powershell.Somehow the below script does not work.Any suggestion, where does it error?# Use the below script to only pull out the details of the GOOD servers.import-module "SQLPS" -DisableNameCheckingset-location "C:\PS\check\"$servers = get-content "C:\PS\check\list_servertest.txt";#$servers.Count$collection = $()$newset = $servers.Replace("\XYZ1","")foreach ($server in $newset){ $status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) } if (!(Test-Connection $server -Count 1 -ea 0 -Quiet)) { #Server is DOWN $status["Results"] = "DOWN" } else { #Server is UP $status["Results"] = "UP" $sqlservices = Get-Service -ComputerName $server | Where-Object {$_.ServiceName -like "MSSQL`$XYZ1"} #Write-Host "SQL Services on Server [$($server)]" $status += $sqlservices | Select-Object Name, DisplayName, Status } New-Object -TypeName PSObject -Property $status -OutVariable serverStatus $collection += $serverStatus}$collection| Out-File -filepath "C:\PS\check\good_servers.txt" -append$servers = Get-Content "C:\PS\check\good_servers.txt"$filePathOutput = "C:\PS\check\execution_result.txt"
↧