Running Powershell script as User

koppees

New Member
How to run Post-Setup Powershell script as a User? What parameters to use and how to point to a specific ps1 file what I want to run?
 
Normally, you add the .ps1 file under Post-Setup (User). No Parameters are required, unless your script expects arguments to be passed.

If you need pass arguments, then add the Command:
powershell-NoProfile -ExecutionPolicy ByPass -f C:\path\to\Script.ps1 argument1 argument2
 
Normally, you add the .ps1 file under Post-Setup (User). No Parameters are required, unless your script expects arguments to be passed.

If you need pass arguments, then add the Command:
powershell-NoProfile -ExecutionPolicy ByPass -f C:\path\to\Script.ps1 argument1 argument2
That is not correct. After Powershell script gets injected into Windows ISO file the path to script would not be a C: drive any more during Windows installation.

The correct relative path to the script should be this, but it does not work:
powershell -NoProfile -ExecutionPolicy ByPass -File "%SystemDrive%\sources\$OEM$\$$\Setup\FilesU\script.ps1"

I also tried this relative path and it does not work either:
powershell -NoProfile -ExecutionPolicy ByPass -File "%WINDIR%\Setup\FilesU\script.ps1"

Windows installation just gets stuck forever.

Funny thing is, everything works just fine when I run a script under Post-Setup (Machine), but this will run the script too early during Windows installation process.
 
Last edited:
That is not correct. After Powershell script gets injected into Windows ISO file the path to script would not be a C: drive any more during Windows installation.

The correct relative path to the script should be this, but it does not work:
powershell -NoProfile -ExecutionPolicy ByPass -File "%SystemDrive%\sources\$OEM$\$$\Setup\FilesU\script.ps1"

As far as I know the Post-Setup (User) scripts run after Windows installation and login as the current user or as Administrator during Sysprep Audit Mode. In either cases, %SystemDrive% would usually resolve to "C:".

If you would like to run the script stored on the ISO, then it should not be %SystemDrive%, but your USB/DVD or Mounted ISO if you, like me, run the script inside a VM.

Btw, %WINDIR% resolves to "C:\Windows" which is probably not correct either.

I think Garlin's example shows when you have an absolute path to the content of the installed image.
 
Back
Top