July 11, 2019 at 7:21 pm
Ok, just made some progress. I found an old forum post where someone was executing batch files dynamically by passing the commands as variables and it gave me an idea.
What I did, was paste my powershell script into a string variable prepended with -WindowStyle Hidden -NoProfile -Command "powershell script text here"
I had problems initially with getting the script to interpret the statements individually, and after 7 years of doing PowerShell, learned today that PowerShell had a statement terminator of semi-colon. My ending each statement with ;, the whole script was able to run inline and eliminate the need for an external reference to a script file. I love this discovery as whenever I go from SQL to powershell I usually drive myself nuts terminating statements with semicolons for the first couple hours and deleting them, but now I will just leave them in place! (I probably wont stop switching 'print' and 'read' or 'select' and 'get' anytime soon)
Unfortunately storing the command in a variable makes the PowerShell script basically unreadable which is a bit of a bummer if you need to debug or modify the script after, its really easier to go back to the original script, modify it in the ISE and then paste it back in.
Viewing post 1 (of 2 total)
You must be logged in to reply to this topic. Login to reply