ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
35 stars 2 forks source link

[5.0.0] Cannot execute script in PowerShell 5 environment #3596

Closed mwatts-seg closed 3 weeks ago

mwatts-seg commented 3 weeks ago

Summary of the feedback

When I try to execute a script in PS 5 environment, I get this error:

image

I am able to successfully run in the integrated environment. However, this particular script does not work well with PowerShell 7. I did try to manually discover the environments and used the one discovered, but same results.

I also found a forum post, where someone else had this in an earlier version: https://forums.ironmansoftware.com/t/large-amount-of-job-errors-post-3-7-4-upgrade/8469/3

I tried what was suggested: image

image

adamdriscoll commented 3 weeks ago

This is actually expected. PSUv5 won't run in the standard Windows PowerShell executable. We have a .NET 4.8 executable that hosts the WinPS binaries to prevent this. More details will be in our release notes. We need a better error message.

https://docs.powershelluniversal.com/v/v5/getting-started/upgrading#powershell.exe-is-no-longer-used

mwatts-seg commented 3 weeks ago

This is actually expected. PSUv5 won't run in the standard Windows PowerShell executable. We have a .NET 4.8 executable that hosts the WinPS binaries to prevent this. More details will be in our release notes. We need a better error message.

https://docs.powershelluniversal.com/v/v5/getting-started/upgrading#powershell.exe-is-no-longer-used

@adamdriscoll Sorry! I didn't read and that's my fault.

Does that mean we will not be able to execute scripts that are heavily geared towards PowerShell 5? Our organization has tried using PowerShell 7 in the past, but there were issues with some cmdlets, tied with the time constraints of our team with trying to rewrite the scripts.

Does the Integrated environment use the service account to execute the PowerShell process? I tried to run our Azure AD & O365 Photo Sync script, and it had issues access network resources, which makes me think it is trying to use the System account versus the service account.

adamdriscoll commented 3 weeks ago

You'll be able to execute PS5.1 scripts as expected. We still using the local PS5.1 assemblies to execute everything. It's just that we use a different host process so we can control the assembly loading. You shouldn't notice a difference except modules loading more consistently.

mwatts-seg commented 3 weeks ago

You'll be able to execute PS5.1 scripts as expected. We still using the local PS5.1 assemblies to execute everything. It's just that we use a different host process so we can control the assembly loading. You shouldn't notice a difference except modules loading more consistently.

Ah, okay. That makes sense. I tried running 'PowerShell 5.0' without executable defined, as this is how it was when I set it up, It goes to failed right away. If I tried to run it via Integrated environment, it looks to run as SYSTEM context because it has no access outside the box. image

image

adamdriscoll commented 3 weeks ago

Integrated runs as whatever the service is configured. If you don't have a Windows PowerShell 5.1 environment, try adding that and executing it.

mwatts-seg commented 3 weeks ago

Integrated runs as whatever the service is configured. If you don't have a Windows PowerShell 5.1 environment, try adding that and executing it.

Ah okay. I figured out why integrated would not work. Read the part where credentials would not work with integrated, which makes sense. The account does not have authority to do what I want. :) Still trying to work on getting PS5 working.

adamdriscoll commented 3 weeks ago

I've improved the Windows PowerShell 5.1 discovery and added better reporting to address this.