Windows updates Notification By Mail

I manage more than 300 Server  , and there are about 100 Windows platform , The problem  that they are not connected on same domain and some solutions such as WSUS can’t be performed due to the nature of this environment.

Administrators are responsible for updating their servers  and i can’t trace if they are doing what they paid for or not ! so this process should be automated , i merged many scripts into two small scripts which will do this for me.

# PowerShell is needed for sure to complete the JOB

1# Prepare PowerShell to run the scripts

– Open the power shell and type “Set-ExecutionPolicy RemoteSigned

To know what is this mean read this article:http://powershell.com/cs/forums/p/2621/3508.aspx

2# First Script : collect.vbs

collect.vbs “Make sure the extension is vbs” will be responsible to search for updates on the machine same as windows update agent behave and if there is no updates it will simply echo that there are no applicable updates :


Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")

WScript.Echo "List of applicable items on the machine:"

For I = 0 To searchResult.Updates.Count-1
 Set update = searchResult.Updates.Item(I)
 WScript.Echo I + 1 & "> " & update.Title
Next

If searchResult.Updates.Count = 0 Then
 WScript.Echo "There are no applicable updates."
 WScript.Quit
End If

3# Now make small patch “.bat” contain the following line to redirect the output of the below script to txt file


cscript c:/collect.vbs > " Redirect the output of the script on txt file set here the destenation of the file"

for example


cscript c:/collect.vbs > c:/basem.txt

and you can name it basem.bat for example

4 # Second script “notify.ps1″ to get the txt file ” The output of the first script ” and sent it via mail to your mail address


$filename = “PATH TO UPDATES FILE”
$smtpServer = “Your SMTP Server”

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “Your Mail Address”
$msg.To.Add(“Recepient Mail Address”)
$msg.To.Add(“Another Recepient Mail Address”)

$msg.Subject = “Mail Subject ”
$msg.Body = "Write whatever you need in the body
$msg.Attachments.Add($att)
$smtp.Send($msg)

5# Last patch “.bat” to make the notify.ps1 will contain the below to be  executed automatically via scheduled task :


powershell.exe -nologo -command "&{c:/notify.ps1}"

if the path of the notify.ps1 script exist on c:/ for sure if not you can set whatever the source location

6# Make the patches we created on scheduled tasks every whatever the time you need , for me i make it every 48 hr and make sure that collect patch scheduled 10 or 15 minutes before the notify patch

BR,

Bassem

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s