This topic contains 8 replies, has 4 voices, and was last updated by
October 19, 2018 at 9:00 am #114562
I'm trying to run a script using powershell version 2, however it's not working.
So i'm using – powershell -Version 2 (script) = failed
However if I use powershell -Version 2 first to launch powershell version 2 then paste the script in to the window it works perfectly.
So my question is, is there a way to automate this, open powershell -Version 2 first then append the script inside this version 2 window?
October 19, 2018 at 9:07 am #114568ModeratorPoints: 204Rank: Participant
Hm. You could try running:
powershell.exe -Version 2 -File (ScriptPath)
If that doesn't work, can you provide the error message?
October 19, 2018 at 9:12 am #114573
Thanks for the reply James.
I tried this method too, the window just opens and closes. There is no error message unfortunately. I just know the script hasn't worked. But again, if I manually paste it, then it works perfectly.
October 19, 2018 at 9:36 am #114579
@Roger , Is it possible to show the content in your code.
Are you able to open a version 2.0 shell and execute from there instead of using -file.
October 19, 2018 at 10:04 am #114583
Colleagues System Update
set objshell = Createobject("wscript.shell")
objshell.Run("powershell -Version 2 (rest of code goes here)")
October 19, 2018 at 1:50 pm #114618
Why do you call a PowerShell script inside a VB script ?
You should just use PowerShell only. Can you explain lil about your use case here ?
And please checkout the syntax using PowerShell.exe /? in PowerShell or cmd
October 20, 2018 at 8:48 am #115150
Many thanks for your replies.
I understand this seems a bit strange, so i'll try and explain a little further.
I'm using a hta file to load an onclick button, once clicked it will run the powershell script. I know this is a long winded way of doing things but for the purpose of this experiment this is how it has to be.
I'm trying to prove that a script that should not be run in Powershell V2 can be, by simply downgrading the version.
I can successfully downgrade the version however when the script is appended to Powershell -Version 2 (script) it still runs in V5. UNLESS I manually load pwowershell, downgrade the version first and paste in the rest of the script in to that powershell prompt window. This then works as it should and it's ran from with-inside V2.
So my question is, why doesn't this work in the first instance and how can this be overcome? Is there a way to read in the rest of the script once Powershell is downgraded automatically?
Hope this clears things up.
I also know V2 shouldn't be used, all the security issues associated with it and such, however as mentioned this is purely experimental and I would like to understand what's going on.
October 20, 2018 at 3:20 pm #115179
Are you using the -file parameter ? I cannot reproduce your issue using below code.
Sub TestSub() set objshell = Createobject("wscript.shell") objshell.Run("PowerShell.exe -v 2.0 -f c:\temp\test1.ps1") End Sub TestSub()
if you are not using -file, please use it, other wise using -command option will be tedious of big scripts.
October 19, 2018 at 10:08 pm #115092ParticipantPoints: 1,347Rank: Community Hero
Why are you using PS2?
MS has already publicly stated it's announced depreciation …
Jeffrey Snover, a Microsoft Technical Fellow and the "father" of PowerShell, had few tears to shed over the impending demise of Windows PowerShell 2.0. In a Twitter post, he advised moving to new versions of PowerShell:
"PowerShell V2 is being deprecated (and that is a very good thing). If you still use V2, upgrade now to avoid drama."
The rationale is that Windows PowerShell 2.0 currently lacks security protections that have been built into later versions, particularly PowerShell 5.0.
...as well as the threat to downgrade attacks for those with higher PS versions.
I cannot imagine any reason to still be on PSv2, unless you are being blocked from upgrading for whatever reason. This is like still being on WinXP. WE all know there are folks out there on WinXP, because they have software that will only ruin with it. That is not a thing regarding PS. Also, you loose any ability to audit / monitor / control it's use by internals and externals.
I can only assume, you are calling PS from VBS because you want to be able to double click to start the script. This is still not prudent either. PS is designed to prevent this double-click (hence the reason by default it's associated with notepad or VSCode if it is installed) to run thing due to risks associated with double-click to ruin things.
If you are unconcerned with this type of risks (but you should be), then you can just associate .PS1 files with powershell.exe (using Windows Explorer or the like), and double clicking will work. Though I would not advise it from a operational perspective.
The topic ‘Appending a script after powershell is launched?’ is closed to new replies.