Unable to run WSUS Reporting script


hey guys,

i trying put script report status of wsus client updates after os patching activity , found this: http://get-mailbox.net/wsus-reporting-with-powershell-part-3

script running embedded below. upon running in ps on wsus server, loads of methodexception errors.  powershell transcript output embeded below review. had add/delete lot of " ` " characters still hitting unknown roadblock. can please review script , associated errors , advise how working? also, if inferior script, welcome point me better.

script:

###########################  $wsusserver = "zidcwsus01"  # load wsus assembly:  [void][reflection.assembly]::loadwithpartialname("microsoft.updateservices.administration") | out-null  #  # connect wsus , set connection variable future use.   # use $true force connection via ssl  # enter port number used.  $wsus = [microsoft.updateservices.administration.adminproxy]::getupdateserver($wsusserver,$false)  #  # in order make queries within wsus we’ll using getsummariespercomputertarget method  # method requires computer scope , additionally using update scope refine query.  # first create default update scope , modify include latest approved revisions.  $updatescope = new-object microsoft.updateservices.administration.updatescope  $updatescope.approvedstates = [microsoft.updateservices.administration.approvedstates]::latestrevisionapproved  #  # create computer scope  $computerscope = new-object microsoft.updateservices.administration.computertargetscope  #  #return groups have established in wsus console:  $wsus.getcomputertargetgroups()  #  # identify 1 of group ids , use where-object filter specific group , set variable.   # enumerate members of group:  $computertargetgroups = $wsus.getcomputertargetgroups() | {$_.id -eq 'aa60f906-b555-4b81-bd3b-a050fde63ce8'}  $memberofgroup = $wsus.getcomputertargetgroup($computertargetgroups.id).getcomputertargets()  #  # have detailed information each computer object member of wsus group stored in $memberofgroup variable.  # we’ll use find out updates needed members of group  # query group in wsus , provide summary of computers need updates recent synchronization.  # create empty arrays contain collected data.  $updatestatus = @()  $summarystatus = @()  #  # use foreach loop process summaries per computer each  #  member of "email servers" group. populate array  #  updates needed.  foreach ($object in $wsus.getsummariespercomputertarget($updatescope,$computerscope)) {      # use nested foreach process mail servers members.      foreach ($object1 in $memberofgroup){          # use if statement match wsus objects contains update summaries      #  members of mail servers members.          if ($object.computertargetid -match $object1.id) {          # set fulldomain name of mail server member in variable.          $computertargettoupdate = $wsus.getcomputertargetbyname($object1.fulldomainname)          # filter server updates marked install state          #  being either downloaded or notinstalled.  these updates needed.          $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate() | {($_.updateapprovalaction -eq "install") -and       (($_.updateinstallationstate -eq "downloaded") -or       ($_.updateinstallationstate -eq "notinstalled"))}         # null out following variables don't contaminate      #  op_addition variables in below nested foreach loop.      $failedupdatereport = $null      $neededupdatereport = $null       # use nested foreach loop accumulate , convert needed updates `       # kb number url in html format.       if ($neededupdate -ne $null){        foreach ($update in $neededupdate){            $myobject2 = new-object -typename psobject         $myobject2 | add-member -type noteproperty -name server -value (($object1 | select -expandproperty fulldomainname) -replace ".get-mailbox.net", "")         $myobject2 | add-member -type noteproperty -name update -value ('<a>' + (($wsus.getupdate([guid]$update.updateid)).title) + '<' + '/' + 'a' + '>')         $updatestatus += $myobject2           if ($update.updateinstallationstate -eq "failed"){         $failedupdatereport += ('</a><a>' + "(" + (($wsus.getupdate([guid]$update.updateid)).knowledgebasearticles) + ") " +     '<' + '/' + 'a' + '>')        }        if ($update.updateinstallationstate -eq "notinstalled" -or $update.updateinstallationstate -eq "downloaded"){   $neededupdatereport += ('</a><a>' + "(" + (($wsus.getupdate([guid]$update.updateid)).knowledgebasearticles) + ") " + '<' +     '/' + 'a' + '>')        }       }      }      # create custom psobject contain summary data each server , updates    needed.      $myobject1 = new-object -typename psobject      $myobject1 | add-member -type noteproperty -name server -value (($object1 | select -expandproperty fulldomainname) -replace ".d1.na.ihs.gov", "")      $myobject1 | add-member -type noteproperty -name unkowncount -value $object.unknowncount      $myobject1 | add-member -type noteproperty -name notinstalledcount -value  $object.notinstalledcount      $myobject1 | add-member -type noteproperty -name notapplicable -value $object.notapplicablecount      $myobject1 | add-member -type noteproperty -name downloadedcount -value $object.downloadedcount      $myobject1 | add-member -type noteproperty -name installedcount -value $object.installedcount      $myobject1 | add-member -type noteproperty -name installedpendingrebootcount -value $object.installedpendingrebootcount      $myobject1 | add-member -type noteproperty -name failedcount -value $object.failedcount      $myobject1 | add-member -type noteproperty -name computertargetid -value $object.computertargetid      $myobject1 | add-member -type noteproperty -name neededcount -value ($neededupdate | measure).count      $myobject1 | add-member -type noteproperty -name failed -value $failedupdatereport      $myobject1 | add-member -type noteproperty -name needed -value $neededupdatereport      $summarystatus += $myobject1      }    }  }     # return values interesting.  $summarystatus | select server,notinstalled*,downloaded*,installedpending*,failed*,needed* | ft  # filtering returned data little further , using html formatting send acceptable looking report.  # filter results trim down report.  # use html formatting prepare email.  # send report via html formatted email.  # record last time wsus syncronized updates microsoft.   $lastsync = ($wsus.getsubscription()).lastsynchronizationtime     # rewrite array , eliminate servers have 0 needed updates.   $summarystatus = $summarystatus | {$_.neededcount -ne 0} | sort server     # list summary of changes in special table leveraging "first" table class style listed above.   $wsushead += "<table class=`"first`">`r`n"   # note lastsync time.   $wsushead += "<tr><td class=`"first`"><b>last sync:</b></td><td class=`"first`">" +   $lastsync + "</td></tr>`r`n"   $wsushead += "</body>`r`n"   $wsushead += "</style>`r`n"   $wsushead += "</head>`r`n"     # create generic html header use throughout script body of    #  email message table styles control formatting of tables present it.   $htmlhead = "<html xmlns=`"http://www.w3.org/1999/xhtml`">`r`n"   $htmlhead += "<head>`r`n"   $htmlhead += "<style>`r`n"   $htmlhead += "table{border-width: 1px;border-style: outset;border-color: `   black;border-spacing: 1px;border-collapse: separate;}`r`n"   $htmlhead += "th{border-width: 1px;padding: 1px;border-style:   inset;border-color: black;}`r`n"   $htmlhead += "td{border-width: 1px;padding-left: 3px;padding-right: `   3px;border-style: inset;border-color: black;}`r`n"   $htmlhead += "table.first{border-style: none;}`r`n"   $htmlhead += "td.first{border-style: none;}`r`n"   $htmlhead += "</style>`r`n"   $htmlhead += "</head>`r`n"   $htmlhead += "<body>`r`n"     # build variable html sending report.   $updateshtml = $htmlhead   # continue building html updates needed   $updateshtml += $summarystatus | convertto-html -fragment    @{label="server";expression={$_.server}}, @{label="needed count";expression={$_.neededcount}}, @{label="not     installed";expression={$_.notinstalledcount}}, `   @{label="downloaded";expression={$_.downloadedcount}}, @{label="pending reboot";expression=    {$_.installedpendingrebootcount}}, @{label="failed updates";expression={$_.failedcount}}, `   @{label="needed";expression={$_.needed}}     # add assembly fix powershell html markup. ensures special characters   # converted correctly.   add-type -assemblyname system.web   $updateshtml = [system.web.httputility]::htmldecode($updateshtml)     # create html email adding various html sections above.   $mailmessage= "   <html>   <body>   $wsushead   $updateshtml   </body>   </html>   "     # date , time.   $datetime = get-date -format "ddd mm/dd/yyyy h:mm tt"   # set subject line include $datetime variable.   $emailsubject = "update status " + $datetime     # send email compiled data.   [string[]] $emailto = "xxxxxxxxy@yyyyyy.com"   send-mailmessage -to $emailto `   -subject $emailsubject -from "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" `   -body $mailmessage -bodyashtml `   -smtpserver "mailrelayserver"


