上QQ阅读APP看书,第一时间看更新
How to do it...
The steps for the recipe are as follows:
- Install the Windows Update feature and tools, with -Verbose for additional feedback:
Install-WindowsFeature -Name 'UpdateServices' `
-IncludeManagementTools -Verbose
- Review the features that are installed on your server, noting that not only has Windows Software Update Services been installed, but Web Server (IIS), ASP.Net 4.6, and Windows Internal Database have as well:
Get-WindowsFeature |
Where-Object -FilterScript {($psitem.Installed)}
- Create a folder for WSUS update content:
$WSUSContentDir = 'C:\WSUS'
New-Item -Path $WSUSContentDir -ItemType Directory
- Perform post-installation configuration using WsusUtil.exe:
& "$env:ProgramFiles\Update Services\Tools\WsusUtil.exe" `
postinstall
CONTENT_DIR=$WSUSContentDir
- Once configuration completes, the output includes a line stating Log file is located at, followed by a path to a .tmp file in the user's temp directory. Review this log file to see what was done in the configuration (adjust the file name as necessary):
Get-Content -Path "$env:TEMP\1tmp234.tmp"
- View some websites on this machine, noting the WSUS website:
Get-Website
- View the cmdlets in the UpdateServices module:
Get-Command -Module UpdateServices
- Inspect the TypeName and properties of the object created with Get-WsusServer:
$WSUSServer = Get-WsusServer
$WSUSServer.GetType().Fullname
$WSUSServer | Select-Object -Property *
- The object is of type UpdateServer in the Microsoft.UpdateServices.Internal.BaseApi namespace, and is the main object you interact with to manage WSUS from PowerShell. Inspect the methods of the object:
$WSUSServer | Get-Member -MemberType Method
- Inspect some of the configuration values of the UpdateServer object:
$WSUSServer.GetConfiguration() |
Select-Object -Property SyncFromMicrosoftUpdate,LogFilePath
- Product categories are the various operating systems and programs for which updates are available. See what product categories are included by WSUS after the initial install:
$WSUSProducts = Get-WsusProduct -UpdateServer $WSUSServer
$WSUSProducts.Count
$WSUSProducts
- Your $WSUSServer object contains a subscription object with properties and methods useful for managing the synchronization of updates. Access the Subscription object in the $WSUSServer object and inspect it, noting that it is also in the Microsoft.UpdateServices.Internal.BaseApi namespace:
$WSUSSubscription = $WSUSServer.GetSubscription()
$WSUSSubscription.GetType().Fullname
$WSUSSubscription | Select-Object -Property *
$WSUSSubscription | Get-Member -MemberType Method
- Before you choose which product updates you want, you need to know what product categories are available. Get the latest categories of products available from Microsoft Update servers, and use a while loop to wait for completion:
$WSUSSubscription.StartSynchronizationForCategoryOnly()
Do {
Write-Output $WSUSSubscription.GetSynchronizationProgress()
Start-Sleep -Seconds 5
}
While ($WSUSSubscription.GetSynchronizationStatus() -ne `
'NotProcessing')
- Once synchronization is complete, check the results of the synchronization:
$WSUSSubscription.GetLastSynchronizationInfo()
- Again, review the categories of the products available:
$WSUSProducts = Get-WsusProduct -UpdateServer $WSUSServer
$WSUSProducts.Count
$WSUSProducts