0

I want to build the script for custom creation of Win pe from Power shell, I have found sample scripts on Internet but they do not work for me.

Script is :

$Architecture = "x86"
$env:path = $env:path + "; C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat; C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\AMD64\DISM;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\AMD64\Imaging;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\AMD64\BCDBoot;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\AMD64\Oscdimg;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\AMD64\Wdsmcast;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\HelpIndexer;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\WSIM;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment;C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Imaging and Configuration Designer\x86;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\; C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\copype.cmd"
$BuildDir = "D:\winpe x86_2"
Write-Host ("Running Copype script please wait...") -Force 'Yellow'
Invoke-Command { copype.cmd $Architecture $BuildDir }

I was trying with Invoke Expression same error, i was trying with DandISetEnv.bat i was puting it in env variable but no success, i can not see what is wrong. Here is the error:

Running Copype script please wait... -Force Yellow
ERROR: The following processor architecture was not found: x86.
Failed!
Mark Skelton
  • 3,663
  • 4
  • 27
  • 47
Milan
  • 1
  • 4
  • 1
    Why do you have file names appended to the path? The system is going to look for *folders* named `C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat\ ` and `C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\copype.cmd\ `. – Bacon Bits Mar 21 '16 at 19:56
  • Thanks for reply What should I do i dont know i am new to power shell? but when i put thous path a get this error and when is other a get error that copype.cmd is not commant of comandlet – Milan Mar 24 '16 at 09:22
  • The PATH environment variable is the search path. It's a list of folders that Windows will look through to find executable files when there isn't one with the right name in the current directory. It's how you're able to type `notepad.exe` and open Notepad when you're at `C:\ `, even though the file is actually at `C:\Windows\System32\notepad.exe`. `C:\Windows\System32\ ` is in the PATH by default. It's not a PowerShell concept. It's a [common OS concept](https://en.wikipedia.org/wiki/PATH_(variable)). – Bacon Bits Mar 24 '16 at 12:40
  • Specifying a file name isn't going to work there. PATH is a list of folder names to search for other files. My guess is that you should start by changing the values to `C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\ ` and `C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\ ` respectively, but offhand I have no idea what configuration `copype.cmd` needs. – Bacon Bits Mar 24 '16 at 12:40
  • I did try erro again Invoke-Command : A positional parameter cannot be found that accepts argument 'D:\winpe_x86'. At D:\posao_instalacija\Winpe_10\skripte\Test2.ps1:5 char:1 + Invoke-Command copype.cmd $Architecture $BuildDir + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand – Milan Apr 07 '16 at 09:31

1 Answers1

0

I stumbled across this old question trying to do the same thing. I managed to get it working with this function:

function Test-CopyPE {
  $peFileDir = "C:\TestCustom\PE_Files"
  $env = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat" 
  cmd.exe /c """$env"" && copype amd64 $peFileDir"
}

These are some of the related answers I used to help me figure it out:

a2k42
  • 672
  • 6
  • 19