Windows PowerShell Compatiblity is enabled. We recommend disabling this feature of PowerShell when using PowerShell Universal

So when I’m entering Environment in the Admin page I do see the following banner:
Windows PowerShell Compatiblity is enabled. We recommend disabling this feature of PowerShell when using PowerShell Universal.

But I can’t figure out how to disable it? I have read the MS article about it but I still don’t get it.
Can anyone give me help with this? some kind of instructions?

1 Like

We’ll be updating the link from the product to here: https://docs.powershelluniversal.com/config/environments#windows-powershell-compatiblity

I think our detection isn’t working properly since I was on a call yesterday where the customer had done this and PSU was still stating it was enabled.

@adam is it still “safe” (as in, not a performance hit as time goes on) to use -UseWindowsPowerShell for relevant scripts tied to a PowerShell v7 environment? Or is your recommendation to only use Windows PowerShell (< v5.1) for such work? For example the AD module you reference in the article above.

I’m running almost everything in PS7 and it’s adapted for it. But some scripts I need to use PS5.1 for then I just call them from PS7 but they will run in an environment with PS5.1.
Easy peasy :slight_smile:

Sure, I’m doing the same, but my question is whether disabling WidnowsCompat and instead using v7 and -UseWindowsPowerShell effectively results in the same result as leaving Windows Compatibility enabled (additional processes, slower performance, etc.).

I would be careful with it. It would have the same effect as the implicit app compat as it will open an external process that will stay open for the duration of the runspace. I’m not sure what would happen if you were to call Remove-Module after using it. It may stop that external process and then at least you could manage the state a lot more closely.

This actually works. It loads the module using WinPS (which starts a powershell.exe process), executes the Get-ScheduledJob command and then you can remove the session at the end and it stops the process.

New-UDDashboard -Content {
    Import-Module PSScheduledJob -UseWindowsPowerShell
    Get-ScheduledJob | Out-Null
    Get-PSSession -Name 'WinPSCompatSession' | Remove-PSSession
}

I’ll have to think about this but we may be able to just bake this into PSU so users don’t need to worry about cleaning up sessions.

Not sure if this gives you anything else to think about, but I’ve anecdotally used the code below…

$newPwd = Invoke-Command -ScriptBlock { Powershell.exe -Command "Add-Type -AssemblyName 'System.Web' ; [System.Web.Security.Membership]::GeneratePassword(13,1)" }

Some very basic testing leans to Invoke-Command being faster…

Measure-Command -Expression { Import-Module Activedirectory -UseWindowsPowerShell; get-aduser -Identity $user ; Get-PSSession -Name 'WinPSCompatSession' | Remove-PSSession}
Measure-Command -Expression { Invoke-command -ScriptBlock { Powershell.exe -Command "Import-Module Activedirectory ; get-aduser -Identity $user" } }