Task PowerShell script - How to use PowerShell 7.x

I have a task that runs a cmdlet that requires PowerShell 7. Tasks that have the type PowerShell Script default to Windows PowerShell 5.x. How do I get Morpheus to use PowerShell 7 instead?

The PowerShell task calls PowerShell.exe (version 5).

Unfortunately, I’m not aware of any method to alter this. However, it might be beneficial to suggest this as an idea for improvement! Feel free to share your idea here. Ideas - Morpheus

One way around this might be to use a file template to place the script onto the VM and start the process from PS 5 using Start-Process.

Start-Process -FilePath “pwsh.exe” -ArgumentList “-File .\PowerShellScript.ps1” -Wait

There could be a better approach out there, this is just what initially came to mind

Thanks for the quick reply, I’ll give that a go.

you could look to wrap your powershell script like this in the Morpheus powershell task

pwsh -c {$PSVersionTable}

Also I think this would be a great idea for you to raise in our ideas section. I think there should be a selection on the powershell task to run windows powershell either under powershell.exe or pwsh

1 Like

Thank you both. I was able to workaround my issue by using pwsh.exe -c parameter. I have submitted an idea as suggested. :slightly_smiling_face:

1 Like