{"id":73001,"date":"2015-10-02T00:01:00","date_gmt":"2015-10-02T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/10\/02\/use-powershell-to-create-windows-to-go-keyspart-5\/"},"modified":"2019-02-18T09:35:03","modified_gmt":"2019-02-18T16:35:03","slug":"use-powershell-to-create-windows-to-go-keyspart-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-create-windows-to-go-keyspart-5\/","title":{"rendered":"Use PowerShell to Create Windows To Go Keys&#8212;Part 5"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Use a basic Windows PowerShell workflow to create multiple devices.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Hey, Scripting Guy! I was wondering if there is an efficient way to use Windows PowerShell to create multiple Windows To Go keys at the same time.<\/p>\n<p>&mdash;TM<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Hello TM,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today. I am going to wind up my week of posts by playing with that very idea.<\/p>\n<p><b>&nbsp; &nbsp;Note<\/b>&nbsp;&nbsp;This is a five-part series that includes the following posts:<\/p>\n<ul>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/09\/28\/use-powershell-to-create-windows-to-go-keys-part-1.aspx\" target=\"_blank\">Use PowerShell to Create Windows To Go Keys&mdash;Part 1<\/a>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; Use Windows PowerShell to identify Windows To Go devices.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/09\/29\/use-powershell-to-create-windows-to-go-keys-part-2.aspx\" target=\"_blank\">Use PowerShell to Create Windows To Go Keys&mdash;Part 2<\/a>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; Use Windows PowerShell to partition a Windows To Go device.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/09\/30\/use-powershell-to-create-windows-to-go-keys-part-3.aspx\" target=\"_blank\">Use PowerShell to Create Windows To Go Keys&mdash;Part 3<\/a>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; Use Windows PowerShell to apply an image to a Windows To Go key and make it bootable.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/10\/01\/use-powershell-to-create-windows-to-go-keys-part-4.aspx\" target=\"_blank\">Use PowerShell to Create Windows To Go Keys&mdash;Part 4<\/a>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp; &nbsp;Use Windows PowerShell to inject drivers and populate the data for Unattend.xml.<\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2015\/10\/02\/use-powershell-to-create-windows-to-go-keys-part-5.aspx\" target=\"_blank\">Use PowerShell to Create Windows To Go Keys&mdash;Part 5<\/a>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp; Use a basic Windows PowerShell workflow to create multiple devices.<\/li>\n<\/ul>\n<p><span style=\"font-size:12px\">Today I&#8217;m going to implement a basic Windows PowerShell workflow to image multiple Windows To Go keys from the same image. The process is actually very close to creating one key, but I need to trap for a few situations:<\/span><\/p>\n<ul>\n<li>Obtain a complete list of all potential Windows To Go keys<\/li>\n<li>Create code for multiple and independent Unattend.xml files<\/li>\n<li>Designate a unique pair of drive letters for the operating system and system drive for each workflow<\/li>\n<\/ul>\n<p>First off, I&#8217;ll give that workflow a name. I&rsquo;ll name this one simply <b>CreateWTG<\/b>:<\/p>\n<p style=\"margin-left:30px\">workflow CreateWTG<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p>Now I get all available Windows To Go devices attached to the computer:<\/p>\n<p style=\"margin-left:30px\">$WTG= Get-Disk | Where-Object { (&#8216;Imation IronKey Wkspace&#8217;,&#8217;Kingston DT Ultimate&#8217;) -match $_.Friendlyname }<\/p>\n<p>I&#8217;ll begin to process all of the keys attached by using <b>Foreach &ndash;parallel<\/b>. This keyword operates in a similar manner to the standard <b>Foreach-Object<\/b>, but it launches the processes in parallel.<\/p>\n<p style=\"margin-left:30px\">Foreach -parallel ($WTGDisk in $WTG)<\/p>\n<p style=\"margin-left:30px\">&nbsp;{<\/p>\n<p>I&#8217;m going to add <b>Start-Sleep<\/b> with a random sequence to try to ensure that the individually spawned processes don&rsquo;t try to grab the same drive Letter. I&rsquo;ll pick a three-minute random window:<\/p>\n<p style=\"margin-left:30px\">Start-Sleep (Get-Random 180)<\/p>\n<p>My next task is to go through the list of keys to use to identify all available drive letters. I will do this each time to try to ensure that I do not clash with drive letters that are in use by any other process. For this, I am going to use two separate tricks in PowerShell.<\/p>\n<p>I first use the CIM class, <b>cim_LogicalDisk<\/b>, which will provide all letters assigned to physical devices and active network drive letters. I can target the <b>DeviceID<\/b> property, which contains the drive letter:<\/p>\n<p style=\"margin-left:30px\">[string[]]$InUse=$NULL<\/p>\n<p style=\"margin-left:30px\">$InUse+=Get-CimInstance cim_logicaldisk | select-object -ExpandProperty DeviceID<\/p>\n<p>Now I have a second issue: drive letters that are assigned to a network drive but are offline. I have not been able to find a CIM class that has this information. But fortunately, it&rsquo;s all stored in the Registry under HKEY_CURRENT_USER\\Network. I can run <b>Get-ChildItem<\/b> against this key to get the list. This will show all network drive letters whether or not they are offline.<\/p>\n<p style=\"margin-left:30px\">$InUse+=Get-ChildItem Registry::HKey_Current_User\\Network &ndash;Name<\/p>\n<p>I now have all the drive letters that are in use by Windows. However, if you examine the list, you will see that the results are &ldquo;Dirty.&rdquo; The data from <b>CIM_LogicalDisk<\/b> and the data from <b>Get-ChildItem<\/b> don&rsquo;t align. Some have colons, and some are lowercase.<\/p>\n<p>I only need to use this list for a simple match comparison. So I am going to build a list of drive letters from A &ndash; Z, then put together an array that contains only those that are not in use.<\/p>\n<p>First I define the array and start the loop:<\/p>\n<p style=\"margin-left:30px\">[string[]]$Available=$NULL<\/p>\n<p style=\"margin-left:30px\"># Step through all letters from A to Z<\/p>\n<p style=\"margin-left:30px\"># Yes <del datetime=\"2015-09-29T11:20\">we<\/del><ins cite=\"mailto:Dia%20Reeves%20(Aquent%20LLC)\" datetime=\"2015-09-29T11:20\">I<\/ins> could have just said 65 to 90 but I thought<\/p>\n<p style=\"margin-left:30px\"># you might find it neat to see how to get the ASCII number<\/p>\n<p style=\"margin-left:30px\"># for a Character<\/p>\n<p style=\"margin-left:30px\">#<\/p>\n<p style=\"margin-left:30px\">for ($x = ([byte][char]&#8217;A&#8217;); $x -le ([byte][char]&#8217;Z&#8217;); $x++)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p>Here I have a simple comparison. If the character in question does not match anything in the array of drive letters that are in use, I will add it to the array.<\/p>\n<p><b>&nbsp; &nbsp;Note<\/b>&nbsp;&nbsp;For those of you (like myself) who are IT pros, the explanation point character ( <b>!<\/b> ) indicates a Boolean NOT.<\/p>\n<p style=\"margin-left:30px\">&nbsp;If (![boolean]($InUse -match [char][byte]$x)) { $Available+=[char][byte]$x }<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p>I could have easily written it like as follows to perform the same thing. (Yes, sometimes Boolean can make your head spin if you&rsquo;re not a developer.)<\/p>\n<p style=\"margin-left:30px\">&nbsp;If ([boolean]($InUse -match [char][byte]$x) &ndash;eq $False) { $Available+=[char][byte]$x }<\/p>\n<p>Now that I have an available list, I&#8217;ll grab two drive letters. I&rsquo;ll use a little <b>Get-Random<\/b> to avoid having things clash.<\/p>\n<p style=\"margin-left:30px\">$Position=[int](Get-Random $Available.count)<\/p>\n<p style=\"margin-left:30px\">&nbsp;$DriveSystem=$Available[$Position]<\/p>\n<p style=\"margin-left:30px\">&nbsp;$DriveOS=$Available[$Position+1]<\/p>\n<p>I can now clear the disk, and partition and format the key in question. Note how I have updated the variable from <b>$WTG<\/b> to <b>$WTGDisk<\/b>. (Remember that I am now in a <b>Foreach<\/b> process.)<\/p>\n<p style=\"margin-left:30px\">$DiskNumber=$WTGDisk.DiskNumber<\/p>\n<p style=\"margin-left:30px\">Clear-Disk &ndash;Number $DiskNumber &ndash;RemoveData &ndash;RemoveOEM &ndash;Confirm:$False<\/p>\n<p style=\"margin-left:30px\">Get-Disk &ndash;number $DiskNumber | Get-Partition | Remove-Partition &ndash;confirm:$False<\/p>\n<p style=\"margin-left:30px\">Initialize-Disk &ndash;Number $DiskNumber &ndash;PartitionStyle MBR<\/p>\n<p style=\"margin-left:30px\">$System=New-Partition -DiskNumber $DiskNumber -size (350MB) &ndash;IsActive<\/p>\n<p style=\"margin-left:30px\">$OS= New-Partition &ndash;DiskNumber $DiskNumber &ndash;UseMaximumSize<\/p>\n<p style=\"margin-left:30px\">Format-Volume -NewFileSystemLabel &#8220;System&#8221; -FileSystem FAT32 -Partition $System -confirm:$False<\/p>\n<p style=\"margin-left:30px\">Format-Volume -NewFileSystemLabel &#8220;Windows&#8221; -FileSystem NTFS -Partition $OS -confirm:$False<\/p>\n<p style=\"margin-left:30px\">Set-Partition -InputObject $System -NewDriveLetter $DriveSystem<\/p>\n<p style=\"margin-left:30px\">Set-Partition -InputObject $OS -NewDriveLetter $DriveOS<\/p>\n<p style=\"margin-left:30px\">Set-Partition -InputObject $OS &ndash;NoDefaultDriveLetter<\/p>\n<p>After the disk is partitioned, I apply the image. However, I need to make sure the log file has a unique name because by default, it&rsquo;s simply called DISM.LOG. So I&rsquo;ll add the disk number as part of its temporary log name.<\/p>\n<p style=\"margin-left:30px\">$Wimfile=&rsquo;.\\install.wim&rsquo;<\/p>\n<p style=\"margin-left:30px\">Expand-WindowsImage &ndash;imagepath &#8220;$wimfile&#8221; &ndash;index 1 &ndash;ApplyPath &#8220;$DriveOS`:\\&#8221; -LogPath &#8220;.\\Dism$($DiskNumber).log&#8221;<\/p>\n<p>Now here is where I hit a snag. The BCDBoot command I need to execute is not a recognized command in the PowerShell workflow engine. But I can alleviate this issue by wrapping it as an inline script, which launches a separate PowerShell process for it to execute out of the workflow.<\/p>\n<p>Because this is a new PowerShell process I need tell it what variables it should use from the existing workflow and then assign it a name. This can be a little confusing for the IT pro at first because the new name can be exactly the same as the old name.<\/p>\n<p style=\"margin-left:30px\">inlinescript<\/p>\n<p style=\"margin-left:30px\">&nbsp; {<\/p>\n<p style=\"margin-left:30px\">&nbsp; $OSDrive=Using:OSDrive<\/p>\n<p style=\"margin-left:30px\">&nbsp; $SystemDrive=UsingSystemDrive<span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n<p style=\"margin-left:30px\">&nbsp; &amp; &#8220;$($env:windir)\\system32\\bcdboot&#8221; &#8220;$OSDrive`:\\Windows&#8221; \/f ALL \/s &#8220;$Systemdrive`:&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; }<\/p>\n<p>I prepare the SAN-Policy.xml as in my previous post, but with one minor change. I will make the file name unique for this process so that I don&rsquo;t have multiple PowerShell processes accessing the same file with the same cmdlet and getting some type of <b>File in Use<\/b> error message. I will use <b>$OSDrive<\/b> as the unique characteristic to modify the file name.<\/p>\n<p style=\"margin-left:30px\">$Policy=@&#8221;<\/p>\n<p style=\"margin-left:30px\">&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242; standalone=&#8217;yes&#8217;?&gt;<\/p>\n<p style=\"margin-left:30px\">&lt;unattend xmlns=&#8221;urn:schemas-microsoft-com:unattend&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;settings pass=&#8221;offlineServicing&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;component<\/p>\n<p style=\"margin-left:30px\">&nbsp; xmlns:wcm=&#8221;http:\/\/schemas.microsoft.com\/WMIConfig\/2002\/St\nate&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; language=&#8221;neutral&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; name=&#8221;Microsoft-Windows-PartitionManager&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; processorArchitecture=&#8221;x86&#8243;<\/p>\n<p style=\"margin-left:30px\">&nbsp; publicKeyToken=&#8221;31bf3856ad364e35&#8243;<\/p>\n<p style=\"margin-left:30px\">&nbsp; versionScope=&#8221;nonSxS&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;SanPolicy&gt;4&lt;\/SanPolicy&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/component&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;component<\/p>\n<p style=\"margin-left:30px\">&nbsp; xmlns:wcm=&#8221;http:\/\/schemas.microsoft.com\/WMIConfig\/2002\/State&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; language=&#8221;neutral&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; name=&#8221;Microsoft-Windows-PartitionManager&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; processorArchitecture=&#8221;amd64&#8243;<\/p>\n<p style=\"margin-left:30px\">&nbsp; publicKeyToken=&#8221;31bf3856ad364e35&#8243;<\/p>\n<p style=\"margin-left:30px\">&nbsp; versionScope=&#8221;nonSxS&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;SanPolicy&gt;4&lt;\/SanPolicy&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/component&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/settings&gt;<\/p>\n<p style=\"margin-left:30px\">&lt;\/unattend&gt;<\/p>\n<p style=\"margin-left:30px\">&#8220;@<\/p>\n<p style=\"margin-left:30px\">$SanPolicyFile=&#8221;.\\$OSDrive-san-policy.xml&#8221;<\/p>\n<p style=\"margin-left:30px\">Remove-item $SanPolicyFile -erroraction SilentlyContinue<\/p>\n<p style=\"margin-left:30px\">Add-content -path $SanPolicyFile -Value $Policy<\/p>\n<p style=\"margin-left:30px\">Use-WindowsUnattend &ndash;unattendpath $SanPolicyFile &ndash;path &#8220;$OSdrive`:\\&#8221;<\/p>\n<p>I now inject the drivers as previously from our source folder:<\/p>\n<p style=\"margin-left:30px\">$Drivers=&rsquo;.\\Drivers&rsquo;<\/p>\n<p style=\"margin-left:30px\">Add-WindowsDriver &ndash;Path &ldquo;$DriveOS`:&rdquo; &ndash;driver $Drivers &ndash;recurse<\/p>\n<p>For the final touch, I will add the Unattend.xml files. I use the same technique with the SAN-Policy.xml file to make the source file unique. What I must do, however, is ensure the file name is still called <b>unattend.xml<\/b> when it transfers to the destination Windows To Go key.<\/p>\n<p style=\"margin-left:30px\">$Computername=&rdquo;WTG-$(Get-Random)&rdquo;<\/p>\n<p style=\"margin-left:30px\">$Organization=&rsquo;Contoso Inc.&rsquo;<\/p>\n<p style=\"margin-left:30px\">$Owner=&rsquo;Contoso Inc. IT Dept.&rsquo;<\/p>\n<p style=\"margin-left:30px\">$Timezone=&rsquo;Eastern Standard Time&rsquo;<\/p>\n<p style=\"margin-left:30px\">$AdminPassword=&rsquo;P@ssw0rd&rsquo;<\/p>\n<p style=\"margin-left:30px\">$Unattend=@&#8221;<\/p>\n<p style=\"margin-left:30px\">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<\/p>\n<p style=\"margin-left:30px\">&lt;unattend xmlns=&#8221;urn:schemas-microsoft-com:unattend&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;settings pass=&#8221;specialize&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;component name=&#8221;Microsoft-Windows-Shell-Setup&#8221; processorArchitecture=&#8221;amd64&#8243; publicKeyToken=&#8221;31bf3856ad364e35&#8243; language=&#8221;neutral&#8221; versionScope=&#8221;nonSxS&#8221; xmlns:wcm=&#8221;http:\/\/schemas.microsoft.com\/WMIConfig\/2002\/State&#8221; xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;ComputerName&gt;$Computername&lt;\/ComputerName&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;RegisteredOrganization&gt;$Organization&lt;\/RegisteredOrganization&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;RegisteredOwner&gt;$Owner&lt;\/RegisteredOwner&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;TimeZone&gt;$Timezone&lt;\/TimeZone&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;\/component&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/settings&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;settings pass=&#8221;oobeSystem&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;component name=&#8221;Microsoft-Windows-Shell-Setup&#8221; processorArchitecture=&#8221;amd64&#8243; publicKeyToken=&#8221;31bf3856ad364e35&#8243; language=&#8221;neutral&#8221; versionScope=&#8221;nonSxS&#8221; xmlns:wcm=&#8221;http:\/\/schemas.microsoft.com\/WMIConfig\/2002\/State&#8221; xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221;&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;UserAccounts&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; &lt;AdministratorPassword&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp; &lt;Value&gt;$Adminpassword&lt;\/Value&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp; &lt;PlainText&gt;true&lt;\/PlainText&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; &lt;\/AdministratorPassword&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;\/UserAccounts&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;AutoLogon&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;Password&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Value&gt;$Adminpassword&lt;\/Value&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;PlainText&gt;true&lt;\/PlainText&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;\/Password&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;Username&gt;administrator&lt;\/Username&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;LogonCount&gt;1&lt;\/Log\\onCount&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;Enabled&gt;true&lt;\/Enabled&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;\/AutoLogon&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;&lt;RegisteredOrganization&gt;$Organization&lt;\/RegisteredOrganization&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;RegisteredOwner&gt;$Owner&lt;\/RegisteredOwner&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;OOBE&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; &lt;HideEULAPage&gt;true&lt;\/HideEULAPage&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; &lt;SkipMachineOOBE&gt;true&lt;\/SkipMachineOOBE&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; &lt;\/OOBE&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp; &lt;\/component&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;\/settings&gt;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&lt;cpi:offlineImage cpi:source=&#8221;&#8221; xmlns:cpi=&#8221;urn:schemas-microsoft-com:cpi&#8221; \/&gt;<\/p>\n<p style=\"margin-left:30px\">&lt;\/unattend&gt;<\/p>\n<p style=\"margin-left:30px\">&#8220;@<\/p>\n<p style=\"margin-left:30px\">$UnattendFile=&rdquo;.\\$OSDrive-unattend.xml&rdquo;<\/p>\n<p style=\"margin-left:30px\">Remove-item $UnattendFile -erroraction SilentlyContinue<\/p>\n<p style=\"margin-left:30px\">Add-content -path $Unattendfile -Value $Unattend<\/p>\n<p style=\"margin-left:30px\">Copy-Item -path $Unattendfile -destination &#8220;$DriveOS`:\\Windows\\System32\\Sysprep\\unattend.xml&#8221;<\/p>\n<p>Finally, I need to remove the drive letters from the partitions to place them back into the available pool:<\/p>\n<p style=\"margin-left:30px\">&nbsp;Get-Volume -DriveLetter $OSDrive | Get-Partition | Remove-PartitionAccessPath -accesspath &#8220;$OSDrive`:\\&#8221;<\/p>\n<p style=\"margin-left:30px\">&nbsp;Get-Volume -DriveLetter $SystemDrive | Get-Partition | Remove-PartitionAccessPath -accesspath &#8220;$SystemDrive`:\\&#8221;<\/p>\n<p>At this point, we should have a complete workflow for creating Windows To Go keys. There are, of course, many ways to improve on this example&mdash;such as adding some logging, bringing in online or offline domain joining, or adding some error trapping.<\/p>\n<p>My hope is that you can use this as a small example for how you could leverage a workflow to make your job easier in the Windows To Go world.<\/p>\n<p>If you would like a copy of this workflow, you can download it fro\nm the Script Center Repository. Play with it directly and see what you can do to improve on its design: <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/Sample-Workflow-to-Deploy-6dc3dc49\" target=\"_blank\">Sample Workflow to Deploy Multiple Windows To Go Keys<\/a>.<\/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 an email to The Scripting Guys 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, remember eat your cmdlets every day with a dash of creativity.<\/p>\n<p><b>Sean Kearney<\/b>, Windows PowerShell MVP and Honorary Scripting Guy<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use a basic Windows PowerShell workflow to create multiple devices. &nbsp;Hey, Scripting Guy! I was wondering if there is an efficient way to use Windows PowerShell to create multiple Windows To Go keys at the same time. &mdash;TM &nbsp;Hello TM, Honorary Scripting Guy, Sean Kearney, is here today. I am going to wind up [&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,154,45,616],"class_list":["post-73001","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell","tag-windows-to-go"],"acf":[],"blog_post_summary":"<p>Summary: Use a basic Windows PowerShell workflow to create multiple devices. &nbsp;Hey, Scripting Guy! I was wondering if there is an efficient way to use Windows PowerShell to create multiple Windows To Go keys at the same time. &mdash;TM &nbsp;Hello TM, Honorary Scripting Guy, Sean Kearney, is here today. I am going to wind up [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/73001","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=73001"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/73001\/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=73001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=73001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=73001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}