Background: I wanted to get into powershell scripts to automate some tasks at work. I am not an admin, and am not able to run an elevated powershell process. I tend to use batch scripts to programmatically perform certain tasks with command line utilities, but as my abilities have grown it's got to the point where it's clear powershell would be a much more appropriate tool for the task. I played around with the immediate windows, and wrote a basic script just to see if I could get something working.
Once I got a grip on some test commands, I saved them to a file.
Write-Host "Let's do this"
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.MessageBox]::Show("Script Successful")
calc.exe
I was surprised to find that, while I can execute whatever I want in the immediate window, to load a .ps1 (which I guess is the powershell equivalent of a .bat), it has to be signed, and I need to be an admin to change this behaviour.
However, my first thought was just "well, ok, I'll just send my commands to the immediate window from a .bat". So I looked at powershell -help, and wrote the following in the command prompt:
type test.ps1 | powershell -
It works, and it works from a .bat too. Am I missing something here? What's the point in disallowing the calling of .ps1 files from the immediate window if all you need is a .bat that says type harmfulscript.ps1 | powershell -
, and you're good?