{"id":75311,"date":"2015-12-03T00:01:00","date_gmt":"2015-12-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/12\/03\/build-a-powershell-enabled-windows-pe-key-part-4\/"},"modified":"2019-02-18T09:20:48","modified_gmt":"2019-02-18T16:20:48","slug":"build-a-powershell-enabled-windows-pe-key-part-4","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/build-a-powershell-enabled-windows-pe-key-part-4\/","title":{"rendered":"Build a PowerShell-Enabled Windows PE Key: Part 4"},"content":{"rendered":"<p><b>Summary<\/b>: Build out the necessary file structure for a Windows PE environment.<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today to give you all you need to build out your own Windows PE file structure.<\/p>\n<p><b><\/b><strong>&nbsp; &nbsp;Note<\/strong>&nbsp;&nbsp; This is a five-part series that includes the following posts:<\/p>\n<ul>\n<li><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: Part 1<\/a><br>Install the Windows ADK and validate its presence with Windows PowerShell<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/01\/build-a-powershell-enabled-windows-pe-key-part-2.aspx\" target=\"_blank\">Build a PowerShell-Enabled Windows PE Key: Part 2<\/a><br>Customize a Windows PE environment to contain Windows PowerShell and DISM modules<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/02\/build-a-powershell-enabled-windows-pe-key-part-3.aspx\" target=\"_blank\">Build a PowerShell-Enabled Windows PE Key: Part 3<\/a><br>Identify available USB keys and make them bootable devices<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/03\/build-a-powershell-enabled-windows-pe-key-part-4.aspx\" target=\"_blank\">Build a PowerShell-Enabled Windows PE Key: Part 4<\/a><br>Build out the necessary file structure for a Windows PE environment<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/12\/04\/build-a-powershell-enabled-windows-pe-key-part-5.aspx\" target=\"_blank\">Build a PowerShell-Enabled Windows PE Key: Part 5<\/a><br>Populate a bootable USB key with content from Windows PE<\/li>\n<\/ul>\n<p>Let&rsquo;s think about what we&rsquo;ve developed in the first three parts of this series:<\/p>\n<ul>\n<li>One Windows ADK environment for Windows 10. <br> Check.<\/li>\n<li>One customized Windows PE WIM file with Windows PowerShell.<br> Check.<\/li>\n<li>One prepared bootable USB key.<br> Check.<\/li>\n<\/ul>\n<p>Our next task is to pull all of this together into a file structure for Windows PE.<\/p>\n<p>Confused?<\/p>\n<p>Normally, we would take a Windows image file and expand it directly to the target file system. But not with Windows PE. A Windows PE environment boots from a very tiny version of Windows. It then creates a RAM drive (think back to the days of DOS!) and places the WIM file structure within the RAM drive.<\/p>\n<p>Fortunately, we don&rsquo;t need to do any work, the file structure is readily built for us. If you examine the folder structure for Windows PE, you&rsquo;ll see a folder called <b>Media<\/b>. This is located directly under your AMD64 or x86 folder, depending upon the chosen version of Windows PE.<\/p>\n<p>In our case, we are working with the 64-bit version, which means the folder you need to grab is:<\/p>\n<p>C:\\Program Files (x86)\\Windows Kits\\10\\Assessment and Deployment Kit\\Windows Preinstallation Environment\\amd64\\Media<\/p>\n<p>If you use our previous function and <b>$Variables<\/b>, you can reference it in this fashion:<\/p>\n<p style=\"margin-left:30px\">$WinPEMedia=&rdquo;$WinADK\\Media&rdquo;<\/p>\n<p>We now need somewhere to put the file structure of Windows PE, so let&rsquo;s use this:<\/p>\n<p style=\"margin-left:30px\">$WinPETemp=&#8217;C:\\TempPE&#8217;<br> New-Item -ItemType Directory -Path $WinPETemp &ndash;Force<br> Copy-Item -Path &#8220;$WinAdk\\Media&#8221; -Destination $WinPETemp -Recurse &ndash;Force<br>New-Item -ItemType Directory -Path &#8220;$WinPETemp\\Media\\Sources&#8221; &ndash;Force<br>Copy-Item -path &#8220;$WinAdk\\en-us\\winpe.wim&#8221; -Destination &#8220;$WinPETemp\\Media\\Sources\\boot.wim&#8221;<\/p>\n<p>If you did nothing else, you&rsquo;d have yourself a very basic structure for Windows PE under the folder called <b>Media<\/b> that is defined within <b>$WinPETemp<\/b>.<\/p>\n<p>The critical file is called Boot.wim and it is under the <b>Sources<\/b> folder. We need to update this file with the customized version we created in Part 2 of this series. Remember these three lines of PowerShell?<\/p>\n<p style=\"margin-left:30px\">$Destination=&rsquo;C:\\Pewim&rsquo;<br> New-Item -Path $Destination -ItemType Directory &ndash;Force<br> Copy-Item -path &#8220;$WinPETemp\\Media\\boot.wim&#8221; -destination &#8220;$Destination\\&#8221;<\/p>\n<p>We&rsquo;ll need to copy the Boot.wim from the folder defined in <b>$Destination<\/b> to the <b>Sources<\/b> folder:<\/p>\n<p style=\"margin-left:30px\">Copy-Item &ndash;path &ldquo;$Destination\\boot.wim&rdquo; &ndash;destination &ldquo;$WinPETemp\\Media\\Sources&rdquo; &ndash;force<\/p>\n<p>This folder structure will now have everything you need for using Windows PE with Windows PowerShell. Our next phase?<\/p>\n<p>We get that puppy on a USB key and start to play&hellip;tomorrow!<\/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<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Build out the necessary file structure for a Windows PE environment. Honorary Scripting Guy, Sean Kearney, is here today to give you all you need to build out your own Windows PE file structure. &nbsp; &nbsp;Note&nbsp;&nbsp; This is a five-part series that includes the following posts: Build a PowerShell-Enabled Windows PE Key: Part 1Install [&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,3,154,649,45],"class_list":["post-75311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-windows-pe","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Build out the necessary file structure for a Windows PE environment. Honorary Scripting Guy, Sean Kearney, is here today to give you all you need to build out your own Windows PE file structure. &nbsp; &nbsp;Note&nbsp;&nbsp; This is a five-part series that includes the following posts: Build a PowerShell-Enabled Windows PE Key: Part 1Install [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75311","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=75311"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75311\/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=75311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=75311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=75311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}