r/PowerShell • • Mar 15 '26

Powershell script that acts as powershell when called?

Yeah, I know the title is confusing. I have a system where I can only run PowerShell scripts. I cannot run individual commands themselves, only scripts. It is an actual terminal.

However, it allows you to run it with a parameter. I've kind of managed to get working by doing the below:

param(
    [Parameter(Mandatory = $true)]
    [string]$Command
)


Powershell.exe "$Command"

So I would do run PowerShellScript.ps1 -parameters Get-Process. This works.

Problem is, as soon as there's a space in the parameter, it fails, thinking it's a separate parameter. So I can't do run PowerShellScript.ps1 -parameters Get-process | where processname -like "*Teams*". Any advice on how to get around this? The terminal I have is very basic, trust me when I tell you it can't do much. The solution has to lie within the script itself.

17 Upvotes

31 comments sorted by

View all comments

Show parent comment

2

u/SimpleSysadmin Mar 16 '26

I don’t think it’s a block, I think it’s similar to how you can deploy scripts through intune or an RMM platform but you can’t get an interactive console. He’s pushing scripts via defender but wants the ability to do single command scripts that he can add the command into as an argument.

That’s my read of it