{"id":75151,"date":"2015-12-11T00:01:00","date_gmt":"2015-12-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/12\/11\/using-deployimage-and-windows-powershell-to-build-a-nano-server-part-5\/"},"modified":"2019-02-18T09:20:43","modified_gmt":"2019-02-18T16:20:43","slug":"using-deployimage-and-windows-powershell-to-build-a-nano-server-part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/using-deployimage-and-windows-powershell-to-build-a-nano-server-part-5\/","title":{"rendered":"Using DeployImage and Windows PowerShell to Build a Nano Server: Part 5"},"content":{"rendered":"<p><b>Summary<\/b>: Use the <b>DeployImage<\/b> module to build bootable Windows PE media with deployment content.<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today to show you one of my favorite pieces of my <b>DeployImage<\/b> module&mdash;building a piece of bootable USB media that has everything I need to deploy Nano Server.<\/p>\n<p><b>&nbsp; &nbsp;Note<\/b>&nbsp;&nbsp;&nbsp;This is a five-part series that includes the following posts:<\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/use-deployimage-module-and-powershell-to-build-a-nano-server-part-1\/\" target=\"_blank\">Use DeployImage Module and PowerShell to Build a Nano Server: Part 1<\/a><br> Introducing the <b>DeployImage<\/b>&nbsp;module and the cmdlets for Nano Server.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/08\/use-deployimage-module-and-powershell-to-build-a-nano-server-part-2.aspx\" target=\"_blank\">Use DeployImage Module and PowerShell to Build a Nano Server: Part 2<\/a><br> Use the&nbsp;<b>New-NanoServerWim<\/b>&nbsp;cmdlet from the&nbsp;<b>DeployImage<\/b>&nbsp;module to build an updated Nano Server WIM file.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/09\/use-deployimage-module-and-powershell-to-build-a-nano-server-part-3.aspx\" target=\"_blank\">Use DeployImage Module and PowerShell to Build a Nano Server: Part 3<\/a><br> Use the&nbsp;<strong>New-UnattendXMLContent<\/strong>&nbsp;cmdlet in his&nbsp;<strong>DeployImage<\/strong>&nbsp;module to automate naming the Nano Server.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/10\/using-deployimage-and-windows-powershell-to-build-a-nano-server-part-4.aspx\" target=\"_blank\">Using DeployImage and Windows PowerShell to Build a Nano Server: Part 4<\/a><br> Use the new cmdlets in the&nbsp;<b>DeployImage<\/b>&nbsp;module to simplify the deployment of a Nano Server.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/11\/using-deployimage-and-windows-powershell-to-build-a-nano-server-part-5.aspx\" target=\"_blank\">Using DeployImage and Windows PowerShell to Build a Nano Server: Part 5<\/a><br> Use the&nbsp;<b>DeployImage<\/b>&nbsp;module to build bootable Windows PE media with deployment content.<\/li>\n<\/ul>\n<p>Last week in the series, <a href=\"\/b\/heyscriptingguy\/archive\/2015\/11\/30\/build-a-powershell-enabled-windows-pe-key-part-1.aspx\" target=\"_blank\">Build a PowerShell-Enabled Windows PE Key<\/a>, I talkedl about building a Windows PE USB key with Windows PowerShell. This week, I explored how to use the new <b>DeployImage<\/b> module to build out Nano Server. Today we&rsquo;re going to combine them.<\/p>\n<p>Much of the work we did last week&hellip;well, that&rsquo;s now simply a few cmdlets in the <b>DeployImage<\/b> module. We can now build out the custom WIM file with Windows PowerShell with the <b>New-WindowsPEWim<\/b> cmdlet.<\/p>\n<p>If you provide no parameters, it will presume the Windows 10 ADK is on drive C: and that you&rsquo;d like the custom WIM file to exist at C:\\Pewim\\custom.wim. Running this command will build the custom Windows PE WIM file with Windows PowerShell built in, and it will capture the resulting file and path into the <b>$Wimfile<\/b> object:<\/p>\n<p style=\"margin-left:30px\">$Wimfile=New-WindowsPEWim<\/p>\n<p>You can provide an alternate destination and temporary folder by using the <b>WinPETemp<\/b> and <b>Destination<\/b> parameters. The following example will use a temporary folder called C:\\WinPEtemp and place the custom.wim file in &nbsp;the C:\\CustomWim folder:<\/p>\n<p style=\"margin-left:30px\">New-WindowsPEWim &ndash;WinPETemp &lsquo;C:\\WinPETemp&rsquo; &ndash;Destination &lsquo;C:\\CustomWim&rsquo;<\/p>\n<p>It also tweaks that environment to automatically launch PowerShell and attempt to import the <b>DeployImage<\/b> module.<\/p>\n<p>From this point, we pick a drive Letter to use for the USB media, grab an available USB disk from the menu, and partition it:<\/p>\n<p style=\"margin-left:30px\">$OSDrive=&rsquo;L&rsquo;<\/p>\n<p style=\"margin-left:30px\">$Disk=Get-AttachedDisk -USB -GUI<\/p>\n<p style=\"margin-left:30px\">New-PartitionStructure -Disk $disk -OSDrive $OSDrive -USB -MBR<\/p>\n<p>We then build out the Windows PE media folder from the Windows 10 ADK content:<\/p>\n<p style=\"margin-left:30px\">$WinPETemp=&#8217;C:\\TempPE&#8217;<\/p>\n<p style=\"margin-left:30px\">$OSdrive=&#8217;L&#8217;<\/p>\n<p style=\"margin-left:30px\">$Env:WinPERoot=&#8221;$($WinPEDrive)`:\\Program Files$(Get-ArchitectureString)\\Windows Kits\\10\\Assessment and Deployment Kit\\Windows Preinstallation Environment&#8221;<\/p>\n<p style=\"margin-left:30px\">$WinADK=&#8221;$($Env:WinPERoot)\\amd64&#8243;<\/p>\n<p style=\"margin-left:30px\">Remove-item -Path $WinPETemp -Recurse -Force<\/p>\n<p style=\"margin-left:30px\">New-Item -ItemType Directory -Path $WinPETemp -Force<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path &#8220;$WinAdk\\Media&#8221; -Destination $WinPETemp -Recurse -Force<\/p>\n<p style=\"margin-left:30px\">New-Item -ItemType Directory -Path &#8220;$WinPETemp\\Media\\Sources&#8221; -Force<\/p>\n<p style=\"margin-left:30px\">Copy-Item -path $Wimfile -Destination &#8220;$WinPETemp\\Media\\Sources\\boot.wim&#8221;<\/p>\n<p>The following command partitions the USB media we selected earlier, drops in our Windows PE structure, and makes it bootable:<\/p>\n<p style=\"margin-left:30px\">New-PartitionStructure -Disk $disk -OSDrive $OSDrive -USB -MBR<\/p>\n<p style=\"margin-left:30px\">$WinPEKey=$OsDrive+&#8217;:&#8217;<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path &#8220;$WinPETemp\\Media\\*&#8221; -destination &#8220;$WinPeKey\\&#8221; -Recurse<\/p>\n<p style=\"margin-left:30px\">Send-BootCode -OSDrive $OSDrive -USB<\/p>\n<p>We need to identify the current location of the <b>DeployImage<\/b> module. To be honest, it could be in my GitHub folder, your personal modules folder, or almost anywhere. To do this, we&rsquo;ll grab its location from the <b>Path<\/b> property when using <b>Get-Module<\/b>, and we&rsquo;ll pipe this to <b>Split-Path<\/b> to get only the parent folder:<\/p>\n<p style=\"margin-left:30px\">$Modulepath=Split-path ((get-module deployimage).path)<\/p>\n<p>We can now create a folder to hold the module and copy it to our Windows PE key:<\/p>\n<p style=\"margin-left:30px\">New-Item -Path &#8220;$WinPeKey\\DeployImage&#8221; -ItemType Directory -Force<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path &#8220;$ModulePath\\*&#8221; -Destination &#8220;$WinPEkey\\DeployImage&#8221; -Recurse<\/p>\n<p>If we have any drivers to bring over to Nano Server, we&rsquo;ll populate a driver&rsquo;s folder on the Windows PE key:<\/p>\n<p style=\"margin-left:30px\">New-Item -Path &#8220;$WinPEKey\\Drivers&#8221; -ItemType Directory -Force<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path &#8220;$DriverPath\\*&#8221; -Destination &#8220;$WinPEkey\\Drivers&#8221; &ndash;Recurse<\/p>\n<p>Then of course, the most critical piece, the Nano Server media:<\/p>\n<p style=\"margin-left:30px\">New-Item -Path &#8220;$WinPeKey\\NanoServer&#8221; -ItemType Directory -Force<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path &#8220;$($NanoMedia)NanoServer\\*&#8221; -Destination &#8220;$WinPEKey\\NanoServer\\&#8221; -Recurse<\/p>\n<p style=\"margin-left:30px\">Copy-Item -Path $CustomNano -Destination &#8220;$WinPeKey\\NanoServer&#8221;<\/p>\n<p>If you built out a custom Nano Server WIM file, you can also copy that over. Personally, I would throw it into the Nano Server folder&mdash;seems to make more sense:<\/p>\n<p style=\"margin-left:30px\">Copy-Item &ndash;path C:\\Nanotemp\\NanoCustom.wim &ndash;destination &ldquo;$WinPeKey\\NanoServer&rdquo;<\/p>\n<p>Believe it or not, that&rsquo;s it! You should now be able to have a USB key that boots into Windows PowerShell&nbsp;5.0, contains all the media and scripts to not only build a custom Nano Server WIM file, but also deploy it to a physical disk.<\/p>\n<p>The <b>DeployImage<\/b> module is available at the following locations:<\/p>\n<ul>\n<li>Script Center Repository: <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/DeployImage-a-module-to-abdf380d\" target=\"_blank\">DeployImage &#8211; a module to simply WIM file deployments<\/a><\/li>\n<li>PowerShell Gallery: <a href=\"https:\/\/www.powershellgallery.com\/packages\/DeployImage\/\" target=\"_blank\">DeployImage 1.6.0<\/a><\/li>\n<li>GitHub (this a community resource that you can contribute to): <a href=\"https:\/\/github.com\/energizedtech\/DeployImage\" target=\"_blank\">energizedtech\/DeployImage<\/a><\/li>\n<\/ul>\n<p>This module can be used easily to deploy any WIM file including Windows to Go.<\/p>\n<p>This is by no means a final production. If you have feedback, comments, or critique, by all means pass it along to me. There is a lot that can be done to improve this module, including error checking, trapping, and additional Help.<\/p>\n<p>Don&rsquo;t miss next week when Dave Wyatt talks all about using Pester in Windows PowerShell.<\/p>\n<p>I invite you to follow the Scripting Guys 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 them 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, always remember that with great PowerShell comes great responsibility.<\/p>\n<p><b>Sean Kearney, <\/b>Honorary Scripting Guy, Cloud and Datacenter Management MVP&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use the DeployImage module to build bootable Windows PE media with deployment content. Honorary Scripting Guy, Sean Kearney, is here today to show you one of my favorite pieces of my DeployImage module&mdash;building a piece of bootable USB media that has everything I need to deploy Nano Server. &nbsp; &nbsp;Note&nbsp;&nbsp;&nbsp;This is a five-part series [&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,651,154,45],"class_list":["post-75151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-nano-server","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Use the DeployImage module to build bootable Windows PE media with deployment content. Honorary Scripting Guy, Sean Kearney, is here today to show you one of my favorite pieces of my DeployImage module&mdash;building a piece of bootable USB media that has everything I need to deploy Nano Server. &nbsp; &nbsp;Note&nbsp;&nbsp;&nbsp;This is a five-part series [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75151","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=75151"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75151\/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=75151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=75151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=75151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}