PowerShell command as a button


I want to create button with PowerShell command " Set-MpPreference -DisableRealtimeMonitoring 1".
i can't figure it out how to do this correctly.
Mayby it is possible to create button why toggle this two commands:

Set-MpPreference -DisableRealtimeMonitoring 1
Set-MpPreference -DisableRealtimeMonitoring 0

DOpus 12.9 (latest)


More a PowerShell question than an Opus one, so I'm not much of an expert, but I think you can use

PowerShell.exe -command <your command>

to run single line PowerShell commands from outside a PowerShell.

To run PowerShell scripts (which might be what you want if you need to toggle something in PowerShell) see here, or similar pages:

1 Like

Yes you can do it like Leo suggested.
Consider to add following switch if you want to run the command, regardless of what the current powershell execution policy is set to on the computer. "-executionpolicy bypass"

You can run multiple commands as well, they need to be separated by ";".

powershell.exe -executionpolicy bypass -command "write-host 'Listing windir..'; ls $env:windir; exit 10;"

Worth checking out:

powershell /?

Thank You!