$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 Yellow
new-item -type directory $dir\ISO -force | Out-Null
new-item -type directory $dir\ISO\boot -force | Out-Null
new-item -type directory $dir\ISO\EFI -force | Out-Null
new-item -type directory $dir\ISO\sources -force | Out-Null
new-item -type directory $dir\mount -force | Out-Null
write-host "Copying bootmgr to $dir\ISO\" -ForegroundColor Yellow
copy-item $tools\bootmgr $dir\ISO\ -force
write-host "Copying bootmgr.efi to $dir\ISO\" -ForegroundColor Yellow
copy-item $tools\bootmgr.efi $dir\ISO\ -force
write-host "Copying etfsboot.com to $dir\ISO\" -ForegroundColor Yellow
copy-item $tools\boot\etfsboot.com $dir\ -force
write-host "Copying efisys.bin to $dir\" -ForegroundColor Yellow
copy-item $tools\boot\efisys.bin $dir\ -force
write-host "Copying efisys_noprompt.bin to $dir\" -ForegroundColor Yellow
copy-item $tools\boot\efisys_noprompt.bin $dir\ -force
write-host "Copying boot folder and contents to $dir\ISO\boot\" -ForegroundColor Yellow
copy-item $tools\boot\* $dir\ISO\boot\ -recurse -force
write-host "Copying EFI folder and contents to $dir\ISO\EFI\" -ForegroundColor Yellow
copy-item $tools\EFI\* $dir\ISO\EFI\ -recurse -force
write-host "Copying winpe.wim to $dir\" -ForegroundColor Yellow
copy-item $tools\winpe.wim $dir\ -force
write-host "Copying imagex.exe to $dir\" -ForegroundColor Yellow
copy-item $wiak\imagex.exe $dir\ -force
Write-Host ""
Write-Host "Mounting WinPE" -foregroundcolor magenta
dism /Mount-Wim /WimFile:$dir\winpe.wim /index:1 /MountDir:$dir\mount
Write-Host ""
Write-Host "Adding Lan Drivers to WinPE" -foregroundcolor magenta
dism /image:$dir\mount /Add-Driver /Driver:C:\LanDrivers\ /recurse
Write-Host ""
Write-Host "Adding Packages to WinPE" -foregroundcolor magenta
dism /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 $cmd
Write-Output "@echo off" >> $cmd
Write-Output "echo Inititalizing WinPE ..." >> $cmd
Write-Output "wpeinit" >> $cmd
Write-Output "echo Initialized!" >> $cmd
Write-Output "echo Connecting to Image Server ..." >> $cmd
Write-Output "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" >> $cmd
Write-Output "echo Connected!" >> $cmd
Write-Output "cd /d Z:\" >> $cmd
Write-Output "echo Launching GUI Interface ..." >> $cmd
Write-Output "index.hta" >> $cmd
Write-Host ""
Write-Host "Saving Changes and UnMounting WinPE" -foregroundcolor magenta
dism /Unmount-Wim /MountDir:$dir\mount /commit
Write-Host ""
Write-Host "Coping winpe.wim and Changing Name to boot.wim" -foregroundcolor magenta
copy-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 magenta
copy-item $dir\ISO\* $drive`:\ -recurse -force
Write-Host "Completed!" -foregroundcolor green
Start-sleep 3
As 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 $cmd
Write-Output "@echo off" >> $cmd
Write-Output "echo Inititalizing WinPE ..." >> $cmd
Write-Output "wpeinit" >> $cmd
Write-Output "echo Initialized!" >> $cmd
Write-Output "echo Connecting to Image Server ..." >> $cmd
Write-Output "net use Z: `"\\SRHS-SUP-FS\Desktop Support\Images`"" >> $cmd
Write-Output "echo Connected!" >> $cmd
Write-Output "cd /d Z:\" >> $cmd
Write-Output "echo Launching GUI Interface ..." >> $cmd
Write-Output "index.hta" >> $cmd
Write-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:
Quote
X:\ windows\system32> @
' @' is not recognized as an internal or eternal command, operable program or batch file.
' @' 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?



Help
Back to top








