Run PowerShell .ps1 scripts in Post-Setup

thehumangerm

New Member
Messages
8
Reaction score
1
Hello,

I changed over my post setup scripts from batch files that run in cmd over to PowerShell for my Win 11 build however Win 11 doesn't seem to natively run ps1 files. I know I can create a .bat file that executed the ps1 files but this seems horribly redundant.

Is there a way I could avoid maintaining an additional .bat file for this purpose? My understanding is windows default script execution policy for PowerShell is undefined which is the equivalent of restricted. My understanding this is done for security reasons by Microsoft which honestly makes no since to me as you can simply change it or run a CMD script to execute. I am wondering if anyone has a better solution to resolve this issue.

Also if you already have code to do this if you wouldn't mind sharing to make sure my spaghetti is reasonable.
 
NTLite explicitly runs each Post-Setup instance of a .ps1 script, by using:
Code:
powershell -NoProfile -ExecutionPolicy Bypass -F script.ps1

Therefore, you don't need to update any of the Execution Policies in order to run a PS script just once during Post-Setup.
If you would like to change the Execution Policy at the system-level, then a simple PS command will do:
Code:
powershell -Command Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force
 
Back
Top