{"id":11461,"date":"2012-01-16T00:01:00","date_gmt":"2012-01-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/01\/16\/introduction-to-wsus-and-powershell\/"},"modified":"2012-01-16T00:01:00","modified_gmt":"2012-01-16T00:01:00","slug":"introduction-to-wsus-and-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/introduction-to-wsus-and-powershell\/","title":{"rendered":"Introduction to WSUS and PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Guest blogger, Boe Prox, shows how to use Windows PowerShell to install WSUS and configure clients for updates.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. You are in for a treat this week. Boe Prox has written a week&rsquo;s worth of goodies, and we will share them here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7558.HSG-1-16-12-1.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7558.HSG-1-16-12-1.jpg\" alt=\"Photo of Boe Prox\" title=\"Photo of Boe Prox\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\">Boe Prox is currently a senior systems administrator with BAE Systems. He has been in the IT industry since 2003, and he has been working with <a href=\"http:\/\/technet.microsoft.com\/en-us\/scriptcenter\/powershell.aspx\" target=\"_blank\">Windows PowerShell<\/a> since 2009. Boe looks to script whatever he can, whenever he can. He is also a moderator on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Hey, Scripting Guy! Forum<\/a>. Check out his current projects published on CodePlex: <a href=\"http:\/\/poshwsus.codeplex.com\/\" target=\"_blank\">PoshWSUS<\/a> and <a href=\"http:\/\/poshpaig.codeplex.com\/\" target=\"_blank\">PoshPAIG<\/a>.<br \/> Boe&rsquo;s blog: <a href=\"http:\/\/learn-powershell.net\/\" target=\"_blank\">Learn PowerShell | Achieve More<\/a><\/p>\n<p>Now, without further ado, here is Boe!<\/p>\n<p>For those of you who are unfamiliar with Windows Software Update Services (WSUS), I am going to start with a brief description of what WSUS is and how it is used to manage patching in an environment. Then I will dive into installing the server by using Windows PowerShell, configuring clients via GPO or the registry to report to the WSUS server and to receive the updates from the server. Lastly, I will discuss how to use Windows PowerShell with the associated assemblies for the WSUS Administrator Console to connect to the WSUS Server.<\/p>\n<h3>What is WSUS?<\/h3>\n<p>Windows Software Update Services (WSUS) is used by system administrators to manage the distribution of updates and hotfixes that are released by Microsoft for an environment. Currently, the most recent version is WSUS&nbsp;3.0 with Service Pack&nbsp;2, and it is available <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=161140\" target=\"_blank\">to download<\/a>. This installation allows you to install the full server installation option or only the console installation (which can be installed on any client or server). It also has the assemblies required to use Windows PowerShell to manage the WSUS server. To determine the version of WSUS, refer to <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc720492(WS.10).aspx\" target=\"_blank\">Appendix G: Detect the Version of WSUS<\/a> on Microsoft TechNet.<\/p>\n<h3>Installing a WSUS Server<\/h3>\n<p>Before you begin the installation of WSUS, make sure you install the following on the selected server:<\/p>\n<ul>\n<li>Internet Information Services (IIS)<\/li>\n<li>At a minimum, .NET Framework&nbsp;2.0<\/li>\n<\/ul>\n<p>You could install WSUS&nbsp;3.0&nbsp;with SP2 on your server by using the file specified in the previous download link and running through the UI installation. But c&rsquo;mon, this is a scripting blog, so surely we can script something out&hellip;right? Right!<\/p>\n<p>Because there are several switches available with the executable file, we can easily script an unattended installation of the WSUS server along with specific configurations that meet our requirements. For more information about those switches, see <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc708476%28WS.10%29.aspx\" target=\"_blank\">Appendix A: Unattended Installations<\/a>. The script I wrote that will allow a local or remote installation of a WSUS server or to install only the WSUS Administration Console is called <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Install-WSUSServerps1-40a8169b\" target=\"_blank\">Install-WSUSServer.ps1<\/a>.<\/p>\n<p>Note: I chose to require a dependency for PSExec.exe to complete the remote installation requirements. There were a number of reasons why I chose to do this, but the main reason is that I wanted to make sure that if an issue occurs that cancels the installation, an error would returned in the script that lets you know something happened.<\/p>\n<p>You can run this script against only one computer at a time. This is because only one SUSDB database can be used for each SQL Server instance (unless you are setting up a WSUS server as a front-end server). You can specify whether to install a console or a server core installation, and it allows for using the internal database installation or a local\/remote SQL Server instance to write data to. Lastly, if the required installation file (WSUS30-KB972455-x86.exe or WSUS30-KB972455-x64.exe) is not in the same directory as the script, you will be given a prompt to download the required file to use for installation. I also wrote an <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Uninstall-WSUSServer-218ce694\" target=\"_blank\">Uninstall-WSUSServer.ps1<\/a> script that performs exactly like the Install-WSUSServer.ps1 script.<\/p>\n<p>So enough talking about this script and let&rsquo;s see it in action. First, let&rsquo;s install our WSUS server and make sure that we save the content locally and save that content on the D drive. I am also going to make sure that I <b>do not<\/b> have the updates made available so it asks me to download the update prior to the installation.<\/p>\n<p style=\"padding-left: 30px\">. .\\Install-WSUSServer.ps1 -Computername DC1 -StoreUpdatesLocally -ContentDirectory &#8220;D:\\WSUS&#8221; -InternalDatabasePath &#8220;D:\\&#8221; &ndash;CreateDatabase &ndash;Verbose<\/p>\n<p>The command and the associated output are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6318.hsg-1-16-12-2.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6318.hsg-1-16-12-2.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>The following image shows the newly created folders.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2046.hsg-1-16-12-3.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2046.hsg-1-16-12-3.jpg\" alt=\"Image of folders\" title=\"Image of folders\" \/><\/a><\/p>\n<p>Now let&rsquo;s fire up the console. To do this, I make an RDP connection to my DC1 server as shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2555.hsg-1-16-12-4.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2555.hsg-1-16-12-4.jpg\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>Yep, it&rsquo;s all there! OK, now let&rsquo;s install the Administration Console on my laptop so I can make use of the assemblies for Windows PowerShell integration. Here is the command line that I use to install only the console.<\/p>\n<p style=\"padding-left: 30px\">. .\\Install-WSUSServer.ps1 &ndash;ConsoleOnly -verbose<\/p>\n<p>The following image shows the command that I use to install the console, and the output from the Install-WSUSServer.ps1 script.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1067.hsg-1-16-12-5.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1067.hsg-1-16-12-5.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>This was a little simpler because I already had the installation file that I needed to complete the Administration Console installation.<\/p>\n<h3>Configure clients to use WSUS<\/h3>\n<p>OK, we have our WSUS server installed and running, and we have our Administration Console installed on the laptop. The next step is to configure my laptop and the server to communicate to the WSUS application so we can image the patches that are required for each client. There are a couple of ways to accomplish this task. If the client is in an Active Directory environment, all you have to is use Group Policy to make the configuration changes.&nbsp;<\/p>\n<p>Note: For non-domain systems, you can make this change by using gpedit.msc.<\/p>\n<p>For the sake of simplicity, I am just going to configure the GPO to point my client to the WSUS server (<b>Specify intranet Microsoft update service location<\/b>), set the update client to only download (<b>Configure Automatic Updates<\/b>) the approved updates, and change the detection to every four hours (<b>Automatic Updates detection frequency<\/b>). The changes are reflected in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0312.hsg-1-16-12-6.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0312.hsg-1-16-12-6.jpg\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>Another way is to do some registry hacking to make the changes, which leads me to my next set of Windows PowerShell scripts that accomplish this task. The first script allows you to view the settings in the registry and the other script allows you to change the registry settings to configure the client. You can find these scripts in the Script Center Repository:<\/p>\n<ul>\n<li>To view the registry settings: <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Get-WSUSClientSetting-e52e4260\" target=\"_blank\">Get-WSUSClientSetting<\/a><\/li>\n<li>To set the registry settings: <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Set-ClientWSUSSetting-2e84b805\" target=\"_blank\">Set-ClientWSUSSetting<\/a><\/li>\n<\/ul>\n<p>For more information about the registry information that I used in these scripts, see <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc708449(WS.10).aspx\" target=\"_blank\">Configure Automatic Updates in a Non&ndash;Active Directory Environment<\/a>.<\/p>\n<p>First, let&rsquo;s see the settings that we will be changing to talk to our WSUS server on DC1. To do this, I use the <b>Get-ClientWSUSSetting<\/b> command as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-ClientWSUSSetting | Select WUServer,WUStatusServer,DetectionFrequency,AUOptions<\/p>\n<p>The following image shows the output from this command.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2728.hsg-1-16-12-7.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2728.hsg-1-16-12-7.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Now let&rsquo;s change these to reflect the same GPO we configured for the domain. Here is the command that does that.<\/p>\n<p style=\"padding-left: 30px\">Set-ClientWSUSSetting -Options DownloadOnly -DetectionFrequency 4 -UpdateServer &#8216;http:\/\/DC1&#8217; -Verbose<\/p>\n<p>The image shown here illustrates the output from the command.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2235.hsg-1-16-12-8.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2235.hsg-1-16-12-8.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Now, I use the <b>Get-ClientWSUSSetting<\/b> command to verify that the changes worked properly. As shown in the following image, it worked just fine.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6431.hsg-1-16-12-9.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6431.hsg-1-16-12-9.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Perfect. Now our clients are talking to the WSUS server, and they will begin reporting what patches are needed to be compliant.<\/p>\n<h3>WSUS and Windows PowerShell<\/h3>\n<p>Now we are at the point where we can begin working with the assemblies by using Windows PowerShell, and make our initial connection to the WSUS server. We want to use the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.updateservices.administration%28v=VS.85%29.aspx\" target=\"_blank\">Microsoft.UpdateServices.Administration<\/a> assembly. Here is the command that I use to load that assembly.<\/p>\n<p style=\"padding-left: 30px\">[reflection.assembly]::LoadWithPartialName(&#8220;Microsoft.UpdateServices.Administration&#8221;) | Out-Null<\/p>\n<p>Now it is time to make the initial WSUS connection by using the .NET accelerator [Microsoft.UpdateServices.Administration.AdminProxy] and the static method <b>getUpdateServer()<\/b>, which requires two values: the WSUS server name and a Boolean value for a secure connection. Because I am not using a secure connection for the WSUS server, we will set it for False. Here is the command.<\/p>\n<p style=\"padding-left: 30px\">$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(&lsquo;DC1&rsquo;,$False)<\/p>\n<p style=\"padding-left: 30px\">$wsus<\/p>\n<p>The output from the command is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4532.hsg-1-16-12-10.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4532.hsg-1-16-12-10.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Here you can see some information regarding the remote WSUS server, such as the port number that is being used and the version of the WSUS server.<\/p>\n<p>That is all for today with WSUS. I have shown the beginnings of using Windows PowerShell to make the initial connection to the WSUS server. Tomorrow I will expand on this by showing how you can use Windows PowerShell to perform some basic administration for your WSUS server.<\/p>\n<p>~Boe<\/p>\n<p>Thanks Boe, that is a great introduction to WSUS. WSUS Week will continue tomorrow.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Guest blogger, Boe Prox, shows how to use Windows PowerShell to install WSUS and configure clients for updates. Microsoft Scripting Guy, Ed Wilson, is here. You are in for a treat this week. Boe Prox has written a week&rsquo;s worth of goodies, and we will share them here. Boe Prox is currently a senior [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[162,56,3,130,45,318],"class_list":["post-11461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-boe-prox","tag-guest-blogger","tag-scripting-guy","tag-servers","tag-windows-powershell","tag-wsus"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger, Boe Prox, shows how to use Windows PowerShell to install WSUS and configure clients for updates. Microsoft Scripting Guy, Ed Wilson, is here. You are in for a treat this week. Boe Prox has written a week&rsquo;s worth of goodies, and we will share them here. Boe Prox is currently a senior [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=11461"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=11461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=11461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=11461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}