Put this together for a coworker to switch between Windows XP and Windows 7.  Was a “quicky” solution so feedback welcome to polish it up.

Note:  You will need to place a copy of bcdedit.exe in the C:\Windows\System32 directory of your XP instance.

-Shane

[CmdletBinding()]
param(
 
    [Parameter(Mandatory=$True)]
    [ValidateSet('WIN7','WINXP')]
    [string]$OperatingSystem
 
)
 
[System.Collections.ArrayList]$BCDInfo = . "$env:SystemRoot\system32\bcdedit.exe" /v
 
$IDIndex = $BCDInfo.IndexOf("Windows Boot Loader") + 2
 
$Win7GUID = ($BCDInfo[$IDIndex].Split(" "))[-1]
 
. "$env:SystemRoot\system32\bcdedit.exe" /set "{ntldr}" description “Windows XP Pro”
. "$env:SystemRoot\system32\bcdedit.exe" /set "$Win7GUID" description “Windows 7”
. "$env:SystemRoot\system32\bcdedit.exe" /timeout 5
 
switch ($OperatingSystem) {
    'WIN7'    {
    
        . "$env:SystemRoot\system32\bcdedit.exe" /default "$Win7GUID"
        
        . "$env:SystemRoot\system32\bcdedit.exe" /displayorder "$Win7GUID" "{ntldr}"
        
        for($i=10;$i -gt 0;$i--)
        {
            Write-Host "Restarting in $i"
            Sleep 1
        }
        
        Restart-Computer -Force
    
    }
    'WINXP'  { 
        
        . "$env:SystemRoot\system32\bcdedit.exe" /default "{ntldr}"
        
        . "$env:SystemRoot\system32\bcdedit.exe" /displayorder "{ntldr}" "$Win7GUID"
        
        for($i=10;$i -gt 0;$i--)
        {
            Write-Host "Restarting in $i"
            Sleep 1
        }
        
        Restart-Computer -Force
    
    }
}
Advertisements