errors (truncated fit):

**********************  windows powershell transcript start  start time: 20140313193454  username  : zidcwsus01\p12345   machine	  : zidcwsus01 (microsoft windows nt 6.1.7601 service pack 1)   **********************  transcript started, output file d:\scripts\output.txt  ps d:\scripts> .\wsus_report_2.ps1    updateserver                            id                                      name                                     ------------                            --                                      ----                                     microsoft.updateservices.internal.ba... cedbf2-a30e-4f0d-82c8-008a8069f    abc                                       microsoft.updateservices.internal.ba... b7ed-5727-47f3-84de-015e03f688a    unassigned computers                     microsoft.updateservices.internal.ba... e97deb-848f-4d23-9709-084896736    def                       microsoft.updateservices.internal.ba... ae9ba0-0604-4cec-a2eb-0a967ae3b    ghi                                      microsoft.updateservices.internal.ba... 7c1c2-7ec7-4eed-a086-0b6067757a    blah blah                           microsoft.updateservices.internal.ba... 79eaf-397e-41ca-98-0df676767955    test01                                                                     cannot convert argument "0", value: "", "getcomputertargetgroup" type "system.guid": "cannot convert null t  o type "system.guid"."  @ d:\scripts\wsus_report_2.ps1:26 char:46  + $memberofgroup = $wsus.getcomputertargetgroup <<<< ($computertargetgroups.id).getcomputertargets()      + categoryinfo          : notspecified: (:) [], methodexception      + fullyqualifiederrorid : methodargumentconversioninvalidcastargument     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull     exception calling "getcomputertargetbyname" "1" argument(s): "specified argument out of range of valid val  ues.  parameter name: specified argument out of range of valid values.  parameter name: name"  @ d:\scripts\wsus_report_2.ps1:45 char:64  +         $computertargettoupdate = $wsus.getcomputertargetbyname <<<< ($object1.fulldomainname)      + categoryinfo          : notspecified: (:) [], methodinvocationexception      + fullyqualifiederrorid : dotnetmethodexception     cannot call method on null-valued expression.  @ d:\scripts\wsus_report_2.ps1:48 char:83  +         $neededupdate = $computertargettoupdate.getupdateinstallationinfoperupdate <<<< () | {($_.updateapprova  laction -eq "install") -and       + categoryinfo          : invalidoperation: (getupdateinstallationinfoperupdate:string) [], runtimeexception      + fullyqualifiederrorid : invokemethodonnull            ps d:\scripts> stop-transcript | out-null  **********************  windows powershell transcript end  end time: 20140313193617  **********************  

os: windows 2008 r2 std sp1

wsus version: 3.2.7600.226

thanks reply daniel :)

i got script work ....finally! bunch boe prox article (below) , scott's original script used (link below). had update wsus group guids target groups

#$computertargetgroups = $wsus.getcomputertargetgroups() ` | {$_.id -eq 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}

and set 'all computers' guid. tailored $updatescope options shown boe , have working script.....phew! again guys :)

now remains exclude guids target groups , sort results in report per wsus group (for think cannot use 'all computers' guid in target group). guess  original reson post answered. should post new 1 these questions?

http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/19/use-powershell-to-find-missing-updates-on-wsus-client-computers.aspx

http://get-mailbox.net/wsus-reporting-with-powershell-part-3



Windows Server  >  WSUS



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client