![]() ![]() If instead, you run the same command, except you put in the full SQL server name the instance name, for each instance, then the Smo.Server object returns the correct information. ![]() pulling the VersionString returns an empty string. Where $computer is a server name, and on that server there is multiple instances a single Smo.Server object is returned, which is essentially empty. when you get the Smo.Server object: $svcPacks = New-Object -typeName .Server($computer) To answer question, I think that the real issue that encountering is that this script will not work against SQL servers that have multiple instances. So, adding in the else statements, shortening the version strings, and using -match your code block will look something like this: # Sets the server versions You were trying to check the version $vs2005sp4 = "" but the VersionString property is going to return ".00" which if you use -eq doesn't work, but if you use -match it will work. That way if your version string has a better chance of matching if the version string doesn't match exactly. The other thing I would do is instead of using -eq in your if statements, use -match and shorten your version string. Then it won't continue, and evaluate if it could be the other versions. So if it fails the first evaluation: if($versionBuild -eq $vs2008r2sp2) When evaluating your $VersionBuild, you don't have any else statements. Well, from the looks of it, it's a small mistake. $msg.Body = get-content $servicePackReport $msg.From = "Environment Service Pack Report for $titledate" Write-Host "Sending Email notification to $user" # Send Notification if alert $i is greater then 0 SQL Server 2005 with SP4 - " $vs2005sp4 "Īdd-Content $servicePackReport $tableDescription # Create table at end of report showing legend of colors for the critical and warning Write-Host -ForegroundColor DarkYellow "$computer $deviceID service pack build = $versionBuild" # If statement needed to remove label that were null # Set background color to orange if service pack is 2005 SP4 # Set background color to yellow if service pack is 2008 SP3 # Set background color to green if service pack is 2008r2 SP2 $svcPacks = New-Object -typeName .Server($computer) #$svcPacks = Get-WmiObject -ComputerName $computer -Class "_NAMESPACE" -namespace "root\Microsoft\SqlServer\ReportServer" Get-ChildItem $reportPath | Where-Object | Sort-Object -property "name" $DateToDelete = $CurrentDate.AddDays($Daysback) # Remove the report if it has already been run today so it does not append to the existing report $datetime = Get-Date -Format "MM-dd-yyyy_HHmmss" $servers = Get-Content "c:\Scripts\InPutFiles\servers.txt" # Count if any computers have low disk space. $servicePackReport = $reportPath $reportName $reportName = "ServicePackRpt_$(get-date -format ddMMyyyy).html" $users = # I use this for testing by uing my email address. I think I am having trouble with the $svcPack variable and the corresponding variables that find the data needed. txt doc and find the SQL instances that are on that server as well as the sql service pack version build for each instance. I am trying to create a script to look at a list of servers from a. ![]()
0 Comments
Leave a Reply. |