PoshCode Logo PowerShell Code Repository

WSUS Admin Module by Boe Prox 6 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2360"></script>download | new post

This module allows you to manage WSUS from PowerShell. Save code as a .psm1 file and use the Import-Module command for this module. You can approve/decline updates, perform synchronizations, add/remove clients from a target group, create/delete Target groups and much more with currently 40 advanced functions. For more information about this module, please see my blog http://boeprox.wordpress.com/

  1. Write-Host "`n"
  2. Write-Host "`t`tWSUS Administrator Module 1.0"
  3. Write-Host "`n"
  4. Write-Host -nonewline "Make initial connection to WSUS Server:`t"
  5. Write-Host -fore Yellow "Connect-WSUSServer"
  6. Write-Host -nonewline "Disconnect from WSUS Server:`t`t"
  7. Write-Host -fore Yellow "Disconnect-WSUSServer"
  8. Write-Host -nonewline "List all available commands:`t`t"
  9. Write-Host -fore Yellow "Get-WSUSCommands"
  10. Write-Host "`n"
  11.  
  12. function Get-WSUSCommands {
  13. <#  
  14. .SYNOPSIS  
  15.     Lists all WSUS functions available from this module.
  16. .DESCRIPTION
  17.     Lists all WSUS functions available from this module.    
  18. .NOTES  
  19.     Name: Get-WSUSCommand
  20.     Author: Boe Prox
  21.     DateCreated: 18Oct2010
  22.            
  23. .LINK  
  24.     https://boeprox.wordpress.org
  25. .EXAMPLE
  26. Get-WSUSCommands
  27.  
  28. Description
  29. -----------
  30. This command lists all of the available WSUS commands in the module.      
  31. #>
  32. [cmdletbinding()]  
  33. Param ()
  34.  
  35. #List all WSUS functions available
  36. Get-Command *WSUS*  -CommandType Function  | Sort-Object Name
  37. }
  38.  
  39. function Connect-WSUSServer {
  40. <#  
  41. .SYNOPSIS  
  42.     Retrieves the last check-in times of clients on WSUS.
  43. .DESCRIPTION
  44.     Retrieves the last check-in times of clients on WSUS. You will need to run this on a machine that
  45.     has the WSUS Administrator console installed.
  46. .PARAMETER WsusServer
  47.     Name of WSUS server to query against.          
  48. .PARAMETER Secure
  49.     Determines if a secure connection will be used to connect to the WSUS server. If not used, then a non-secure
  50.     connection will be used.    
  51. .NOTES  
  52.     Name: Get-LastCheckIn
  53.     Author: Boe Prox
  54.     DateCreated: 24SEPT2010
  55.            
  56. .LINK  
  57.     https://boeprox.wordpress.org
  58. .EXAMPLE
  59. Connect-WSUSServer -wsusserver "server1"
  60.  
  61. Description
  62. -----------
  63. This command will make the connection to the WSUS using an unsecure port (Default:80).
  64. .EXAMPLE
  65. Connect-WSUSServer -wsusserver "server1"  -secure
  66.  
  67. Description
  68. -----------
  69. This command will make a secure connection (Default: 443) to a WSUS server.    
  70.        
  71. #>
  72. [cmdletbinding(
  73.         DefaultParameterSetName = 'wsus',
  74.         ConfirmImpact = 'low'
  75. )]
  76.     Param(
  77.         [Parameter(
  78.             Mandatory = $True,
  79.             Position = 0,
  80.             ParameterSetName = 'wsus',
  81.             ValueFromPipeline = $True)]
  82.             [string]$WsusServer,                    
  83.         [Parameter(
  84.             Mandatory = $False,
  85.             Position = 1,
  86.             ParameterSetName = 'wsus',
  87.             ValueFromPipeline = $False)]
  88.             [switch]$Secure                    
  89.             )            
  90. #Load required assemblies            
  91. [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
  92. #Make connection to WSUS server
  93. Write-Host -ForegroundColor Yellow "Attempting connection to WSUS Server: $($wsusserver)"  
  94. $ErrorActionPreference = 'stop'
  95. Try {
  96.     If ($secure) {
  97.         $Global:wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusserver,$True)
  98.         $Wsus | FT Name, Version,PortNumber
  99.         }
  100.     Else {
  101.         $Global:wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusserver,$False)
  102.         $Wsus | FT Name, Version,PortNumber
  103.         }
  104.     }
  105. Catch {
  106.     Write-Error "Unable to connect to $($wsusserver)!`n$($error[0])"
  107.     }                
  108. }
  109.  
  110. function Disconnect-WSUSServer {
  111. <#  
  112. .SYNOPSIS  
  113.     Disconnects session against WSUS server.
  114. .DESCRIPTION
  115.     Disconnects session against WSUS server.
  116. .NOTES  
  117.     Name: Disconnect-WSUSServer
  118.     Author: Boe Prox
  119.     DateCreated: 27Oct2010
  120.            
  121. .LINK  
  122.     https://boeprox.wordpress.org
  123. .EXAMPLE
  124. Disconnect-WSUSServer
  125.  
  126. Description
  127. -----------
  128. This command will disconnect the session to the WSUS server.  
  129.        
  130. #>
  131. [cmdletbinding()]  
  132. Param ()
  133. #Disconnect WSUS session by removing the variable  
  134. Remove-Variable -Name wsus -Force
  135. }
  136.  
  137. function Get-WSUSClients {
  138. <#  
  139. .SYNOPSIS  
  140.     Retrieves a list of all of the clients in WSUS.
  141. .DESCRIPTION
  142.     Retrieves a list of all of the clients in WSUS.  
  143. .NOTES  
  144.     Name: Get-WSUSClients
  145.     Author: Boe Prox
  146.     DateCreated: 24SEPT2010
  147.            
  148. .LINK  
  149.     https://boeprox.wordpress.org
  150. .EXAMPLE
  151. Get-WSUSClients
  152.  
  153. Description
  154. -----------
  155. This command will list every client in WSUS.  
  156.        
  157. #>
  158. [cmdletbinding()]  
  159. Param ()
  160. #Gather all computers in WSUS    
  161. $wsus.GetComputerTargets()
  162. }
  163.        
  164.  
  165. function Start-WSUSSync {
  166. <#  
  167. .SYNOPSIS  
  168.     Start synchronization on WSUS server.
  169. .DESCRIPTION
  170.     Start synchronization on WSUS server.
  171. .PARAMETER Monitor
  172.     Starts a synchronization and runs a background job to monitor currently running content download and
  173.     notifies user when completed.        
  174. .NOTES  
  175.     Name: Start-WSUSSync
  176.     Author: Boe Prox
  177.     DateCreated: 24SEPT2010
  178.            
  179. .LINK  
  180.     https://boeprox.wordpress.org
  181. .EXAMPLE
  182. Start-WSUSSync
  183.  
  184. Description
  185. -----------
  186. This command will begin a manual sychronization on WSUS with the defined update source.
  187. .EXAMPLE
  188. Start-WSUSSync -monitor
  189.  
  190. Description
  191. -----------
  192. This command will begin a manual synchronization on WSUS and will begin a background job that will notifiy via
  193. pop-up message when the synchronization has completed.      
  194.        
  195. #>
  196. [cmdletbinding(
  197.         DefaultParameterSetName = 'monitor',
  198.         ConfirmImpact = 'low',
  199.     SupportsShouldProcess = $True
  200. )]
  201. Param (
  202.     [Parameter(
  203.         Mandatory = $False,
  204.         Position = 0,
  205.         ParameterSetName = 'monitor',
  206.         ValueFromPipeline = $False)]
  207.         [switch]$Monitor
  208.     )
  209. $sub = $wsus.GetSubscription()    
  210. $sync = $sub.GetSynchronizationProgress()    
  211. If ($monitor) {
  212.     #Stop and remove any jobs for SyncMonitoring
  213.     $jobs = Get-Job | ? {$_.Name -eq "WSUSSyncProgressMonitor"}
  214.     If ($jobs) {
  215.         $jobs | Stop-Job
  216.         $jobs | Remove-Job
  217.         }
  218.     #Start WSUS synchronization
  219.     If ($pscmdlet.ShouldProcess($($wsus.name))) {
  220.             $sub.StartSynchronization()  
  221.             "Synchronization have been started."
  222.             Start-Sleep -Seconds 3
  223.         Start-Job -Name "WSUSSyncProgressMonitor" -ArgumentList $sync -ScriptBlock {
  224.             Param (
  225.                 $sync
  226.                 )
  227.             #Load required assemblies for message window    
  228.             [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms)                        
  229.             While ($sync.Phase -ne "NotProcessing") {
  230.                 $null
  231.                 }
  232.             [System.Windows.Forms.MessageBox]::Show("Synchronization has been completed on WSUS",”Information”)            
  233.             } | Out-Null
  234.         }            
  235.     }
  236. Else {
  237.     #Start WSUS synchronization
  238.     If ($pscmdlet.ShouldProcess($($wsus.name))) {
  239.         $sub.StartSynchronization()  
  240.         "Synchronization have been started."
  241.         }
  242.     }
  243. }        
  244.  
  245. function Stop-WSUSSync {
  246. <#  
  247. .SYNOPSIS  
  248.     Stops a currently running WSUS sync.
  249. .DESCRIPTION
  250.     Stops a currently running WSUS sync.
  251. .NOTES  
  252.     Name: Stop-WSUSSync
  253.     Author: Boe Prox
  254.     DateCreated: 24SEPT2010
  255.            
  256. .LINK  
  257.     https://boeprox.wordpress.org
  258. .EXAMPLE
  259. Stop-WSUSSync  
  260.  
  261. Description
  262. -----------
  263. This command will stop a currently running WSUS synchronization.
  264.        
  265. #>
  266. [cmdletbinding(
  267.         DefaultParameterSetName = 'update',
  268.         ConfirmImpact = 'low',
  269.     SupportsShouldProcess = $True
  270. )]
  271.     Param()
  272. $sub = $wsus.GetSubscription()      
  273. #Cancel synchronization running on WSUS      
  274. If ($pscmdlet.ShouldProcess($($wsus.name))) {
  275.     $sub.StopSynchronization()
  276.     "Synchronization have been cancelled."
  277.     }    
  278. }        
  279.  
  280. function Get-WSUSSyncHistory {
  281. <#  
  282. .SYNOPSIS  
  283.     Retrieves the synchronization history of the WSUS server.
  284. .DESCRIPTION
  285.     Retrieves the synchronization history of the WSUS server.    
  286. .NOTES  
  287.     Name: Get-WSUSSyncHistory
  288.     Author: Boe Prox
  289.     DateCreated: 24SEPT2010
  290.            
  291. .LINK  
  292.     https://boeprox.wordpress.org
  293. .EXAMPLE
  294. Get-WSUSSyncHistory
  295.  
  296. Description
  297. -----------
  298. This command will list out the entire synchronization history of the WSUS server.  
  299.        
  300. #>
  301. [cmdletbinding()]  
  302. Param ()
  303.  
  304. $sub = $wsus.GetSubscription()
  305. $sub.GetSynchronizationHistory()      
  306. }  
  307.  
  308. function Get-WSUSSyncProgress {
  309. <#  
  310. .SYNOPSIS  
  311.     Displays the current progress of a WSUS synchronization.
  312. .DESCRIPTION
  313.     Displays the current progress of a WSUS synchronization.
  314. .PARAMETER Monitor
  315.     Runs a background job to monitor currently running synchonization and notifies user when completed.      
  316. .NOTES  
  317.     Name: Get-WSUSSyncProgress
  318.     Author: Boe Prox
  319.     DateCreated: 24SEPT2010
  320.            
  321. .LINK  
  322.     https://boeprox.wordpress.org
  323. .EXAMPLE
  324. Get-WSUSSyncProgress
  325.  
  326. Description
  327. -----------
  328. This command will show you the current status of the WSUS sync.
  329. .EXAMPLE
  330. Get-WSUSSyncProgress -monitor    
  331.  
  332. Description
  333. -----------
  334. This command will begin a background job that will notify you when the WSUS synchronization
  335. has been completed.
  336.        
  337. #>
  338. [cmdletbinding()]  
  339. Param (
  340.     [Parameter(
  341.         Mandatory = $False,
  342.         Position = 0,
  343.         ParameterSetName = 'monitor',
  344.         ValueFromPipeline = $False)]
  345.         [switch]$Monitor
  346.     )
  347. $sub = $wsus.GetSubscription()    
  348. If ($monitor) {
  349.     $job = Get-Job
  350.     If ($job) {
  351.         $job = Get-Job -Name "WSUSSyncProgressMonitor"
  352.         }
  353.     If ($job) {
  354.         Get-Job -Name "WSUSSyncProgressMonitor" | Stop-Job
  355.         Get-Job -Name "WSUSSyncProgressMonitor" | Remove-Job
  356.         }    
  357.     Start-Job -Name "WSUSSyncProgressMonitor" -ArgumentList $sub -ScriptBlock {
  358.         Param (
  359.             $sub
  360.             )
  361.         #Load required assemblies for message window    
  362.         [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms)                        
  363.         While (($sub.GetSynchronizationProgress()).Phase -ne "NotProcessing") {
  364.             $null
  365.             }
  366.         [System.Windows.Forms.MessageBox]::Show("Synchronization has been completed on WSUS",”Information”)            
  367.         } | Out-Null
  368.     }
  369. Else {
  370.     #Gather all child servers in WSUS    
  371.     $sub.GetSynchronizationProgress()
  372.     }
  373.      
  374. }  
  375.  
  376. function Get-WSUSEvents {
  377. <#  
  378. .SYNOPSIS  
  379.     Retrieves all WSUS events.
  380. .DESCRIPTION
  381.     Retrieves all WSUS events from the WSUS server.  
  382. .NOTES  
  383.     Name: Get-WSUSEvents
  384.     Author: Boe Prox
  385.     DateCreated: 24SEPT2010
  386.            
  387. .LINK  
  388.     https://boeprox.wordpress.org
  389. .EXAMPLE
  390. Get-WSUSEvents  
  391.  
  392. Description
  393. -----------
  394. This command will show you all of the WSUS events.
  395.        
  396. #>
  397. [cmdletbinding()]  
  398. Param ()
  399.  
  400. $sub = $wsus.GetSubscription()
  401. $sub.GetEventHistory()      
  402. }  
  403.  
  404. function Get-WSUSGroups {
  405. <#  
  406. .SYNOPSIS  
  407.     Retrieves all of the WSUS Target Groups.
  408. .DESCRIPTION
  409.     Retrieves all of the WSUS Target Groups.    
  410. .NOTES  
  411.     Name: Get-WSUSGroups
  412.     Author: Boe Prox
  413.     DateCreated: 24SEPT2010
  414.            
  415. .LINK  
  416.     https://boeprox.wordpress.org
  417. .EXAMPLE
  418. Get-WSUSGroups  
  419.  
  420. Description
  421. -----------
  422. This command will list out all of the WSUS Target groups and their respective IDs.
  423.        
  424. #>
  425. [cmdletbinding()]  
  426. Param ()
  427.  
  428. $wsus.GetComputerTargetGroups()      
  429. }  
  430.  
  431. function Get-WSUSServer {
  432. <#  
  433. .SYNOPSIS  
  434.     Retrieves connection and configuration information from the WSUS server.
  435. .DESCRIPTION
  436.     Retrieves connection and configuration information from the WSUS server.
  437. .PARAMETER Configuration
  438.     Lists more configuration information from WSUS Server      
  439. .NOTES  
  440.     Name: Get-WSUSServer
  441.     Author: Boe Prox
  442.     DateCreated: 24SEPT2010
  443.            
  444. .LINK  
  445.     https://boeprox.wordpress.org
  446. .EXAMPLE
  447. Get-WSUSServer
  448.  
  449. Description
  450. -----------
  451. This command will display basic information regarding the WSUS server.
  452. .EXAMPLE
  453. Get-WSUSServer -configuration      
  454.  
  455. Description
  456. -----------
  457. This command will list out more detailed information regarding the configuration of the WSUS server.
  458.        
  459. #>
  460. [cmdletbinding(
  461.         DefaultParameterSetName = 'wsus',
  462.         ConfirmImpact = 'low'
  463. )]
  464.     Param(                        
  465.         [Parameter(
  466.             Mandatory = $False,
  467.             Position = 0,
  468.             ParameterSetName = 'wsus',
  469.             ValueFromPipeline = $False)]
  470.             [switch]$Configuration                    
  471.             )                    
  472. If ($configuration) {
  473.     $wsus.GetConfiguration()
  474.     }
  475. Else {
  476.     $wsus
  477.     }        
  478. }  
  479.  
  480. function Get-WSUSUpdates {
  481. <#  
  482. .SYNOPSIS  
  483.     Retrieves all of the updates from a WSUS server.
  484. .DESCRIPTION
  485.     Retrieves all of the updates from a WSUS server.  
  486. .NOTES  
  487.     Name: Get-WSUSUpdates
  488.     Author: Boe Prox
  489.     DateCreated: 24SEPT2010
  490.            
  491. .LINK  
  492.     https://boeprox.wordpress.org
  493. .EXAMPLE
  494. Get-WSUSUpdates  
  495.  
  496. Description
  497. -----------
  498. This command will list out every update that is in WSUS's database whether it has been approved or not.
  499.        
  500. #>
  501. [cmdletbinding()]  
  502. Param ()
  503.  
  504. $wsus.GetUpdates()      
  505. }  
  506.  
  507. function Get-WSUSEmailConfig {
  508. <#  
  509. .SYNOPSIS  
  510.     Retrieves the email notification configuration from WSUS.
  511. .DESCRIPTION
  512.     Retrieves the email notification configuration from WSUS.
  513. .PARAMETER SendTestEmail
  514.     Optional switch that will send a test email to the configured email addresses        
  515. .NOTES  
  516.     Name: Get-WSUSEmailConfig
  517.     Author: Boe Prox
  518.     DateCreated: 24SEPT2010
  519.            
  520. .LINK  
  521.     https://boeprox.wordpress.org
  522. .EXAMPLE
  523.  Get-WSUSEmailConfig
  524.  
  525.  Description
  526. -----------
  527. This command will display the configuration of the email notifications.
  528. .EXAMPLE
  529. Get-WSUSEmailConfig -SendTestEmail    
  530.  
  531. Description
  532. -----------
  533. This command will send a test email to the address or addresses in the To field.
  534.        
  535. #>
  536. [cmdletbinding(
  537.         DefaultParameterSetName = 'wsus',
  538.         ConfirmImpact = 'low'
  539. )]
  540.     Param(                          
  541.         [Parameter(
  542.             Mandatory = $False,
  543.             Position = 0,
  544.             ParameterSetName = 'wsus',
  545.             ValueFromPipeline = $False)]
  546.             [switch]$SendTestEmail                  
  547.             )                  
  548. $email = $wsus.GetEmailNotificationConfiguration()    
  549. If ($SendTestEmail) {
  550.     $email.SendTestEmail()
  551.     Write-Host -fore Green "Test email sent."
  552.     }          
  553. Else {
  554.     $email
  555.     }    
  556. }  
  557.  
  558. function Get-WSUSUpdateCategories {
  559. <#  
  560. .SYNOPSIS  
  561.     Retrieves the list of Update categories available from WSUS.
  562. .DESCRIPTION
  563.     Retrieves the list of Update categories available from WSUS.  
  564. .NOTES  
  565.     Name: Get-WSUSUpdateCategories
  566.     Author: Boe Prox
  567.     DateCreated: 24SEPT2010
  568.            
  569. .LINK  
  570.     https://boeprox.wordpress.org
  571. .EXAMPLE
  572. Get-WSUSUpdateCategories  
  573.  
  574. Description
  575. -----------
  576. This command will list all of the categories for updates in WSUS.
  577.        
  578. #>
  579. [cmdletbinding()]  
  580. Param ()
  581.  
  582. $wsus.GetUpdateCategories()      
  583. }  
  584.  
  585. function Get-WSUSStatus {
  586. <#  
  587. .SYNOPSIS  
  588.     Retrieves a list of all updates and their statuses along with computer statuses.
  589. .DESCRIPTION
  590.     Retrieves a list of all updates and their statuses along with computer statuses.  
  591. .NOTES  
  592.     Name: Get-WSUSStatus
  593.     Author: Boe Prox
  594.     DateCreated: 24SEPT2010
  595.            
  596. .LINK  
  597.     https://boeprox.wordpress.org
  598. .EXAMPLE
  599. Get-WSUSStatus
  600.  
  601. Description
  602. -----------
  603. This command will display the status of the WSUS server along with update statuses.
  604.        
  605. #>
  606. [cmdletbinding()]  
  607. Param ()
  608.  
  609. $wsus.getstatus()      
  610. }  
  611.  
  612. function Set-WSUSEmailConfig {
  613. <#  
  614. .SYNOPSIS  
  615.     Configures the email notifications on a WSUS server.
  616. .DESCRIPTION
  617.     Configures the email notifications on a WSUS server. It is important to note that the email address to send
  618.     the emails to is Read-Only and can only be configured from the WSUS Admin Console. After the settings have been
  619.     changed, the new configuration will be displayed.
  620. .PARAMETER EmailLanguage
  621.     What type of language to send the email in.          
  622. .PARAMETER SenderDisplayName
  623.     The friendly name of where the email is coming from.    
  624. .PARAMETER SenderEmailAddress
  625.     The senders email address
  626. .PARAMETER SendStatusNotification
  627.     Determines if an email will be sent for a status notification    
  628. .PARAMETER SendSyncnotification
  629.     Determines if an email will be sent after a sync by WSUS
  630. .PARAMETER SMTPHostname
  631.     Server name of the smtp server to send email from
  632. .PARAMETER SMTPPort
  633.     Port number to be used to connect to smtp server to send email
  634. .PARAMETER SmtpServerRequiresAuthentication
  635.     Used if smtp server requires authentication
  636. .PARAMETER SmtpUserName  
  637.     Username to submit if required by smtp server
  638. .PARAMETER StatusNotificationFrequency
  639.     Frequency (Daily or Weekly) to send notifications
  640. .PARAMETER StatusNotificationTimeOfDay
  641.     Date/Time to send notifications
  642. .PARAMETER UpdateServer
  643.     Name of the WSUS update server
  644. .PARAMETER SmtpPassword
  645.     Password to user for smtp server connection.    
  646. .NOTES  
  647.     Name: Set-WSUSEmailConfig
  648.     Author: Boe Prox
  649.     DateCreated: 24SEPT2010
  650.            
  651. .LINK  
  652.     https://boeprox.wordpress.org
  653. .EXAMPLE  
  654. Set-WSUSEmailConfig -SenderDisplayName "WSUSAdmin" -SenderEmailAddress "wsusadmin@domain.com"
  655.  
  656. Description
  657. -----------  
  658. This command will change the sender name and email address for email notifications and then display the new settings.      
  659. #>
  660. [cmdletbinding(
  661.         DefaultParameterSetName = 'wsus',
  662.         ConfirmImpact = 'low'
  663. )]
  664.     Param(
  665.         [Parameter(
  666.             Mandatory = $False, Position = 0,
  667.             ParameterSetName = '', ValueFromPipeline = $False)]
  668.             [string]$EmailLanguage,                    
  669.         [Parameter(
  670.             Mandatory = $False, Position = 1,
  671.             ParameterSetName = '', ValueFromPipeline = $False)]
  672.             [string]$SenderDisplayName,                          
  673.         [Parameter(
  674.             Mandatory = $False, Position = 2,
  675.             ParameterSetName = '', ValueFromPipeline = $False)]
  676.             [string]$SenderEmailAddress,  
  677.         [Parameter(
  678.             Mandatory = $False, Position = 3,
  679.             ParameterSetName = '', ValueFromPipeline = $False)]
  680.             [string][ValidateSet("True","False")]$SendStatusNotification,
  681.         [Parameter(
  682.             Mandatory = $False, Position = 4,
  683.             ParameterSetName = '',ValueFromPipeline = $False)]
  684.             [string][ValidateSet("True","False")]$SendSyncnotification,
  685.         [Parameter(
  686.             Mandatory = $False, Position = 5,
  687.             ParameterSetName = '', ValueFromPipeline = $False)]
  688.             [string]$SMTPHostname,
  689.         [Parameter(
  690.             Mandatory = $False, Position = 6,
  691.             ParameterSetName = '', ValueFromPipeline = $False)]
  692.             [int]$SMTPPort,
  693.         [Parameter(
  694.             Mandatory = $False, Position = 7,
  695.             ParameterSetName = '', ValueFromPipeline = $False)]
  696.             [string][ValidateSet("True","False")]$SmtpServerRequiresAuthentication,    
  697.         [Parameter(
  698.             Mandatory = $False, Position = 8,
  699.             ParameterSetName = 'account', ValueFromPipeline = $False)]
  700.             [string]$SmtpUserName,
  701.         [Parameter(
  702.             Mandatory = $False, Position = 9,
  703.             ParameterSetName = '', ValueFromPipeline = $False)]
  704.             [string][ValidateSet("Daily","Weekly")]$StatusNotificationFrequency,
  705.         [Parameter(
  706.             Mandatory = $False, Position = 10,
  707.             ParameterSetName = '', ValueFromPipeline = $False)]
  708.             [string]$StatusNotificationTimeOfDay,
  709.         [Parameter(
  710.             Mandatory = $False,Position = 11,
  711.             ParameterSetName = '',ValueFromPipeline = $False)]
  712.             [string]$UpdateServer,
  713.         [Parameter(
  714.             Mandatory = $False,Position = 12,
  715.             ParameterSetName = 'account',ValueFromPipeline = $False)]
  716.             [string]$SmtpPassword                                                                                                                                                              
  717.             )  
  718. #Configure Email Notifications
  719. $email = $wsus.GetEmailNotificationConfiguration()
  720. $ErrorActionPreference = 'stop'
  721. Try {
  722.     If ($StatusNotificationTimeOfDay) {
  723.         #Validate Notification Time of Day Parameter
  724.         If (!([regex]::ismatch($StatusNotificationTimeOfDay,"^\d{2}:\d{2}$"))) {
  725.             Write-Error "$($StatusNotificationTimeOfDay) is not a valid time to use!`nMust be 'NN:NN'"
  726.             }
  727.         Else {                
  728.             $email.StatusNotificationTimeOfDay = $StatusNotificationTimeOfDay
  729.             }
  730.         }
  731.     If ($UpdateServer) {$email.UpdateServer = $UpdateServer}
  732.     If ($EmailLanguage) {$email.EmailLanguage = $EmailLanguage}
  733.     If ($SenderDisplayName) {$email.SenderDisplayName = $SenderDisplayName}
  734.     If ($SenderEmailAddress) {
  735.         #Validate Email Address Parameter
  736.         If (!([regex]::ismatch($SenderEmailAddress,"^\w+@\w+\.com|mil|org|net$"))) {
  737.             Write-Error "$($SenderEmailAddress) is not a valid email address!`nMust be 'xxxx@xxxxx.xxx'"
  738.             }
  739.         Else {                    
  740.             $email.SenderEmailAddress = $SenderEmailAddress
  741.             }
  742.         }
  743.     If ($SMTPHostname) {$email.SMTPHostname = $SMTPHostname}
  744.     If ($SMTPPort) {$email.SMTPPort = $SMTPPort}
  745.     If ($SmtpServerRequiresAuthentication) {$email.SmtpServerRequiresAuthentication = $SmtpServerRequiresAuthentication}
  746.     If ($SmtpUserName) {$email.SmtpUserName = $SmtpUserName}
  747.     If ($SmtpPassword) {$mail.SetSmtpUserPassword($SmtpPassword)}
  748.     Switch ($StatusNotificationFrequency) {
  749.         "Daily" {$email.StatusNotificationFrequency = [Microsoft.UpdateServices.Administration.EmailStatusNotificationFrequency]::Daily}
  750.         "Weekly" {$email.StatusNotificationFrequency = [Microsoft.UpdateServices.Administration.EmailStatusNotificationFrequency]::Weekly}
  751.         Default {$Null}
  752.         }
  753.     Switch ($SendStatusNotification) {
  754.         "True" {$email.SendStatusNotification = 1}
  755.         "False" {$email.SendStatusNotification = 0}
  756.         Default {$Null}
  757.         }        
  758.     Switch ($SendSyncNotification) {
  759.         "True" {$email.SendSyncNotification = 1}
  760.         "False" {$email.SendSyncNotification = 0}
  761.         Default {$Null}
  762.         }
  763.     }    
  764. Catch {
  765.     Write-Error "$($error[0])"
  766.     }
  767. #Save Configuration Changes
  768. Try {
  769.     $email.Save()
  770.     Write-Host -fore Green "Email settings changed"
  771.     $email
  772.     }        
  773. Catch {
  774.     Write-Error "$($error[0])"
  775.     }    
  776. }  
  777.  
  778. function Convert-WSUSTargetGroup {
  779. <#  
  780. .SYNOPSIS  
  781.     Converts the WSUS group from ID to Name or Name to ID.
  782. .DESCRIPTION
  783.     Converts the WSUS group from ID to Name or Name to ID.
  784. .PARAMETER Id
  785.     GUID of the group to be converted to friendly name          
  786. .PARAMETER Name
  787.     Name of the group to be converted to a guid    
  788. .NOTES  
  789.     Name: Convert-WSUSTargetGroup
  790.     Author: Boe Prox
  791.     DateCreated: 24SEPT2010
  792.            
  793. .LINK  
  794.     https://boeprox.wordpress.org
  795. .EXAMPLE  
  796. Convert-WSUSTargetGroup -name "Domain Servers"
  797.  
  798. Description
  799. -----------      
  800. This command will convert the group name "Domain Servers" into the GUID format.
  801.  
  802. .EXAMPLE
  803. Convert-WSUSTargetGroup -ID "b73ca6ed-5727-47f3-84de-015e03f6a88a"
  804.  
  805. Description
  806. -----------    
  807. This command will convert the given GUID into a friendly name.
  808.  
  809. #>
  810. [cmdletbinding(
  811.         DefaultParameterSetName = 'name',
  812.         ConfirmImpact = 'low'
  813. )]
  814.     Param(
  815.         [Parameter(
  816.             Mandatory = $False,
  817.             Position = 2,
  818.             ParameterSetName = 'id',
  819.             ValueFromPipeline = $False)]
  820.             [string]$Id,
  821.         [Parameter(
  822.             Mandatory = $False,
  823.             Position = 3,
  824.             ParameterSetName = 'name',
  825.             ValueFromPipeline = $False)]
  826.             [string]$Name                          
  827.             )            
  828. If ($name) {    
  829.     Try {    
  830.         $group = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq $name}
  831.         $group | Select -ExpandProperty ID
  832.         }
  833.     Catch {
  834.         Write-Error "Unable to locate $($name)."
  835.         }        
  836.     }  
  837. If ($id) {    
  838.     Try {    
  839.         $group = $wsus.GetComputerTargetGroups() | ? {$_.ID -eq $id}
  840.         $group | Select -ExpandProperty Name
  841.         }
  842.     Catch {
  843.         Write-Error "Unable to locate $($id)."
  844.         }        
  845.     }          
  846. }  
  847.  
  848. function Get-WSUSClientsInGroup {
  849. <#  
  850. .SYNOPSIS  
  851.     Retrieves a list of clients that are members of a group.
  852. .DESCRIPTION
  853.     Retrieves a list of clients that are members of a group.
  854. .PARAMETER Id
  855.     Retrieves list of clients in group by group guid.          
  856. .PARAMETER Name
  857.     Retrieves list of clients in group by group name.    
  858. .NOTES  
  859.     Name: Get-WSUSClientsInGroup
  860.     Author: Boe Prox
  861.     DateCreated: 24SEPT2010
  862.            
  863. .LINK  
  864.     https://boeprox.wordpress.org
  865. .EXAMPLE  
  866. Get-WSUSClientsInGroup -name "Domain Servers"
  867.  
  868. Description
  869. -----------      
  870. This command will list all clients that are members of the specified group via group name.
  871.  
  872. .EXAMPLE
  873. Get-WSUSClientsInGroup -ID "b73ca6ed-5727-47f3-84de-015e03f6a88a"
  874.  
  875. Description
  876. -----------    
  877. This command will list all clients that are members of the specified group via the group guid.
  878.        
  879. #>
  880. [cmdletbinding(
  881.         DefaultParameterSetName = 'name',
  882.         ConfirmImpact = 'low'
  883. )]
  884.     Param(
  885.         [Parameter(
  886.             Mandatory = $False,
  887.             Position = 2,
  888.             ParameterSetName = 'name',            
  889.             ValueFromPipeline = $False)]
  890.             [string]$Name,
  891.         [Parameter(
  892.             Mandatory = $False,
  893.             Position = 3,
  894.             ParameterSetName = 'id',
  895.             ValueFromPipeline = $False)]
  896.             [string]$Id                          
  897.             )                        
  898. If ($id) {    
  899.     ($wsus.GetComputerTargetGroups() | ? {$_.Id -eq $id}).GetComputerTargets()
  900.     }
  901. If ($name) {
  902.     ($wsus.GetComputerTargetGroups() | ? {$_.name -eq $name}).GetComputerTargets()
  903.     }    
  904. }  
  905.  
  906. function Get-WSUSClient {
  907. <#  
  908. .SYNOPSIS  
  909.     Retrieves information about a WSUS client.
  910. .DESCRIPTION
  911.     Retrieves information about a WSUS client.
  912. .PARAMETER Computer
  913.     Name of the client to search for. Accepts a partial name.
  914. .NOTES  
  915.     Name: Get-WSUSClient
  916.     Author: Boe Prox
  917.     DateCreated: 24SEPT2010
  918.            
  919. .LINK  
  920.     https://boeprox.wordpress.org
  921. .EXAMPLE  
  922. Get-WSUSClient -computer "server1"
  923.  
  924. Description
  925. -----------      
  926. This command will search for and display all computers matching the given input.
  927.        
  928. #>
  929. [cmdletbinding(
  930.         DefaultParameterSetName = 'wsus',
  931.         ConfirmImpact = 'low'
  932. )]
  933.     Param(
  934.         [Parameter(
  935.             Mandatory = $True,
  936.             Position = 0,
  937.             ParameterSetName = 'wsus',
  938.             ValueFromPipeline = $True)]
  939.             [string]$Computer                                  
  940.             )                
  941. $ErrorActionPreference = 'stop'    
  942. #Retrieve computer in WSUS
  943. Try {      
  944.     $wsus.SearchComputerTargets($computer)
  945.     }
  946. Catch {
  947.     Write-Error "Unable to retrieve $($computer) from database."
  948.     }    
  949. }
  950.  
  951. function New-WSUSGroup {
  952. <#  
  953. .SYNOPSIS  
  954.     Creates a new WSUS Target group.
  955. .DESCRIPTION
  956.     Creates a new WSUS Target group.
  957. .PARAMETER Group
  958.     Name of group being created.
  959. .PARAMETER ParentGroupName
  960.     Name of group being created.
  961. .PARAMETER ParentGroupId
  962.     Name of group being created.        
  963. .NOTES  
  964.     Name: New-WSUSGroup
  965.     Author: Boe Prox
  966.     DateCreated: 24SEPT2010
  967.            
  968. .LINK  
  969.     https://boeprox.wordpress.org
  970. .EXAMPLE
  971. New-WSUSGroup -name "TestGroup"
  972.  
  973. Description
  974. -----------  
  975. This command will create a new Target group called 'TestGroup'      
  976. .EXAMPLE
  977. New-WSUSGroup -name "TestGroup" -parentgroupname "Domain Servers"
  978.  
  979. Description
  980. -----------  
  981. This command will create a new Target group called 'TestGroup' under the parent group 'Domain Servers'    
  982. #>
  983. [cmdletbinding(
  984.         DefaultParameterSetName = 'group',
  985.         ConfirmImpact = 'low',
  986.     SupportsShouldProcess = $True
  987. )]
  988.     Param(
  989.         [Parameter(
  990.             Mandatory = $True,
  991.             Position = 0,
  992.             ParameterSetName = '',
  993.             ValueFromPipeline = $True)]
  994.             [string]$Group,
  995.         [Parameter(
  996.             Mandatory = $False,
  997.             Position = 1,
  998.             ParameterSetName = 'parentgroup',
  999.             ValueFromPipeline = $True)]
  1000.             [string]$ParentGroupName,
  1001.         [Parameter(
  1002.             Mandatory = $False,
  1003.             Position = 2,
  1004.             ParameterSetName = 'parentgroup',
  1005.             ValueFromPipeline = $True)]
  1006.             [string]$ParentGroupId                                              
  1007.             )
  1008. Process {
  1009.     #Determine action based on Parameter Set Name
  1010.     Switch ($pscmdlet.ParameterSetName) {            
  1011.         "group" {
  1012.             Write-Verbose "Creating computer group"        
  1013.             If ($pscmdlet.ShouldProcess($group)) {
  1014.                 #Create the computer target group
  1015.                 $wsus.CreateComputerTargetGroup($group)
  1016.                 "$($group) has been created."
  1017.                 }
  1018.             }                
  1019.         "parentgroup" {
  1020.             If ($parentgroupname) {
  1021.                 #Retrieve group based off of name
  1022.                 Write-Verbose "Querying for parent group"
  1023.                 $parentgroup = Get-WSUSGroups | ? {$_.name -eq $parentgroupname}
  1024.                 If (!$parentgroup) {
  1025.                     Write-Error "Parent Group name `'$parentgroupname`' does not exist in WSUS!"
  1026.                     Break
  1027.                     }
  1028.                 }
  1029.             If ($parentgroupid) {
  1030.                 #Retrieve group based off of guid
  1031.                 Write-Verbose "Querying for parent group"
  1032.                 $parentgroup = Get-WSUSGroups | ? {$_.id -eq $parentgroupid}
  1033.                 If (!$parentgroup) {
  1034.                     Write-Error "Parent Group id `'$parentgroupid`' does not exist in WSUS!"
  1035.                     Break
  1036.                     }                
  1037.                 }                    
  1038.             Write-Verbose "Creating computer group"                
  1039.             If ($pscmdlet.ShouldProcess($group)) {
  1040.                 #Create the computer target group
  1041.                 $wsus.CreateComputerTargetGroup($group,$parentgroup)
  1042.                 "$($group) has been created under $($parentgroup.Name)."
  1043.                 }            
  1044.             }                
  1045.         }
  1046.     }                
  1047. }            
  1048.  
  1049. function Get-WSUSUpdate {
  1050. <#  
  1051. .SYNOPSIS  
  1052.     Retrieves information from a wsus update.
  1053. .DESCRIPTION
  1054.     Retrieves information from a wsus update. Depending on how the information is presented in the search, more
  1055.     than one update may be returned.
  1056. .PARAMETER Update
  1057.     String to search for. This can be any string for the update to include
  1058.     KB article numbers, name of update, category, etc... Use of wildcards (*,%) not allowed in search!
  1059. .NOTES  
  1060.     Name: Get-WSUSUpdate
  1061.     Author: Boe Prox
  1062.     DateCreated: 24SEPT2010
  1063.            
  1064. .LINK  
  1065.     https://boeprox.wordpress.org
  1066. .EXAMPLE
  1067. Get-WSUSUpdate -update "Exchange"
  1068.  
  1069. Description
  1070. -----------  
  1071. This command will list every update that has 'Exchange' in it.
  1072. .EXAMPLE
  1073. Get-WSUSUpdate -update "925474"
  1074.  
  1075. Description
  1076. -----------  
  1077. This command will list every update that has '925474' in it.
  1078. #>
  1079. [cmdletbinding(
  1080.         DefaultParameterSetName = 'wsus',
  1081.         ConfirmImpact = 'low'
  1082. )]
  1083.     Param(
  1084.         [Parameter(
  1085.             Mandatory = $True,
  1086.             Position = 0,
  1087.             ParameterSetName = 'wsus',
  1088.             ValueFromPipeline = $True)]
  1089.             [string]$Update                                  
  1090.             )                
  1091. $ErrorActionPreference = 'stop'    
  1092. #Retrieve computer in WSUS
  1093. Try {      
  1094.     $wsus.SearchUpdates($update)
  1095.     }
  1096. Catch {
  1097.     Write-Error "Unable to retrieve $($update) from database."
  1098.     }    
  1099. }
  1100.  
  1101. function Remove-WSUSGroup {
  1102. <#  
  1103. .SYNOPSIS  
  1104.     Creates a new WSUS Target group.
  1105. .DESCRIPTION
  1106.     Creates a new WSUS Target group.
  1107. .PARAMETER Name
  1108.     Name of group being deleted.
  1109. .PARAMETER Id
  1110.     Id of group being deleted.      
  1111. .NOTES  
  1112.     Name: Remove-WSUSGroup
  1113.     Author: Boe Prox
  1114.     DateCreated: 24SEPT2010
  1115.            
  1116. .LINK  
  1117.     https://boeprox.wordpress.org
  1118. .EXAMPLE
  1119. Remove-WSUSGroup  -name "Domain Servers"
  1120.  
  1121. Description
  1122. -----------  
  1123. This command will remove the Domain Servers WSUS Target group.  
  1124. .EXAMPLE
  1125. Remove-WSUSGroup  -id "fc93e74e-ba59-4593-9ff7-690af1be695f"
  1126.  
  1127. Description
  1128. -----------  
  1129. This command will remove the Target group with ID 'fc93e74e-ba59-4593-9ff7-690af1be695f' from WSUS.      
  1130. #>
  1131. [cmdletbinding(
  1132.         DefaultParameterSetName = 'name',
  1133.         ConfirmImpact = 'low',
  1134.     SupportsShouldProcess = $True
  1135. )]
  1136.     Param(
  1137.         [Parameter(
  1138.             Mandatory = $False,
  1139.             Position = 0,
  1140.             ParameterSetName = 'name',
  1141.             ValueFromPipeline = $True)]
  1142.             [string]$Name,
  1143.         [Parameter(
  1144.             Mandatory = $False,
  1145.             Position = 1,
  1146.             ParameterSetName = 'id',
  1147.             ValueFromPipeline = $True)]
  1148.             [string]$Id
  1149.         )            
  1150. Process {
  1151.     #Determine action based on Parameter Set Name
  1152.     Switch ($pscmdlet.ParameterSetName) {            
  1153.         "name" {
  1154.             Write-Verbose "Querying for computer group"
  1155.             $group = Get-WSUSGroup -name $name
  1156.             If (!$group) {
  1157.                 Write-Error "Group $name does not exist in WSUS!"
  1158.                 Break
  1159.                 }
  1160.             Else {                              
  1161.                 If ($pscmdlet.ShouldProcess($name)) {
  1162.                     #Create the computer target group
  1163.                     $group.Delete()
  1164.                     "$($name) has been deleted from WSUS."
  1165.                     }
  1166.                 }                    
  1167.             }                
  1168.         "id" {
  1169.             Write-Verbose "Querying for computer group"
  1170.             $group = Get-WSUSGroup -id $id
  1171.             If (!$group) {
  1172.                 Write-Error "Group $id does not exist in WSUS!"
  1173.                 Break
  1174.                 }                                      
  1175.             If ($pscmdlet.ShouldProcess($id)) {
  1176.                 #Create the computer target group
  1177.                 $group.Delete()
  1178.                 "$($id) has been deleted from WSUS."
  1179.                 }            
  1180.             }                
  1181.         }
  1182.     }                
  1183. }
  1184.  
  1185. function Add-WSUSClientToGroup {
  1186. <#  
  1187. .SYNOPSIS  
  1188.     Adds a computer client to an existing WSUS group.
  1189. .DESCRIPTION
  1190.     Adds a computer client to an existing WSUS group.
  1191. .PARAMETER Group
  1192.     Name of group to add client to.
  1193. .PARAMETER Computer
  1194.     Name of computer being added to group.        
  1195. .NOTES  
  1196.     Name: Add-WSUSClientToGroup
  1197.     Author: Boe Prox
  1198.     DateCreated: 24SEPT2010
  1199.            
  1200. .LINK  
  1201.     https://boeprox.wordpress.org
  1202. .EXAMPLE
  1203. Add-WSUSClientToGroup -group "Domain Servers" -computer "server1"
  1204.  
  1205. Description
  1206. -----------  
  1207. This command will add the client "server1" to the WSUS target group "Domain Servers".      
  1208. #>
  1209. [cmdletbinding(
  1210.         DefaultParameterSetName = 'group',
  1211.         ConfirmImpact = 'low',
  1212.     SupportsShouldProcess = $True
  1213. )]
  1214.     Param(
  1215.         [Parameter(
  1216.             Mandatory = $True,
  1217.             Position = 0,
  1218.             ParameterSetName = 'group',
  1219.             ValueFromPipeline = $True)]
  1220.             [string]$Group,
  1221.         [Parameter(
  1222.             Mandatory = $False,
  1223.             Position = 1,
  1224.             ParameterSetName = 'group',
  1225.             ValueFromPipeline = $True)]
  1226.             [string]$Computer                                            
  1227.             )
  1228. #Verify Computer is in WSUS
  1229. Write-Verbose "Validating client in WSUS"
  1230. $client = Get-WSUSClient -computer $computer
  1231. If ($client) {
  1232.     #Get group object
  1233.     Write-Verbose "Retrieving group"
  1234.     $targetgroup = Get-WSUSGroup -name $group
  1235.     If (!$targetgroup) {
  1236.         Write-Error "Group $group does not exist in WSUS!"
  1237.         Break
  1238.         }    
  1239.     #Add client to group
  1240.     Write-Verbose "Adding client to group"
  1241.     If ($pscmdlet.ShouldProcess($($client.fulldomainname))) {
  1242.         $targetgroup.AddComputerTarget($client)
  1243.         "$($client.FullDomainName) has been added to $($group)"
  1244.         }
  1245.     }
  1246. Else {
  1247.     Write-Error "Computer: $computer is not in WSUS!"
  1248.     }    
  1249. }          
  1250.  
  1251. function Remove-WSUSClientFromGroup {
  1252. <#  
  1253. .SYNOPSIS  
  1254.     Removes a computer client to an existing WSUS group.
  1255. .DESCRIPTION
  1256.     Removes a computer client to an existing WSUS group.
  1257. .PARAMETER Group
  1258.     Name of group to remove client from.
  1259. .PARAMETER Computer
  1260.     Name of computer being removed from group.        
  1261. .NOTES  
  1262.     Name: Remove-WSUSClientToGroup
  1263.     Author: Boe Prox
  1264.     DateCreated: 24SEPT2010
  1265.            
  1266. .LINK  
  1267.     https://boeprox.wordpress.org
  1268. .EXAMPLE
  1269. Remove-WSUSClientFromGroup -group "Domain Servers" -computer "server1"
  1270.  
  1271. Description
  1272. -----------  
  1273. This command will remove the client "server1" from the WSUS target group "Domain Servers".      
  1274. #>
  1275. [cmdletbinding(
  1276.         DefaultParameterSetName = 'group',
  1277.         ConfirmImpact = 'low',
  1278.     SupportsShouldProcess = $True
  1279. )]
  1280.     Param(
  1281.         [Parameter(
  1282.             Mandatory = $True,
  1283.             Position = 0,
  1284.             ParameterSetName = 'group',
  1285.             ValueFromPipeline = $True)]
  1286.             [string]$Group,
  1287.         [Parameter(
  1288.             Mandatory = $False,
  1289.             Position = 1,
  1290.             ParameterSetName = 'group',
  1291.             ValueFromPipeline = $True)]
  1292.             [string]$Computer                                            
  1293.             )
  1294. #Verify Computer is in WSUS
  1295. $client = Get-WSUSClient -computer $computer
  1296. If ($client) {
  1297.     #Get group object
  1298.     Write-Verbose "Retrieving group"
  1299.     $targetgroup = Get-WSUSGroup -name $group
  1300.     If (!$targetgroup) {
  1301.         Write-Error "Group $group does not exist in WSUS!"
  1302.         Break
  1303.         }
  1304.     #Remove client from group
  1305.     Write-Verbose "Removing client to group"
  1306.     If ($pscmdlet.ShouldProcess($($client.fulldomainname))) {
  1307.         $targetgroup.RemoveComputerTarget($client)
  1308.         "$($client.fulldomainname) has been removed from $($group)"
  1309.         }
  1310.     }
  1311. Else {
  1312.     Write-Error "Computer: $computer is not in WSUS!"
  1313.     }    
  1314. }            
  1315.  
  1316. function Get-WSUSDatabaseConfig {
  1317. <#  
  1318. .SYNOPSIS  
  1319.     Displays the current WSUS database configuration.
  1320. .DESCRIPTION
  1321.     Displays the current WSUS database configuration.
  1322. .NOTES  
  1323.     Name: Get-WSUSDatabaseConfig
  1324.     Author: Boe Prox
  1325.     DateCreated: 24SEPT2010
  1326.            
  1327. .LINK  
  1328.     https://boeprox.wordpress.org
  1329. .EXAMPLE
  1330. Get-WSUSDatabaseConfig
  1331.  
  1332. Description
  1333. -----------  
  1334. This command will display the configuration information for the WSUS connection to a database.      
  1335. #>
  1336. [cmdletbinding()]  
  1337. Param ()
  1338.  
  1339. $wsus.GetDatabaseConfiguration()      
  1340. }
  1341.  
  1342. function Get-WSUSSubscription {
  1343. <#  
  1344. .SYNOPSIS  
  1345.     Displays WSUS subscription information.
  1346. .DESCRIPTION
  1347.     Displays WSUS subscription information. You can view the next synchronization time, who last modified the schedule, etc...
  1348. .NOTES  
  1349.     Name: Get-WSUSSubscription
  1350.     Author: Boe Prox
  1351.     DateCreated: 24SEPT2010
  1352.            
  1353. .LINK  
  1354.     https://boeprox.wordpress.org
  1355. .EXAMPLE  
  1356. Get-WSUSSubscription      
  1357.  
  1358. Description
  1359. -----------  
  1360. This command will list out the various subscription information on the WSUS server.
  1361. #>
  1362. [cmdletbinding()]  
  1363. Param ()
  1364.  
  1365. $wsus.GetSubscription()    
  1366. }
  1367.  
  1368. function Deny-WSUSUpdate {
  1369. <#  
  1370. .SYNOPSIS  
  1371.     Declines an update on WSUS.
  1372. .DESCRIPTION
  1373.     Declines an update on WSUS. Use of the -whatif is advised to be sure you are declining the right patch or patches.
  1374. .PARAMETER InputObject
  1375.     Collection of update/s being declined. This must be an object, otherwise it will fail.      
  1376. .PARAMETER Update
  1377.     Name of update/s being declined.    
  1378. .NOTES  
  1379.     Name: Deny-WSUSUpdate
  1380.     Author: Boe Prox
  1381.     DateCreated: 24SEPT2010
  1382.            
  1383. .LINK  
  1384.     https://boeprox.wordpress.org
  1385. .EXAMPLE
  1386. Get-WSUSUpdate -update "Exchange 2010" | Deny-WSUSUpdate
  1387.  
  1388. Description
  1389. -----------  
  1390. This command will decline all updates with 'Exchange 2010' in its metadata.
  1391. .EXAMPLE
  1392. Deny-WSUSUpdate  -Update "Exchange 2010"
  1393.  
  1394. Description
  1395. -----------  
  1396. This command will decline all updates with 'Exchange 2010' in its metadata.
  1397. .EXAMPLE
  1398. $updates = Get-WSUSUpdate -update "Exchange 2010"
  1399. Deny-WSUSUpdate -InputObject $updates
  1400.  
  1401. Description
  1402. -----------  
  1403. This command will decline all updates with 'Exchange 2010' in its metadata.  
  1404. .EXAMPLE
  1405. Get-WSUSUpdate -update "Exchange 2010" | Deny-WSUSUpdate
  1406.  
  1407. Description
  1408. -----------  
  1409. This command will decline all updates with 'Exchange 2010' in its metadata via the pipeline.    
  1410. #>
  1411. [cmdletbinding(
  1412.         DefaultParameterSetName = 'collection',
  1413.         ConfirmImpact = 'low',
  1414.     SupportsShouldProcess = $True
  1415. )]
  1416.     Param(
  1417.         [Parameter(
  1418.             Mandatory = $True,
  1419.             Position = 0,
  1420.             ParameterSetName = 'collection',
  1421.             ValueFromPipeline = $True)]
  1422.             [system.object]$InputObject,                                          
  1423.         [Parameter(
  1424.             Mandatory = $False,
  1425.             Position = 1,
  1426.             ParameterSetName = 'string',
  1427.             ValueFromPipeline = $False)]
  1428.             [string]$Update                                          
  1429.             )                      
  1430. Process {
  1431.     Switch ($pscmdlet.ParameterSetName) {
  1432.         "Collection" {
  1433.             Write-Verbose "Using 'Collection' set name"        
  1434.             #Change the collection to patches for use in loop
  1435.             $patches = $inputobject        
  1436.             }
  1437.         "String" {
  1438.             Write-Verbose "Using 'String' set name"        
  1439.             #Gather all updates from given information
  1440.             Write-Verbose "Searching for updates"
  1441.             $patches = Get-WSUSUpdate -update $update        
  1442.             }
  1443.         }
  1444.     ForEach ($patch in $patches) {
  1445.         #Decline the update
  1446.         Write-Verbose "Declining update"                
  1447.         If ($pscmdlet.ShouldProcess($($patch.title))) {
  1448.             $patch.Decline($True) | out-null
  1449.             #Print out report of what was declined
  1450.             New-Object PSObject -Property @{
  1451.                 Patch = $patch.title
  1452.                 ApprovalAction = "Declined"
  1453.                 }
  1454.             }        
  1455.         }
  1456.     }    
  1457. }            
  1458.  
  1459. function Approve-WSUSUpdate {
  1460. <#  
  1461. .SYNOPSIS  
  1462.     Approves a WSUS update for a specific group with an optional deadline.
  1463. .DESCRIPTION
  1464.     Approves a WSUS update for a specific group with an optional deadline.
  1465. .PARAMETER InputObject
  1466.     Update object that is being approved.    
  1467. .PARAMETER Update
  1468.     Name of update being approved.
  1469. .PARAMETER Group
  1470.     Name of group which will receive the update.      
  1471. .PARAMETER Deadline
  1472.     Optional deadline for client to install patch.
  1473. .PARAMETER Action
  1474.     Type of approval action to take on update. Accepted values are Install, Approve, Uninstall and NotApproved      
  1475. .NOTES  
  1476.     Name: Approve-WSUSUpdate
  1477.     Author: Boe Prox
  1478.     DateCreated: 24SEPT2010
  1479.            
  1480. .LINK  
  1481.     https://boeprox.wordpress.org
  1482. .EXAMPLE  
  1483. Approve-WSUSUpdate -update "KB979906" -Group "Domain Servers" -Action Install
  1484.  
  1485. Description
  1486. -----------
  1487. This command will approve all updates with the KnowledgeBase number of KB979906 for the 'Domain Servers' group and
  1488. the action command of 'Install'.
  1489. .EXAMPLE  
  1490. Approve-WSUSUpdate -update "KB979906" -Group "Domain Servers" -Action Install -Deadline (get-Date).AddDays(3)
  1491.  
  1492. Description
  1493. -----------
  1494. This command will approve all updates with the KnowledgeBase number of KB979906 for the 'Domain Servers' group and
  1495. the action command of 'Install' and sets a deadline for 3 days from when this command is run.
  1496. .EXAMPLE  
  1497. Get-WSUSUpdate -Update "KB979906" | Approve-WSUSUpdate -Group "Domain Servers" -Action Install
  1498.  
  1499. Description
  1500. -----------
  1501. This command will take the collection of objects from the Get-WSUSUpdate command and then approve all updates for
  1502. the 'Domain Servers' group and the action command of 'Install'.
  1503.        
  1504. #>
  1505. [cmdletbinding(
  1506.         DefaultParameterSetName = 'string',
  1507.         ConfirmImpact = 'low',
  1508.     SupportsShouldProcess = $True
  1509. )]
  1510.     Param(
  1511.         [Parameter(            
  1512.             Mandatory = $True,
  1513.             Position = 0,
  1514.             ParameterSetName = 'collection',
  1515.             ValueFromPipeline = $True)]
  1516.             [system.object]
  1517.             [ValidateNotNullOrEmpty()]
  1518.             $InputObject,    
  1519.         [Parameter(
  1520.             Mandatory = $True,
  1521.             Position = 0,
  1522.             ParameterSetName = 'string',
  1523.             ValueFromPipeline = $False)]
  1524.             [string]$Update,          
  1525.         [Parameter(
  1526.             Mandatory = $True,
  1527.             Position = 1,
  1528.             ParameterSetName = '',
  1529.             ValueFromPipeline = $False)]
  1530.             [string]
  1531.             [ValidateSet("Install", "All", "NotApproved","Uninstall")]
  1532.             $Action,              
  1533.         [Parameter(
  1534.             Mandatory = $True,
  1535.             Position = 2,
  1536.             ParameterSetName = '',
  1537.             ValueFromPipeline = $False)]
  1538.             [string]$Group,
  1539.         [Parameter(
  1540.             Mandatory = $False,
  1541.             Position = 3,
  1542.             ParameterSetName = '',
  1543.             ValueFromPipeline = $False)]
  1544.             [datetime]$Deadline                      
  1545.         )
  1546. Begin {
  1547.     #Define the actions available
  1548.     Write-Verbose "Defining available approval actions"
  1549.     $Install = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install
  1550.     $All = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::All
  1551.     $NotApproved = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::NotApproved
  1552.     $Uninstall = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Uninstall
  1553.    
  1554.     #Search for group specified
  1555.     Write-Verbose "Searching for group"        
  1556.     $targetgroup = Get-WSUSGroup -name $group
  1557.     If (!$targetgroup) {
  1558.         Write-Error "Group $group does not exist in WSUS!"
  1559.         Break
  1560.         }      
  1561.     }                    
  1562. Process {
  1563.     #Perform appropriate action based on Parameter set name
  1564.     Switch ($pscmdlet.ParameterSetName) {            
  1565.         "collection" {
  1566.             Write-Verbose "Using 'Collection' set name"
  1567.             #Change the variable that will hold the objects
  1568.             $patches = $inputobject    
  1569.             }                
  1570.         "string" {
  1571.             Write-Verbose "Using 'String' set name"
  1572.             #Search for updates
  1573.             Write-Verbose "Searching for update/s"
  1574.             $patches = Get-WSUSUpdate -update $update
  1575.             If (!$patches) {
  1576.                 Write-Error "Update $update could not be found in WSUS!"
  1577.                 Break
  1578.                 }                    
  1579.             }                
  1580.         }
  1581.     ForEach ($patch in $patches) {
  1582.         #Determine if Deadline is required
  1583.         If ($deadline) {
  1584.             Write-Verbose "Approving update with a deadline."
  1585.             If ($pscmdlet.ShouldProcess($($patch.title))) {
  1586.                 #Create the computer target group
  1587.                 $patch.Approve($action,$targetgroup,$deadline) | out-null
  1588.                 #Print out report of what was approved
  1589.                 New-Object PSObject -Property @{
  1590.                     Patch = $patch.title
  1591.                     TargetGroup = $group
  1592.                     ApprovalAction = $action
  1593.                     Deadline = "$($deadline)"
  1594.                     }
  1595.                 }        
  1596.             }
  1597.         Else {    
  1598.             #Approve the patch
  1599.             Write-Verbose "Approving update without a deadline."                              
  1600.             If ($pscmdlet.ShouldProcess($($patch.title))) {
  1601.                 #Create the computer target group
  1602.                 $patch.Approve($action,$targetgroup) | out-null
  1603.                 #Print out report of what was approved
  1604.                 New-Object PSObject -Property @{
  1605.                     Patch = $patch.title
  1606.                     TargetGroup = $group
  1607.                     ApprovalAction = $action
  1608.                     }              
  1609.                 }
  1610.             }                
  1611.         }
  1612.     }                
  1613. }
  1614.  
  1615. function Get-WSUSGroup {
  1616. <#  
  1617. .SYNOPSIS  
  1618.     Retrieves specific WSUS target group.
  1619. .DESCRIPTION
  1620.     Retrieves specific WSUS target group.
  1621. .PARAMETER Name
  1622.     Name of group to search for. No wildcards allowed.
  1623. .PARAMETER Id
  1624.     GUID of group to search for. No wildcards allowed.      
  1625. .NOTES  
  1626.     Name: Get-WSUSGroups
  1627.     Author: Boe Prox
  1628.     DateCreated: 24SEPT2010
  1629.            
  1630. .LINK  
  1631.     https://boeprox.wordpress.org
  1632. .EXAMPLE  
  1633. Get-WSUSGroup -name "Domain Servers"
  1634.  
  1635. Description
  1636. -----------
  1637. This command will search for the group and display the information for Domain Servers"
  1638.  
  1639. .EXAMPLE  
  1640. Get-WSUSGroup -ID "0b5ba818-021e-4238-8098-7245b0f90557"
  1641.  
  1642. Description
  1643. -----------
  1644. This command will search for the group and display the information for the WSUS
  1645. group guid 0b5ba818-021e-4238-8098-7245b0f90557"
  1646.        
  1647. #>
  1648. [cmdletbinding(
  1649.         DefaultParameterSetName = 'name',
  1650.         ConfirmImpact = 'low',
  1651.     SupportsShouldProcess = $True
  1652.     )]
  1653.     Param(
  1654.         [Parameter(
  1655.             Mandatory = $True,
  1656.             Position = 0,
  1657.             ParameterSetName = 'name',
  1658.             ValueFromPipeline = $False)]
  1659.             [string]$Name,
  1660.         [Parameter(
  1661.             Mandatory = $True,
  1662.             Position = 0,
  1663.             ParameterSetName = 'id',
  1664.             ValueFromPipeline = $False)]
  1665.             [string]$Id            
  1666.         )            
  1667. Switch ($pscmdlet.ParameterSetName) {
  1668.     "name" {$wsus.GetComputerTargetGroups() | ? {$_.name -eq $name}}
  1669.     "id"   {$wsus.GetComputerTargetGroups() | ? {$_.id -eq $id}}
  1670.     }
  1671. }  
  1672.  
  1673. function Remove-WSUSUpdate {
  1674. <#  
  1675. .SYNOPSIS  
  1676.     Removes an update on WSUS.
  1677. .DESCRIPTION
  1678.     Removes an update on WSUS. Use of the -whatif is advised to be sure you are declining the right patch or patches.
  1679. .PARAMETER Update
  1680.     Name of update being removed.      
  1681. .NOTES  
  1682.     Name: Remove-WSUSUpdate
  1683.     Author: Boe Prox
  1684.     DateCreated: 24SEPT2010
  1685.            
  1686. .LINK  
  1687.     https://boeprox.wordpress.org
  1688. .EXAMPLE  
  1689. Remove-WSUSUpdate -update "KB986569"
  1690.  
  1691. Description
  1692. -----------
  1693. This command will remove all instances of KB986569 from WSUS.
  1694.        
  1695. #>
  1696. [cmdletbinding(
  1697.         DefaultParameterSetName = 'update',
  1698.         ConfirmImpact = 'low',
  1699.     SupportsShouldProcess = $True
  1700. )]
  1701.     Param(
  1702.         [Parameter(
  1703.             Mandatory = $True,
  1704.             Position = 0,
  1705.             ParameterSetName = 'update',
  1706.             ValueFromPipeline = $True)]
  1707.             [string]$Update                                          
  1708.             )
  1709. Begin {
  1710.     #Gather all updates from given information
  1711.     Write-Verbose "Searching for updates"
  1712.     $patches = Get-WSUSUpdate -update $update
  1713.     }            
  1714. Process {
  1715.     ForEach ($patch in $patches) {
  1716.         #Storing update guid
  1717.         $guid = ($patch.id).updateid              
  1718.         If ($pscmdlet.ShouldProcess($($patch.title))) {
  1719.             $wsus.DeleteUpdate($id,$True)
  1720.             "$($patch.title) has been deleted from WSUS"
  1721.             }        
  1722.         }
  1723.     }    
  1724. }  
  1725.  
  1726. function Stop-WSUSDownloads {
  1727. <#  
  1728. .SYNOPSIS  
  1729.     Cancels all current WSUS downloads.
  1730. .DESCRIPTION
  1731.     Cancels all current WSUS downloads.      
  1732. .NOTES  
  1733.     Name: Stop-WSUSDownloads
  1734.     Author: Boe Prox
  1735.     DateCreated: 24SEPT2010
  1736.            
  1737. .LINK  
  1738.     https://boeprox.wordpress.org
  1739. .EXAMPLE
  1740. Stop-WSUSDownloads
  1741.  
  1742. Description
  1743. -----------  
  1744. This command will stop all updates being downloaded to the WSUS server.
  1745.        
  1746. #>
  1747. [cmdletbinding(
  1748.         DefaultParameterSetName = 'update',
  1749.         ConfirmImpact = 'low',
  1750.     SupportsShouldProcess = $True
  1751. )]
  1752.     Param()
  1753. #Cancel all downloads running on WSUS      
  1754. If ($pscmdlet.ShouldProcess($($wsus.name))) {
  1755.     $wsus.CancelAllDownloads()
  1756.     "Downloads have been cancelled."
  1757.     }
  1758. }    
  1759.  
  1760. function Resume-WSUSDownloads {
  1761. <#  
  1762. .SYNOPSIS  
  1763.     Resumes all current WSUS downloads.
  1764. .DESCRIPTION
  1765.     Resumes all current WSUS downloads that had been cancelled.
  1766. .NOTES  
  1767.     Name: Resume-WSUSDownloads
  1768.     Author: Boe Prox
  1769.     DateCreated: 24SEPT2010
  1770.            
  1771. .LINK  
  1772.     https://boeprox.wordpress.org
  1773. .EXAMPLE
  1774. Resume-WSUSDownloads
  1775.  
  1776. Description
  1777. -----------
  1778. This command will resume the downloading of updates to the WSUS server.
  1779.        
  1780. #>
  1781. [cmdletbinding(
  1782.         DefaultParameterSetName = 'update',
  1783.         ConfirmImpact = 'low',
  1784.     SupportsShouldProcess = $True
  1785. )]
  1786.     Param()
  1787. #Cancel all downloads running on WSUS      
  1788. If ($pscmdlet.ShouldProcess($($wsus.name))) {
  1789.     $wsus.ResumeAllDownloads()
  1790.     "Downloads have been resumed."
  1791.     }
  1792. }
  1793.  
  1794. function Stop-WSUSUpdateDownload {
  1795. <#  
  1796. .SYNOPSIS  
  1797.     Stops update download after approval.
  1798. .DESCRIPTION
  1799.     Stops update download after approval.
  1800. .PARAMETER update
  1801.     Name of update to cancel download.      
  1802. .NOTES  
  1803.     Name: Stop-WSUSUpdateDownload
  1804.     Author: Boe Prox
  1805.     DateCreated: 24SEPT2010
  1806.            
  1807. .LINK  
  1808.     https://boeprox.wordpress.org
  1809. .EXAMPLE  
  1810. Stop-WSUSUpdateDownload -update "KB965896"
  1811.  
  1812. Description
  1813. -----------
  1814. This command will cancel the download of update KB956896.      
  1815. #>
  1816. [cmdletbinding(
  1817.         DefaultParameterSetName = 'update',
  1818.         ConfirmImpact = 'low',
  1819.     SupportsShouldProcess = $True
  1820. )]
  1821.     Param(
  1822.         [Parameter(
  1823.             Mandatory = $True,
  1824.             Position = 0,
  1825.             ParameterSetName = 'update',
  1826.             ValueFromPipeline = $True)]
  1827.             [string]$update                                          
  1828.             )
  1829. Begin {
  1830.     #Gather all updates from given information
  1831.     Write-Verbose "Searching for updates"
  1832.     $patches = Get-WSUSUpdate -update $update
  1833.     }            
  1834. Process {
  1835.     If ($patches) {
  1836.         ForEach ($patch in $patches) {
  1837.             Write-Verbose "Cancelling update download"                
  1838.             If ($pscmdlet.ShouldProcess($($patch.title))) {
  1839.                 $patch.CancelDownload()
  1840.                 "$($patch.title) download has been cancelled."
  1841.                 }        
  1842.             }
  1843.         }
  1844.     Else {
  1845.         Write-Warning "No patches found that need downloading cancelled."
  1846.         }        
  1847.     }    
  1848. }
  1849.  
  1850. function Resume-WSUSUpdateDownload {
  1851. <#  
  1852. .SYNOPSIS  
  1853.     Resumes previously cancelled update download after approval.
  1854. .DESCRIPTION
  1855.     Resumes previously cancelled update download after approval.
  1856. .PARAMETER Update
  1857.     Name of cancelled update download to resume download.      
  1858. .NOTES  
  1859.     Name: Resume-WSUSUpdateDownload
  1860.     Author: Boe Prox
  1861.     DateCreated: 24SEPT2010
  1862.            
  1863. .LINK  
  1864.     https://boeprox.wordpress.org
  1865. .EXAMPLE  
  1866. Resume-WSUSUpdateDownload -update "KB965896"
  1867.  
  1868. Description
  1869. -----------
  1870. This command will resume the download of update KB956896 that was previously cancelled.      
  1871. #>
  1872. [cmdletbinding(
  1873.         DefaultParameterSetName = 'update',
  1874.         ConfirmImpact = 'low',
  1875.     SupportsShouldProcess = $True
  1876. )]
  1877.     Param(
  1878.         [Parameter(
  1879.             Mandatory = $True,
  1880.             Position = 0,
  1881.             ParameterSetName = 'update',
  1882.             ValueFromPipeline = $True)]
  1883.             [string]$Update                                          
  1884.             )
  1885. Begin {
  1886.     #Gather all updates from given information
  1887.     Write-Verbose "Searching for updates"
  1888.     $patches = Get-WSUSUpdate -update $update
  1889.     }                
  1890. Process {
  1891.     If ($patches) {
  1892.         ForEach ($patch in $patches) {
  1893.             Write-Verbose "Resuming update download"                
  1894.             If ($pscmdlet.ShouldProcess($($patch.title))) {
  1895.                 $patch.ResumeDownload()
  1896.                 "$($patch.title) download has been resumed."
  1897.                 }        
  1898.             }
  1899.         }
  1900.     Else {
  1901.         Write-Warning "No patches found needing to resume download!"
  1902.         }        
  1903.     }    
  1904. }
  1905.  
  1906. function Start-WSUSCleanup {
  1907. <#  
  1908. .SYNOPSIS  
  1909.     Performs a cleanup on WSUS based on user inputs.
  1910. .DESCRIPTION
  1911.     Performs a cleanup on WSUS based on user inputs.
  1912. .PARAMETER DeclineSupersededUpdates
  1913.     Declined Superseded Updates will be removed.
  1914. .PARAMETER DeclineExpiredUpdates
  1915.     Expired updates should be declined.
  1916. .PARAMETER CleanupObsoleteUpdates
  1917.     Delete obsolete updates from the database.
  1918. .PARAMETER CompressUpdates
  1919.     Obsolete revisions to updates should be deleted from the database.
  1920. .PARAMETER CleanupObsoleteComputers
  1921.     Delete obsolete computers from the database.
  1922. .PARAMETER CleanupUnneededContentFiles
  1923.     Delete unneeded update files.  
  1924. .NOTES  
  1925.     Name: Start-WSUSCleanup
  1926.     Author: Boe Prox
  1927.     DateCreated: 24SEPT2010            
  1928. .LINK  
  1929.     https://boeprox.wordpress.org
  1930. .EXAMPLE  
  1931. Start-WSUSCleanup -CompressUpdates -CleanupObsoleteComputers
  1932.  
  1933. Description
  1934. -----------
  1935. This command will run the WSUS cleanup wizard and delete obsolete computers from the database and delete obsolete update
  1936. revisions from the database.  
  1937. .EXAMPLE
  1938. Start-WSUSCleanup -CompressUpdates -CleanupObsoleteComputers -DeclineExpiredUpdates -CleanupObsoleteUpdates -CleanupUnneededContentFiles
  1939.  
  1940. Description
  1941. -----------
  1942. This command performs a full WSUS cleanup against the database.      
  1943. #>
  1944. [cmdletbinding(
  1945.         DefaultParameterSetName = 'cleanup',
  1946.         ConfirmImpact = 'low',
  1947.     SupportsShouldProcess = $True
  1948. )]
  1949.     Param(
  1950.         [Parameter(
  1951.             Mandatory = $False,
  1952.             Position = 0,
  1953.             ParameterSetName = 'cleanup',
  1954.             ValueFromPipeline = $False)]
  1955.             [switch]$DeclineSupersededUpdates,  
  1956.         [Parameter(
  1957.             Mandatory = $False,
  1958.             Position = 1,
  1959.             ParameterSetName = 'cleanup',
  1960.             ValueFromPipeline = $False)]
  1961.             [switch]$DeclineExpiredUpdates,  
  1962.         [Parameter(
  1963.             Mandatory = $False,
  1964.             Position = 2,
  1965.             ParameterSetName = 'cleanup',
  1966.             ValueFromPipeline = $False)]
  1967.             [switch]$CleanupObsoleteUpdates,  
  1968.         [Parameter(
  1969.             Mandatory = $False,
  1970.             Position = 3,
  1971.             ParameterSetName = 'cleanup',
  1972.             ValueFromPipeline = $False)]
  1973.             [switch]$CompressUpdates,  
  1974.         [Parameter(
  1975.             Mandatory = $False,
  1976.             Position = 4,
  1977.             ParameterSetName = 'cleanup',
  1978.             ValueFromPipeline = $False)]
  1979.             [switch]$CleanupObsoleteComputers,  
  1980.         [Parameter(
  1981.             Mandatory = $False,
  1982.             Position = 5,
  1983.             ParameterSetName = 'cleanup',
  1984.             ValueFromPipeline = $False)]
  1985.             [switch]$CleanupUnneededContentFiles                                                                                                    
  1986.             )
  1987. Begin {            
  1988.     #Create cleanup scope
  1989.     $cleanScope = new-object Microsoft.UpdateServices.Administration.CleanupScope
  1990.     #Create cleanup manager object
  1991.     $cleanup = $wsus.GetCleanupManager()
  1992.  
  1993.     #Determine what will be in the scope
  1994.     If ($DeclineSupersededUpdates) {
  1995.         $cleanScope.DeclineSupersededUpdates = $True
  1996.         }
  1997.     If ($DeclineExpiredUpdates) {
  1998.         $cleanScope.DeclineExpiredUpdates = $True
  1999.         }
  2000.     If ($CleanupObsoleteUpdates) {
  2001.         $cleanScope.CleanupObsoleteUpdates = $True
  2002.         }        
  2003.     If ($CompressUpdates) {
  2004.         $cleanScope.CompressUpdates = $True
  2005.         }
  2006.     If ($CleanupObsoleteComputers) {
  2007.         $cleanScope.CleanupObsoleteComputers = $True
  2008.         }
  2009.     If ($CleanupUnneededContentFiles) {
  2010.         $cleanScope.CleanupUnneededContentFiles = $True
  2011.         }
  2012.     }
  2013. Process {
  2014.     Write-Host "Beginning cleanup"                
  2015.     If ($pscmdlet.ShouldProcess($($wsus.name))) {
  2016.         $cleanup.PerformCleanup($cleanScope)
  2017.         }    
  2018.     }                        
  2019.  
  2020. }
  2021.  
  2022. function Get-WSUSChildServers {
  2023. <#  
  2024. .SYNOPSIS  
  2025.     Retrieves all WSUS child servers.
  2026. .DESCRIPTION
  2027.     Retrieves all WSUS child servers.
  2028. .NOTES  
  2029.     Name: Get-WSUSChildServers
  2030.     Author: Boe Prox
  2031.     DateCreated: 24SEPT2010
  2032.            
  2033. .LINK  
  2034.     https://boeprox.wordpress.org
  2035. .EXAMPLE  
  2036. Get-WSUSChildServers
  2037.  
  2038. Description
  2039. -----------
  2040. This command will display all of the Child WSUS servers.
  2041.        
  2042. #>
  2043. [cmdletbinding()]  
  2044. Param ()
  2045. #Gather all child servers in WSUS    
  2046. $wsus.GetChildServers()
  2047. }
  2048.  
  2049. function Get-WSUSDownstreamServers {
  2050. <#  
  2051. .SYNOPSIS  
  2052.     Retrieves all WSUS downstream servers.
  2053. .DESCRIPTION
  2054.     Retrieves all WSUS downstream servers.
  2055. .NOTES  
  2056.     Name: Get-WSUSDownstreamServers
  2057.     Author: Boe Prox
  2058.     DateCreated: 24SEPT2010
  2059.            
  2060. .LINK  
  2061.     https://boeprox.wordpress.org
  2062. .EXAMPLE  
  2063. Get-WSUSDownstreamServers
  2064.  
  2065. Description
  2066. -----------
  2067. This command will display a list of all of the downstream WSUS servers.
  2068.        
  2069. #>
  2070. [cmdletbinding()]  
  2071. Param ()
  2072. #Gather all child servers in WSUS    
  2073. $wsus.GetDownstreamServers()
  2074. }
  2075.  
  2076. function Get-WSUSContentDownloadProgress {
  2077. <#  
  2078. .SYNOPSIS  
  2079.     Retrieves the progress of currently downloading updates. Displayed in bytes downloaded.
  2080. .DESCRIPTION
  2081.     Retrieves the progress of currently downloading updates. Displayed in bytes downloaded.
  2082. .PARAMETER Monitor
  2083.     Runs a background job to monitor currently running content download and notifies user when completed.    
  2084. .NOTES  
  2085.     Name: Get-WSUSContentDownloadProgress
  2086.     Author: Boe Prox
  2087.     DateCreated: 24SEPT2010
  2088.            
  2089. .LINK  
  2090.     https://boeprox.wordpress.org
  2091. .EXAMPLE  
  2092. Get-WSUSContentDownloadProgress
  2093.  
  2094. Description
  2095. -----------
  2096. This command will display the current progress of the content download.
  2097. .EXAMPLE  
  2098. Get-WSUSContentDownloadProgress -monitor
  2099.  
  2100. Description
  2101. -----------
  2102. This command will create a background job that will monitor the progress and alert the user via pop-up message that
  2103. the download has been completed.
  2104.        
  2105. #>
  2106. [cmdletbinding()]  
  2107. Param (
  2108.     [Parameter(
  2109.         Mandatory = $False,
  2110.         Position = 0,
  2111.         ParameterSetName = 'monitor',
  2112.         ValueFromPipeline = $False)]
  2113.         [switch]$Monitor
  2114.     )
  2115. If ($monitor) {
  2116.     #Stop and remove same jobs if existing
  2117.         $job = Get-Job
  2118.     If ($job) {
  2119.         $job = Get-Job -Name "WSUSSyncProgressMonitor"
  2120.         }
  2121.     If ($job) {
  2122.         Get-Job -Name "WSUSContentProgressMonitor" | Stop-Job
  2123.         Get-Job -Name "WSUSContentProgressMonitor" | Remove-Job
  2124.         }
  2125.     Start-Job -Name "WSUSContentProgressMonitor" -ArgumentList $wsus -ScriptBlock {
  2126.         Param (
  2127.             $wsus
  2128.             )
  2129.         #Load required assemblies for message window    
  2130.         [void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms)            
  2131.         $progress = $wsus.GetContentDownloadProgress()            
  2132.         While ($progress.TotalBytesToDownload -ne $progress.DownloadedBytes) {
  2133.             $null
  2134.             }
  2135.         [System.Windows.Forms.MessageBox]::Show("Content download has been completed on WSUS",”Information”)            
  2136.         } | Out-Null
  2137.     }
  2138. Else {
  2139.     #Gather all child servers in WSUS    
  2140.     $wsus.GetContentDownloadProgress()
  2141.     }        
  2142. }
  2143.  
  2144. function Remove-WSUSClient {
  2145. <#  
  2146. .SYNOPSIS  
  2147.     Removes client from WSUS.
  2148. .DESCRIPTION
  2149.     Removes client from WSUS.
  2150. .PARAMETER Computer
  2151.     Name of the client to remove from WSUS.
  2152. .PARAMETER InputObject
  2153.     Computer object that is being removed.    
  2154. .NOTES  
  2155.     Name: Remove-WSUSClient
  2156.     Author: Boe Prox
  2157.     DateCreated: 12NOV2010
  2158.            
  2159. .LINK  
  2160.     https://boeprox.wordpress.org
  2161. .EXAMPLE  
  2162. Remove-WSUSClient -computer "server1"
  2163.  
  2164. Description
  2165. -----------      
  2166. This command will remove 'server1' from WSUS.
  2167. .EXAMPLE  
  2168. Get-WSUSClient -computer "server1" | Remove-WSUSClient
  2169.  
  2170. Description
  2171. -----------      
  2172. This command will remove 'server1' from WSUS.
  2173. .EXAMPLE  
  2174. Get-WSUSClient -computer "servers" | % {Remove-WSUSClient -inputobject $_}
  2175.  
  2176. Description
  2177. -----------      
  2178. This command will remove multiple servers from WSUS.
  2179.        
  2180. #>
  2181. [cmdletbinding(
  2182.         DefaultParameterSetName = 'collection',
  2183.         ConfirmImpact = 'low',
  2184.     SupportsShouldProcess = $True    
  2185. )]
  2186.     Param(
  2187.         [Parameter(
  2188.             Mandatory = $True,
  2189.             Position = 0,
  2190.             ParameterSetName = 'string',
  2191.             ValueFromPipeline = $True)]
  2192.             [string]$Computer,
  2193.         [Parameter(

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me