Initially, that solution was deployed with success on that farm, but for a weird reason that we couldn’t found out the why, that solution begun displaying an error on its status, as described on the screen shot below:
Based on this scenario, we decided to build a PowerShell to check all solutions status on our farms. If it find some solution with error status, it will create a log file pointing the name and the status of the solution and send by email this alert for the administrators.
Here is the PowerShell code:
####################
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
$ServerName = $env:computername
function sendMail($MailMSG) {
#Write-Host “Sending Email”
$attach = new-object Net.Mail.Attachment($MailMSG)
###First, the administrator must change the mail message values in this section
$FromAddress = “adm-web@sharepoint.com.br” #change by your email address
$ToAddress = “adm-web@sharepoint.com.br” #change by your email address
$MessageSubject = “$ServerName – Alert – Solution Undeployed on Farm”
#$MessageBody = $MailMSG
$MessageBody = “Please verify the attached”
$SendingServer = “smtp.yourcompany.com” #change by your smt server
###Create the mail message
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$SMTPMessage.Attachments.Add($attach)
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
$attach.dispose()
}
# Get current date and format it to avoid invalid characters such as “/” and “:”
$today=Get-Date -format “MM-dd-yyyy HH.mm.ss”
# Replace with your script location
$Location=”D:\Softwares\CheckFarmSolutionScript”
# Replace with your desired log file location + name
$logFile=”$Location\LogSOLUTIONS.log”
If (Test-Path $logFile){
Remove-Item $logFile -Confirm:$false
}
function List-Solutions()
{
$farm = Get-SPFarm
foreach ($solution in $farm.Solutions)
{
if($solution.Deployed -eq $false){
Write “Solution Verification started at $today” >>$logFile
Get-SPSolution -identity $solution.Name >>$logFile
}
}
}
#call the function List-Solutions
#test if the log file exists, If yes, send an email
If (Test-Path $logFile){
sendMail($logFile)
}
####################