here is a solution, you can save all scripts in a central directory, and keep script from running in other path with Applocker. let's say my scripts are saved in c:\work:
1. Open "local security policy" by secpol.msc
2. Open "Security Settings" -> "Application Control Policy"->"Applocker"->"Script Rules"
3. Right click "Script Rules", Click "Create New Rule..."
4. Select "Allow", and enter the user name which
5. Select "Path"
6. Enter the script file path "C:\work"
7. Click "Next" if you don't need exception
8. Enter the Name of the Rule
9. Click "Yes" to create default rule if it is the first time you use Applocker
After the rule created, if you run powershell script from other path, for instance "c:\temp", you will get error
Only running powershell script under c:\work is allowed.
Actually no only powershell script, but also other script like(.com,.bat...) can only be run from c:\work,
you can create other rules to meet your requirement.
Nice post very helpful
ReplyDeletedbakings
great post...can this be done using powershell..?
ReplyDeleteif so can you post it...
many thanks