monarch684 Posted August 11, 2012 Share Posted August 11, 2012 I have create a PowerShell script that builds my WInPE 3.0 and then writes it to my choosen jump drive. I automate some changes in the WinPE that seem to crash WinPE when launched. On the other hand if I make the same changes manually everything works fine. The actual WinPE build is fine it is the startnet.cmd that I am editing. Here is the code:$dir = "C:\WinPE64"$waik = "C:\Program Files\Windows AIK\Tools\amd64"$tools = "C:\Program Files\Windows AIK\Tools\PETools\amd64"$pak = "C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs"$cmd = "$dir\mount\Windows\System32\startnet.cmd"CLS;write-host "Creating Directories" -ForegroundColor Yellownew-item -type directory $dir\ISO -force | Out-Nullnew-item -type directory $dir\ISO\boot -force | Out-Nullnew-item -type directory $dir\ISO\EFI -force | Out-Nullnew-item -type directory $dir\ISO\sources -force | Out-Nullnew-item -type directory $dir\mount -force | Out-Nullwrite-host "Copying bootmgr to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\bootmgr $dir\ISO\ -forcewrite-host "Copying bootmgr.efi to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\bootmgr.efi $dir\ISO\ -forcewrite-host "Copying etfsboot.com to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\boot\etfsboot.com $dir\ -forcewrite-host "Copying efisys.bin to $dir\" -ForegroundColor Yellowcopy-item $tools\boot\efisys.bin $dir\ -forcewrite-host "Copying efisys_noprompt.bin to $dir\" -ForegroundColor Yellowcopy-item $tools\boot\efisys_noprompt.bin $dir\ -forcewrite-host "Copying boot folder and contents to $dir\ISO\boot\" -ForegroundColor Yellowcopy-item $tools\boot\* $dir\ISO\boot\ -recurse -forcewrite-host "Copying EFI folder and contents to $dir\ISO\EFI\" -ForegroundColor Yellowcopy-item $tools\EFI\* $dir\ISO\EFI\ -recurse -forcewrite-host "Copying winpe.wim to $dir\" -ForegroundColor Yellowcopy-item $tools\winpe.wim $dir\ -forcewrite-host "Copying imagex.exe to $dir\" -ForegroundColor Yellowcopy-item $wiak\imagex.exe $dir\ -forceWrite-Host ""Write-Host "Mounting WinPE" -foregroundcolor magentadism /Mount-Wim /WimFile:$dir\winpe.wim /index:1 /MountDir:$dir\mountWrite-Host ""Write-Host "Adding Lan Drivers to WinPE" -foregroundcolor magentadism /image:$dir\mount /Add-Driver /Driver:C:\LanDrivers\ /recurseWrite-Host ""Write-Host "Adding Packages to WinPE" -foregroundcolor magentadism /image:$dir\mount /Add-Package /PackagePath:"$pak\winpe-wmi.cab" /PackagePath:"$pak\winpe-scripting.cab" /PackagePath:"$pak\winpe-hta.cab"Write-Host ""Write-Host "Adding GUI Interface to WinPE" -foregroundcolor magenta<#$startnet = [diagnostics.process]::start("notepad.exe", "'$dir\mount\Windows\System32\startnet.cmd'") $startnet.waitforexit() #>Get-Content $cmd | Where {$_ -ne "wpeinit"} | Out-File $cmdWrite-Output "@echo off" >> $cmdWrite-Output "echo Inititalizing WinPE ..." >> $cmdWrite-Output "wpeinit" >> $cmdWrite-Output "echo Initialized!" >> $cmdWrite-Output "echo Connecting to Image Server ..." >> $cmdWrite-Output "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" >> $cmdWrite-Output "echo Connected!" >> $cmdWrite-Output "cd /d Z:\" >> $cmdWrite-Output "echo Launching GUI Interface ..." >> $cmdWrite-Output "index.hta" >> $cmdWrite-Host ""Write-Host "Saving Changes and UnMounting WinPE" -foregroundcolor magentadism /Unmount-Wim /MountDir:$dir\mount /commitWrite-Host ""Write-Host "Coping winpe.wim and Changing Name to boot.wim" -foregroundcolor magentacopy-item $dir\winpe.wim $dir\ISO\sources\boot.wim | Out-Null"list disk" | diskpart $disk = Read-Host "Select Disk Number""select disk $disk", "clean", "create partition primary", "select partition 1", "active", "format fs=fat32 quick", "assign", "exit" | diskpart$drive = Read-Host "What letter was assigned to drive"Write-Host ""Write-Host "Copying WinPE Files to Jump Drive" -foregroundcolor magentacopy-item $dir\ISO\* $drive`:\ -recurse -forceWrite-Host "Completed!" -foregroundcolor greenStart-sleep 3As you can see here:Write-Host "Adding GUI Interface to WinPE" -foregroundcolor magenta<#$startnet = [diagnostics.process]::start("notepad.exe", "'$dir\mount\Windows\System32\startnet.cmd'") $startnet.waitforexit() #>Get-Content $cmd | Where {$_ -ne "wpeinit"} | Out-File $cmdWrite-Output "@echo off" >> $cmdWrite-Output "echo Inititalizing WinPE ..." >> $cmdWrite-Output "wpeinit" >> $cmdWrite-Output "echo Initialized!" >> $cmdWrite-Output "echo Connecting to Image Server ..." >> $cmdWrite-Output "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" >> $cmdWrite-Output "echo Connected!" >> $cmdWrite-Output "cd /d Z:\" >> $cmdWrite-Output "echo Launching GUI Interface ..." >> $cmdWrite-Output "index.hta" >> $cmdWrite-Host ""I have palyed with manually entering the code and automating the input of the code. The error I get when I automate this is:X:\ windows\system32> @' @' is not recognized as an internal or eternal command, operable program or batch file.Any ideas why this works when I manually edit this file verses automatically editting this file? Link to comment Share on other sites More sharing options...
IcemanND Posted August 11, 2012 Share Posted August 11, 2012 It doesn't like the default unicode encoding of out-file. It also appears to have a problem with the file being "open" at the same time you are writing to it, though since the default startnet.cmd file only has the one wpeinit line it may not make a difference to you.Personally I would replace this:Get-Content $cmd | Where {$_ -ne "wpeinit"} | Out-File $cmdWrite-Output "@echo off" >> $cmdWrite-Output "echo Inititalizing WinPE ..." >> $cmdWrite-Output "wpeinit" >> $cmdWrite-Output "echo Initialized!" >> $cmdWrite-Output "echo Connecting to Image Server ..." >> $cmdWrite-Output "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" >> $cmdWrite-Output "echo Connected!" >> $cmdWrite-Output "cd /d Z:\" >> $cmdWrite-Output "echo Launching GUI Interface ..." >> $cmdWrite-Output "index.hta" >> $cmdWith something like this:$startnet = Get-Content $cmd | Where {$_ -ne "wpeinit"}$startnet += "@echo off" $startnet += "echo Inititalizing WinPE ..." $startnet += "wpeinit" $startnet += "echo Initialized!" $startnet += "echo Connecting to Image Server ..." $startnet += "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" $startnet += "echo Connected!" $startnet += "cd /d Z:\" $startnet += "echo Launching GUI Interface ..." $startnet += "index.hta" Out-File -filepath $cmd -InputObject $startnet -Encoding ASCII Link to comment Share on other sites More sharing options...
monarch684 Posted August 11, 2012 Author Share Posted August 11, 2012 I tried this:$startnet = Get-Content $cmd | Where {$_ -ne "wpeinit"} $startnet += "@echo off" $startnet += "echo Inititalizing WinPE ..." $startnet += "wpeinit" $startnet += "echo Initialized!" $startnet += "echo Connecting to Image Server ..." $startnet += "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" $startnet += "echo Connected!" $startnet += "cd /d Z:\" $startnet += "echo Launching GUI Interface ..." $startnet += "index.hta" Out-File -filepath $cmd -InputObject $startnet -Encoding ASCIIand got this:echo off echo Initializing WinPE ... wpeinit echo Initializied! echo Connecting to Image Server ... net use Z: “\\SRHS-SUP-FS\Desktop Support\Images” echo Connected cd /d Z:\ echo Launching GUI Interface ... index.htaX:\windows\system32>It looks like there are no hard returns being put in. Link to comment Share on other sites More sharing options...
monarch684 Posted August 11, 2012 Author Share Posted August 11, 2012 I modified the script as follows:$startnet = Get-Content $cmd | Where {$_ -ne "wpeinit"} $startnet += "@echo off`r`n" $startnet += "echo Inititalizing WinPE ...`r`n" $startnet += "wpeinit`r`n" $startnet += "echo Initialized!`r`n" $startnet += "echo Connecting to Image Server ...`r`n" $startnet += "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"`r`n" $startnet += "echo Connected!`r`n" $startnet += "cd /d Z:\`r`n" $startnet += "echo Launching GUI Interface ...`r`n" $startnet += "index.hta`r`n" It now works. Here is the final script:$dir = "C:\WinPE64"$waik = "C:\Program Files\Windows AIK\Tools\amd64"$tools = "C:\Program Files\Windows AIK\Tools\PETools\amd64"$pak = "C:\Program Files\Windows AIK\Tools\PETools\amd64\WinPE_FPs"$cmd = "$dir\mount\Windows\System32\startnet.cmd"CLS;write-host "Creating Directories" -ForegroundColor Yellownew-item -type directory $dir\ISO -force | Out-Nullnew-item -type directory $dir\ISO\boot -force | Out-Nullnew-item -type directory $dir\ISO\EFI -force | Out-Nullnew-item -type directory $dir\ISO\sources -force | Out-Nullnew-item -type directory $dir\mount -force | Out-Nullwrite-host "Copying bootmgr to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\bootmgr $dir\ISO\ -forcewrite-host "Copying bootmgr.efi to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\bootmgr.efi $dir\ISO\ -forcewrite-host "Copying etfsboot.com to $dir\ISO\" -ForegroundColor Yellowcopy-item $tools\boot\etfsboot.com $dir\ -forcewrite-host "Copying efisys.bin to $dir\" -ForegroundColor Yellowcopy-item $tools\boot\efisys.bin $dir\ -forcewrite-host "Copying efisys_noprompt.bin to $dir\" -ForegroundColor Yellowcopy-item $tools\boot\efisys_noprompt.bin $dir\ -forcewrite-host "Copying boot folder and contents to $dir\ISO\boot\" -ForegroundColor Yellowcopy-item $tools\boot\* $dir\ISO\boot\ -recurse -forcewrite-host "Copying EFI folder and contents to $dir\ISO\EFI\" -ForegroundColor Yellowcopy-item $tools\EFI\* $dir\ISO\EFI\ -recurse -forcewrite-host "Copying winpe.wim to $dir\" -ForegroundColor Yellowcopy-item $tools\winpe.wim $dir\ -forcewrite-host "Copying imagex.exe to $dir\" -ForegroundColor Yellowcopy-item $wiak\imagex.exe $dir\ -forceWrite-Host ""Write-Host "Mounting WinPE" -foregroundcolor magentadism /Mount-Wim /WimFile:$dir\winpe.wim /index:1 /MountDir:$dir\mountWrite-Host ""Write-Host "Adding Lan Drivers to WinPE" -foregroundcolor magentadism /image:$dir\mount /Add-Driver /Driver:C:\LanDrivers\ /recurseWrite-Host ""Write-Host "Adding Packages to WinPE" -foregroundcolor magentadism /image:$dir\mount /Add-Package /PackagePath:"$pak\winpe-wmi.cab" /PackagePath:"$pak\winpe-scripting.cab" /PackagePath:"$pak\winpe-hta.cab"Write-Host ""Write-Host "Adding GUI Interface to WinPE" -foregroundcolor magenta$startnet = Get-Content $cmd | Where {$_ -ne "wpeinit"} $startnet += "@echo off`r`n" $startnet += "echo Inititalizing WinPE ...`r`n" $startnet += "wpeinit`r`n" $startnet += "echo Initialized!`r`n" $startnet += "echo Connecting to Image Server ...`r`n" $startnet += "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"`r`n" $startnet += "echo Connected!`r`n" $startnet += "cd /d Z:\`r`n" $startnet += "echo Launching GUI Interface ...`r`n" $startnet += "index.hta`r`n" Out-File -filepath $cmd -InputObject $startnet -Encoding ASCIIWrite-Host ""Write-Host "Saving Changes and UnMounting WinPE" -foregroundcolor magentadism /Unmount-Wim /MountDir:$dir\mount /commitWrite-Host ""Write-Host "Coping winpe.wim and Changing Name to boot.wim" -foregroundcolor magentacopy-item $dir\winpe.wim $dir\ISO\sources\boot.wim | Out-Null"list disk" | diskpart $disk = Read-Host "Select Disk Number""select disk $disk", "clean", "create partition primary", "select partition 1", "active", "format fs=fat32 quick", "assign", "exit" | diskpart$drive = Read-Host "What letter was assigned to drive"Write-Host ""Write-Host "Copying WinPE Files to Jump Drive" -foregroundcolor magentacopy-item $dir\ISO\* $drive`:\ -recurse -forceWrite-Host "Completed!" -foregroundcolor greenStart-sleep 3 Link to comment Share on other sites More sharing options...
IcemanND Posted August 11, 2012 Share Posted August 11, 2012 Strange. It added all of the carriage returns when I tested it before posting otherwise I would have added them. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now