r/PowerShell • u/musbur • Dec 04 '25
Solved How to automate stuff on a system that can't run PS scripts?
Coming from Linux I'm used to being able to write shell scripts for whatever repetitive little tasks there may be. Now I'm trying to do the same thing on my Win11 work computer but find that company policy prevents that:
find1.ps1 cannot be loaded because running scripts is disabled on this system.First off, this broad policy seems kind of stupid -- what's the security difference between typing some commands by hand and executing them as a script? Evaluating the permissions of each command as the script is executed (as Linux does) seems to be a more sensible option. Is there any way around this? Am I really supposed to copy-paste PS snippets from a text file into a terminal window?
EDIT
by "is there a way around it" I didn't mean circumventing IT security policy but maybe some other powershell trick that I'm unaware of, like being able to at least define aliases without having to be "running scripts."
EDIT 2
...aaand I found the "trick." In Settings->PowerShell, I could just flip the switch to allow execution of unsigned local scripts. Now also my $profile is sourced to define some useful aliases or functions, which is basically all I wanted. I guess it all makes sense: Somebody too stupid to find that setting probably shouldn't be running PS scripts. I may have barely cleared that hurdle. Thanks for the suggestions everybody.
7
u/Alaknar Dec 04 '25
The difference is that when you're writing them out by hand, most of the time you know what you're doing.
If you're just executing a ps1, you might not even realise what's sitting inside - and you can do a lot of malicious stuff with PowerShell.
This has nothing to do with permissions. It's a basic security measure. Permissions ARE checked as the script runs, but that's a separate thing.
No, you're supposed to do what grown-ups do and talk to your IT, present the business justification for the exemption, and set it up the official way. If IT protests, escalate through your manager.
2
u/purplemonkeymad Dec 04 '25
Is it actually enforced or just the default on your machine. By default scripts outside trusted zones are blocked. If you start powershell with the -ExecutionPolicy parameter set to bypass and it works, it's just the default.
To know if it's a policy run:
The two policy scopes are set by group policy. If that is the case, you can ask your IT if you can get a signing certificate, so that you can sign scripts.
This is not considered a security boundary, for that they would need to be using app locker, which can force stuff like constrained language mode for unsigned scripts.
41
u/-Shants- Dec 04 '25
Bring it up with your manager/IT team to get a policy exemption. Work with your IT dept, not around it
21
u/alconaft43 Dec 04 '25
Set-ExecutionPolicy [-ExecutionPolicy] <ExecutionPolicy> [[-Scope] <ExecutionPolicyScope>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
1
u/musbur Dec 05 '25
Just to clear up a misconception: I wasn't "given a task" that I can only solve with PS without my employer giving me sufficient access to PS. I was just trying to find files with certain names, and since I've been working quickly and efficiently for decades in Unix shells I wanted to basically reproduce the functionality of "find" in PS. And learn some PS in the process. But where Unix commands shine by terseness to the point of being cryptic, PS is so verbose that I immediately turned towards wanting to write a little function for this. You know the rest.
As far as my employer is concerned, I might as well klutz around with Explorer's slow and shitty search or scan all subdirectories by hand like everybody else does. This is not an IT affine company.
7
u/redditnamehere Dec 04 '25
From a cybersecurity professional, scripts can be executed by bad actors on employees devices. I’ve seen it happen - this policy reduces the attack surface.
You know the strengths of using automation, id have a chat with IT (put in a help desk ticket) and understand how you can work together. Maybe a local powerautomate set up and IT can advise how they can put in controls to make them satisfied, for starters. It may be a dead end, but don’t circumvent - MS Defender can do its job pretty well.
3
u/cool24a Dec 04 '25
Sandbox it! Use a virtual Windows machine to test things out and get buy in from leadership!
1
u/richie65 Dec 04 '25
If you cannot get your sysadmin to cooperate...
You can use '
Invoke-Expression' (iex) and keep your scripts in a text file...The only thing the policy blocking scripts does, is prevent the running of '.ps1' (et al.) files.
You can still open a PoSh prompt, or ISE I assume...
Then you can run something like this:
And also - If you open ISE and navigate to the '.txt' file that is your script, you can open that '.txt' file in ISE, then select all (or what-have-you) and run the selected portion.
1
u/odwulf Dec 04 '25
People who suggest "Set-ExecutionPolicy" or "Powershell -ExecutionPolicy ByPass" have never seen a properly secured computer environment. I write Powershell for a living and have done so for years on a computer where I had to create a function to disable Powershell's inner authorization manager (the thing that handles the execution policy) in a profile that was signed with a self-signed certificate. There was no officially sanctioned way to disable the GPO that blocked any change to the locked down execution policy.
1
u/BlackV Dec 04 '25
Set execution policy to remote signed
As always execution policy is not a security boundary
Or sign your script
1
u/Dave_A480 Dec 04 '25
Can you get them to allow WSL on your machine?
If so then you can do linux-stuff in WSL that manipulates data in /mnt/c (which is the windows root drive mounted into WSL)
1
u/neztach Dec 04 '25
All the advise given is valid and should be considered first. However if you wrote the script - and you’re desperate, turn the whole script into a GOLF’d one-liner and copy/paste it
1
u/malice8691 Dec 05 '25
Im guessing its policy because they expect you to run your stuff on a vm? Like either way you need a place to run your script. Provide it or dont give me this task.
1
u/Pixelgordo Dec 05 '25
Run powershell ISE, load the scripts, and then send Crtl E and then F8
1
u/TheDisapprovingBrit Dec 04 '25
No, there is no way around this that won't get you fired. Your employer has decided that allowing script execution is a risk and that your position does not require you to do so.
If you disagree with that stance, provide your manager with your justification for an exemption to the policy and ask them to sign off on it.
1
u/Relative_Test5911 Dec 04 '25 edited Dec 04 '25
Allowing users to execute unknown scripts on their devices is a significant risk. Ask your IT they may add you in as an exception. We are just moving to signed PowerShell only which is going to be a nightmare. Also, we do not allow scripts on user machines. Only VM's.
Pray your IT dont enforce signing. Also if they aren't actually use the below to cmd to run it:
1
u/binaryhextechdude Dec 04 '25
We have a group we put people in who are allowed to run scripts. Everyone else is blocked. Given the incompetence of the average computer user it’s for the best
0
u/Certain-Community438 Dec 04 '25
This kind of configuration indicates a very immature operating environment.
Nonetheless, it's the hand you've been dealt, you'll need to play it.
Ask how an approved exemption can be acquired, and you better be able to demonstrate meaningful gains to your own boss if you want their backing ;)
0
u/mrmattipants Dec 04 '25 edited Dec 08 '25
Assuming you've done your due diligence (i.e. Set-ExecutionPolicy, etc.) and you literally have no option to utilize PowerShell, you could always write/run Batch Scripts (via .BAT or .CMD Files) which are essentially just DOS Commands.
My previous job consisted of writing/running .BAT Scripts, for the purpose of Automation via GPO. In my experience, you can use Batch Scripts to accomplish just about any task that you can with PowerShell.
Of course, I'd take PowerShell over any of the various alternatives, but a Batch Script will do, in a pinch.
Whatever you choose, just say "No" to VBScript. ;)
0
u/texan01 Dec 04 '25
You can also convert it to an exe file.
0
u/Outrageous_Plant_526 Dec 04 '25 edited Dec 04 '25
Depending on the script open the Powershell ISE and copy and paste the script into it and then run it. We have the same restrictions for non-admins and using the ISE works fine. Normally it is the .ps1 extension that is being blocked.
We also setup a management script server just for this scenario where an exception could be made on that server and only that server so scripts could be run.
8
u/[deleted] Dec 04 '25 edited Dec 04 '25
[removed] — view removed comment