SOLVED

Restrict PowerShell on end user devices

%3CLINGO-SUB%20id%3D%22lingo-sub-2666453%22%20slang%3D%22en-US%22%3ERestrict%20PowerShell%20on%20end%20user%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666453%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20all%3C%2FP%3E%3CP%3EAll%20devices%20are%20running%20the%20latest%20version%20on%20Windows%2010.%20We%20have%20deployed%20defender%20for%20endpoint%2C%20Intune%2C%20and%20sccm.%20Can%20defender%20for%20endpoint%20tell%20me%20what%20the%20current%20powershell%20execution%20policy%20is%20on%20every%20device%20%3F%20can%20i%20also%20use%20it%20to%20set%20the%20execution%20policy%20in%20mass%3F%20I%20dont%20want%20to%20resort%20to%20GPO%20because%20many%20users%20work%20remotely%20because%20of%20covid.%3C%2FP%3E%3CP%3EThank%20you%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2666515%22%20slang%3D%22en-US%22%3ERe%3A%20Restrict%20PowerShell%20on%20end%20user%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666515%22%20slang%3D%22en-US%22%3EWhy%20not%20run%20a%20script%20using%20Intune%3F%20You%20can%20target%20any%20script%20directly%20to%20devices.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmem%2Fintune%2Fapps%2Fintune-management-extension%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmem%2Fintune%2Fapps%2Fintune-management-extension%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2666562%22%20slang%3D%22en-US%22%3ERe%3A%20Restrict%20PowerShell%20on%20end%20user%20devices%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666562%22%20slang%3D%22en-US%22%3Edoes%20this%20require%20the%20powershell%20execution%20policy%20to%20be%20set%20to%20bypass%3F%20I%20want%20to%20configure%20all%20devices%20for%20%22remote%20signed%22%3C%2FLINGO-BODY%3E
Frequent Contributor

Hello all

All devices are running the latest version on Windows 10. We have deployed defender for endpoint, Intune, and sccm. Can defender for endpoint tell me what the current powershell execution policy is on every device ? can i also use it to set the execution policy in mass? I dont want to resort to GPO because many users work remotely because of covid.

Thank you 

8 Replies
Why not run a script using Intune? You can target any script directly to devices.

https://docs.microsoft.com/en-us/mem/intune/apps/intune-management-extension
does this require the powershell execution policy to be set to bypass? I want to configure all devices for "remote signed"
Scripts that you run using Intune are executed locally on each device. Unless you pull in other resources like scripts or execute another remote script from the one you assign to a device, you shouldn’t have the need to change anything.

Even if you do need to change the execution policy, you could do so from within the script that you assign to a device.
Understood, however if we create a script that is not digitally signed and we deploy the script to devices using intune, if the powershell execution policy on the device is set for RemoteSigned, then from my understanding the script will not run. Again im trying to move away from "bypass" as the execution policy
Disregard my previous advice. For the scripts I've been running up to now using this option, which are not very complex, they simply work using the scripts option in Intune. If you need to change the execution policy it's a bit of a chicken-egg issue, you can't change the policy using a script thats blocked to unblock that script.

You could try to package the script as a Win32 app in Intune, and set the install command to run PowerShell, with something like "powershell.exe -ExecutionPolicy <SomePolicy> -File .\YourScript.ps1". This would run PowerShell with that specific execution policy for that session only, and not modify it globally for the whole system.
Right, and im sure the scripts you are running are not digitally signed. If powershell needs to be setup for "bypass" to allow Intune to run scripts, then to me this presents a security concern, because bypass allows low priv users to run scripts that are not digitally signed
best response confirmed by Skipster311-1 (Frequent Contributor)
Solution
I agree that digitally signing any scripts is best from a security perspective, no doubt about that. Scripts ran via the Intune scripts option will be ran via the Intune Management Extension, which should respect whatever the execution policy is set to on the device itself. There's a few public resources available which recommend the option as described above using a Win32 app in Intune, which might be best for your scenario.

You can also use a configuration profile (Windows 10, Settings catalog) to enforce the PowerShell execution policy on devices. Search for the "Turn on Script Execution" option under "Administrative Templates\Windows Components\Windows PowerShell".
You also helped me with my powershell scripts, i just now noticed that, lol. Well thanks again for all your help