I have been creating a powershell script to help me automate tasks across various user's PCs, I've encountered an issue where I have to manually allow scripts to run on each PC before I can execute it.
I have attempted to use various solutions that I have found but so far none seem to work.
Solutions I have tried as a batch file (Ideally I would like to have the batch file download the script (sorted this already) then open the powershell script and successfully bypass this):
powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "multitool.ps1"
powershell -command "& {Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force}"
@echo off
reg add HKLM\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell /v "Path" /d "c:\windows\system32\windowspowershell\v1.0\powershell.exe"
reg add HKLM\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell /v "ExecutionPolicy" /d "unrestricted"
@echo off
regedit /s file.reg
Where file.reg contains the following:
[hkey_local_machine\system32\windows\microsoft\powershell\1\shellids\microsoft.powershell]
"Path"="c:\windows\system32\windowspowershell\v1.0\powershell.exe"
"ExecutionPolicy"="unrestricted"
All of these result in the following when running the powershell script:
All help is greatly appreciated
Closest solution I've found for this is running the following line in powershell as admin which will execute the script and bypass the restrictions:
powershell.exe -executionpolicy unrestricted C:\multitool.ps1
If anyone has a cleaner solution that can run the script from the bat file I would greatly appreciate it.