Windows Vista Forums

WSUS "restart needed" email

  1. #1


    Bill Guest

    WSUS "restart needed" email

    Hello,

    I've attempted to modify the script located at:
    http://www.microsoft.com/technet/scr....mspx?mfr=true
    It lists the computers neededing a restart after updates have been installed
    (we currently have configured to not restart if a user is logged on via GPO).

    My modification to send the info via email works fine if run manually but if
    run as a scheduled task the email is not sent. I have other powershell
    scripts that run fine as scheduled tasks but I am at a loss on this one. Any
    assistance is appreciated. Bill

    The line "If ($all -eq $null)" is set for testing. Currently there are no
    computers that need restarting so the -eq $null sends the email, just with no
    computers listed (well, it does if run manually anyway)

    The script:

    [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null

    if (!$wsus) {
    $wsus =
    [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
    }

    $computerScope = new-object
    Microsoft.UpdateServices.Administration.ComputerTargetScope;
    $computerScope.IncludedInstallationStates =
    [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;



    $updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
    $updateScope.IncludedInstallationStates =
    [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;

    $computers = $wsus.GetComputerTargets($computerScope);

    $all = $computers | foreach-object {
    $_.FullDomainName | Out-Null;
    }
    If ($all -eq $null) {
    $emailFrom = "WSUS@xxxxxx"
    $emailTo = "user@xxxxxx"
    $subject = "Server Restart Required"
    $bText1 = "The below server(s) have received Windows Updates and are in need
    of a restart:" + "`r`n"
    $bText2 = "`r`n" + $all + "`r`n"
    $bText3 = "The server(s) most likely have a user logged on." + "`r"
    $bText4 = "WSUS is configured to NOT restart a server if a user is logged on
    `r`n"
    $body = $bText1 + $bText2 + $bText3 + $bText4
    $smtpServer = "SMTPSERVER"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($emailFrom, $emailTo, $subject, $body)
    }

      My System SpecsSystem Spec

  2. #2


    ClaudioG64 Guest

    Re: WSUS "restart needed" email

    On Jan 27, 7:09*pm, Bill <B...@xxxxxx> wrote:

    > Hello,
    >
    > I've attempted to modify the script located at:http://www.microsoft.com/technet/scr...us/default.msp...
    > It lists the computers neededing a restart after updates have been installed
    > (we currently have configured to not restart if a user is logged on via GPO).
    >
    > My modification to send the info via email works fine if run manually butif
    > run as a scheduled task the email is not sent. I have other powershell
    > scripts that run fine as scheduled tasks but I am at a loss on this one. Any
    > assistance is appreciated. Bill
    >
    > The line "If ($all -eq $null)" is set for testing. Currently there are no
    > computers that need restarting so the -eq $null sends the email, just with no
    > computers listed (well, it does if run manually anyway)
    >
    > The script:
    >
    > [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
    >
    > if (!$wsus) {
    > * * * * $wsus =
    > [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
    >
    > }
    >
    > $computerScope = new-object
    > Microsoft.UpdateServices.Administration.ComputerTargetScope;
    > $computerScope.IncludedInstallationStates =
    > [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
    >
    > $updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
    > $updateScope.IncludedInstallationStates =
    > [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
    >
    > $computers = $wsus.GetComputerTargets($computerScope);
    >
    > $all = $computers | foreach-object {
    > * * * * * * * * $_.FullDomainName | Out-Null;}
    >
    > If ($all -eq $null) {
    > $emailFrom = "W...@xxxxxx"
    > $emailTo = "u...@xxxxxx"
    > $subject = "Server Restart Required"
    > $bText1 = "The below server(s) have received Windows Updates and are inneed
    > of a restart:" + "`r`n"
    > $bText2 = "`r`n" + $all + "`r`n"
    > $bText3 = "The server(s) most likely have a user logged on." + "`r"
    > $bText4 = "WSUS is configured to NOT restart a server if a user is logged on
    > `r`n"
    > $body = *$bText1 + $bText2 + $bText3 + $bText4
    > $smtpServer = "SMTPSERVER"
    > $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    > $smtp.Send($emailFrom, $emailTo, $subject, $body)
    >
    > }
    Hello,
    I've created a Powershell script for doing it, using the same Technet
    sample code.

    Its's part of my "WSUS Powertoolkit", now updated to version 1.1.

    You can find it here:
    http://www.pulsarit.net/cs/blogs/cla...olkit-1-1.aspx

    Please feel free to download and customize it (then share your
    thoughts ).

    Ciao, Claudio

    MCSA, MCSE, MCT
    http://www.pulsarit.net/cs/blogs/claudiog/

      My System SpecsSystem Spec

WSUS "restart needed" email

Similar Threads
Thread Thread Starter Forum Replies Last Post
REPOST -- Placement of Email in "Inbox" and in "Sent Items" MLS Vista mail 1 24 Mar 2009
"Restart" vs. "Shut down" Ken Isaacson Vista General 5 31 Dec 2008
Unwanted Multiple contacts in "To","CC","BCC" of email send catago xsailer Vista mail 2 12 Oct 2008
Popup of "Brother MFL pro Control Center" upon restart of my Vista PC chousim@gmail.com Vista print fax & scan 0 12 Aug 2007
Can' t open "creat a new email" or "replay" an email arbitros Vista mail 1 12 Apr 2007