{"id":11641,"date":"2011-12-29T00:01:00","date_gmt":"2011-12-29T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/12\/29\/apply-a-service-pack-to-mdt-deployment-shares-by-using-powershell\/"},"modified":"2011-12-29T00:01:00","modified_gmt":"2011-12-29T00:01:00","slug":"apply-a-service-pack-to-mdt-deployment-shares-by-using-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/apply-a-service-pack-to-mdt-deployment-shares-by-using-powershell\/","title":{"rendered":"Apply a Service Pack to MDT Deployment Shares by Using PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft PowerShell MVP, Sean Kearney, shows how to use Windows PowerShell to update MDT Deployment Shares to the latest service pack.\nMicrosoft Scripting Guy, Ed Wilson, is here. It is time for Part 4 of Windows PowerShell MVP, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/guest+blogger\/sean+kearney\/\" target=\"_blank\">Sean Kearney<\/a>&rsquo;s, most excellent series about using Windows PowerShell with the MDT. <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/12\/28\/use-powershell-to-organize-mdt-application-and-driver-folders.aspx\" target=\"_blank\">Yesterday<\/a>, we learned about using Windows PowerShell to organize MDT application and driver folders. Today Sean will show us how to update MDT Deployment Shares to the latest service pack by using Windows PowerShell.\nOne of the coolest things about having MDT to control your deployment setup is the ease of changing the environment. Another cool feature comes when it is time to update the deployed software.\nIf you look at your Deployment Share, it&rsquo;s just a well-organized structure of folders. These folders are organized right down to operating systems and applications.\nAlthough we tell MDT the version of the operating system and the applications, it really has no clue what&rsquo;s in there. To MDT, it&rsquo;s just a folder with some stuff in it. Knowing this means that updating components to, for example, newer service packs is actually quite easy.\nTherefore, to update Windows&nbsp;7 to Windows Service Pack 1, we could delete the contents of the folder that contains Windows&nbsp;7 and replace it with the contents of new media with Service Pack&nbsp;1 through the GUI.\nWe could do that&hellip;we could do that if we were living in a world of sadness where Windows PowerShell did not exist.\nBut because such a tragic thing never happened thanks to our great creative friends on the Windows PowerShell team, we absolutely can use Windows PowerShell for this task.\nSo our first task in MDT is to determine the assigned Name for your MDT Deployment Share. To do this, use the <b>Add-PSSnapin<\/b> to add in the appropriate snap-in. Next, use the <b>Get-MDTPersistentDrive<\/b> cmdlet to retrieve drive information. These two commands are shown here.<\/p>\n<p style=\"padding-left: 30px\">Add-PSsnapin Microsoft.BDD.PSsnapin<\/p>\n<p style=\"padding-left: 30px\">GET-MDTPersistentDrive\nOn the screen, you&rsquo;ll see a list of Deployment Points that are accessible from MDT. In a new scenario, you&rsquo;ll have one drive that is typically named DS001, but it could be any name. Let&rsquo;s assume we&rsquo;re going to work with the first one in the list. To do this, we can index directly into the first drive. This command is shown here.<\/p>\n<p style=\"padding-left: 30px\">(GET-MDTPersistentDrive)[0]\nNow let&rsquo;s look at that Cmdlet that assigns the <i>DSName<\/i> as a connection point. The command to assign the <i>DSName<\/i> uses the <b>New-PSDrive<\/b> cmdlet. The exact syntax appears here.<\/p>\n<p style=\"padding-left: 30px\">New-PSDrive &ndash;Name &lsquo;DS001&rsquo; -PSProvider MDTProvider &ndash;Root &lsquo;C:DeploymentShare&rsquo;\nYou&rsquo;ll see that there are three available Properties that we are interested in. If we look at the display, it seems obvious that the one we want is <b>Name<\/b> for the DSName and <b>Path<\/b> for the root of the particular structure in MDT. To recreate this from the variables that we have just pulled, we can use the commands that follow.<\/p>\n<p style=\"padding-left: 30px\">$PersistentDrive=(GET-MDTPersistentDrive)[0]<\/p>\n<p style=\"padding-left: 30px\">$DSName=$PersistentDrive.Name<\/p>\n<p style=\"padding-left: 30px\">$PhysicalLocation=$PersistentDrive.Path<\/p>\n<p style=\"padding-left: 30px\">New-PSDrive &ndash;Name $DSName &ndash;PSProvider MDTProvider &ndash;Root $PhysicalLocation\nSo after having done this, we&rsquo;ll actually have a new drive mount point named DSxxx: for MDT. Like any other Windows PowerShell provider, you can test it by using the <b>Test-Path <\/b>cmdlet, or simply use the <b>Set-Location<\/b> cmdlet to change the working location to the newly created drive. The following command changes the working location.<\/p>\n<p style=\"padding-left: 30px\">SET-LOCATION &ldquo;$DSName:&rdquo;\nYou can update the operating system in MDT in one of two ways. The most obvious way is to add it as a service pack in MDT. Unfortunately, this is the slower of the two processes because it actually has to run the service pack installation upon deployment of a new operating system. The other option is to obtain newer media with the service pack preinstalled. The media, of course, must be the same version as what you had before (for example, Enterprise, OEM, or Retail).\nTo update the operating system, we need to know (at least) the folder where it was installed. If you use the <b>Get-ChildItem <\/b>cmdlet, you can see the folder names on the Deployment Share. The following command assumes your <b>DSNAME<\/b> is DS001.<\/p>\n<p style=\"padding-left: 30px\">GET-CHILDITEM &ldquo;$DSNAME:Operating Systems&rdquo;\nIf you are curious about which revisions of Windows exist (assuming a folder of Windows&nbsp;7), you can execute the following command.<\/p>\n<p style=\"padding-left: 30px\">GET-CHILDITEM &lsquo;$DSNAME:Operating SystemsWindows 7&rdquo; &ndash;recurse\nKnowing the location, how could you update this? The process is easier than you think. It literally is removing the contents and replacing them. MDT has no real idea about the difference between a Service Pack&nbsp;1 and an RTM release. It just holds a folder of full of information and a catalog. As long as you are replacing the same exact media with a newer service pack version, we can step to the &ldquo;real world&rdquo; and remove the folder contents. We don&rsquo;t need to use the MDT for that. Remember that we obtained the <i>PhysicalPath<\/i> property earlier to tell us where the data is.\nFirst we want to delete the old content. To do this, use the <b>Get-ChildItem <\/b>cmdlet, and pipe the objects to the <b>Remove-Item <\/b>cmdlet. This command is shown here.<\/p>\n<p style=\"padding-left: 30px\">GET-CHILDITEM &ldquo;$PhysicalLocationOperating SystemsWindows 7&rdquo; &ndash;recurse | REMOVE-ITEM &ndash;recurse &ndash;force\nThen we update the structure with the new contents from the DVD media (or an ISO file). Let&rsquo;s presume that the location of the replacement media with Service Pack&nbsp;1 is on Drive E. We literally copy the data back to the new location. Here is the command to accomplish this task.<\/p>\n<p style=\"padding-left: 30px\">COPY-ITEM E:* &ndash;Destination &ldquo;$PhysicalLocationOperating SystemsWindows 7&rdquo; &ndash;recurse &ndash;force\nTaDa! Your operating system in MDT has now been updated to the most current service pack from the provided media. The cool part is that you don&rsquo;t need to do anything other than rebuild your media. All of your task sequences and other configuration details are identical to what they were before.\nTo update your media, we&rsquo;ll need to know what name you gave it. To find out the names within Windows PowerShell, use the <b>Get-ChildItem <\/b>cmdlet in a command similar to the one shown here.<\/p>\n<p style=\"padding-left: 30px\">GET-CHILDITEM &ldquo;$DSName:Media&rdquo;\nTo update the Media for &#8220;WallaWalla&rdquo;, I use the <b>Update-MDTMedia <\/b>cmdlet. This command is shown here.<\/p>\n<p style=\"padding-left: 30px\">UPDATE-MDTMedia &ldquo;WallaWalla&rdquo;\nPulling all of these different commands into a single script would look like this.<\/p>\n<p style=\"padding-left: 30px\">Add-PSsnapin Microsoft.BDD.PSsnapin<\/p>\n<p style=\"padding-left: 30px\"># GET Available MDT points<\/p>\n<p style=\"padding-left: 30px\">GET-MDTPersistentDrive<\/p>\n<p style=\"padding-left: 30px\"># Work on the First Deployment Share<\/p>\n<p style=\"padding-left: 30px\">$PersistentDrive=(GET-MDTPersistentDrive)[0]<\/p>\n<p style=\"padding-left: 30px\"># Get the DSname and Physical Location<\/p>\n<p style=\"padding-left: 30px\">$DSName=$PersistentDrive.Name<\/p>\n<p style=\"padding-left: 30px\">$PhysicalLocation=$PersistentDrive.Path<\/p>\n<p style=\"padding-left: 30px\"># Connect up the MDT PersistentDrive<\/p>\n<p style=\"padding-left: 30px\">New-PSDrive &ndash;Name $DSName &ndash;PSProvider MDTProvider &ndash;Root $PhysicalLocation<\/p>\n<p style=\"padding-left: 30px\"># Remove the contents of an old Windows 7 Folder<\/p>\n<p style=\"padding-left: 30px\">GET-CHILDITEM &ldquo;$PhysicalLocationOperating SystemsWindows 7&rdquo; &ndash;recurse | REMOVE-ITEM &ndash;recurse &ndash;force<\/p>\n<p style=\"padding-left: 30px\"># Replace the contents with fresh DVD Media<\/p>\n<p style=\"padding-left: 30px\">COPY-ITEM E:* &ndash;Destination &ldquo;$PhysicalLocationOperating SystemsWindows 7&rdquo; &ndash;recurse &ndash;force<\/p>\n<p style=\"padding-left: 30px\"># Update the ISO and content folder for &lsquo;WallaWalla&rsquo;<\/p>\n<p style=\"padding-left: 30px\">UPDATE-MDTMedia &ldquo;WallaWalla&rdquo;\nSure, it took a little time to prepare. But knowing the steps involved, you could update multiple deployment points easily. The other option you have if you&rsquo;re good with IMAGEX, is to apply a service pack to an operating system and then recapture it to a new .wim file. You can simply replace the INSTALL.WIM that is within your Windows&nbsp;7 folder structure with your new Gold one (make sure to rename it INSTALL.WIM).\nTomorrow we&rsquo;ll show you how to build a script to automatically build a basic deployment from scratch. You&rsquo;ll of course have to tweak it, but getting it automatically built&hellip;well isn&rsquo;t that what automation and scripting are all about?\n~Sean\nSean! Dude, you rock! Thank you so much for this way cool blog post. I invite everyone to join us tomorrow for the exciting conclusion to Sean&rsquo;s series about using Windows PowerShell and the MDT.\nI 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=\"http:\/\/blogs.technet.commailto: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.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft PowerShell MVP, Sean Kearney, shows how to use Windows PowerShell to update MDT Deployment Shares to the latest service pack. Microsoft Scripting Guy, Ed Wilson, is here. It is time for Part 4 of Windows PowerShell MVP, Sean Kearney&rsquo;s, most excellent series about using Windows PowerShell with the MDT. Yesterday, we learned about [&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":[56,316,3,154,130,45],"class_list":["post-11641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-mdt","tag-scripting-guy","tag-sean-kearney","tag-servers","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft PowerShell MVP, Sean Kearney, shows how to use Windows PowerShell to update MDT Deployment Shares to the latest service pack. Microsoft Scripting Guy, Ed Wilson, is here. It is time for Part 4 of Windows PowerShell MVP, Sean Kearney&rsquo;s, most excellent series about using Windows PowerShell with the MDT. Yesterday, we learned about [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11641","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=11641"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/11641\/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=11641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=11641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=11641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}