-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another PS7 Error? Could not load type 'System.Management.Automation.PSSnapIn' from assembly #3568
Comments
Let me start by answering once again then:-) As you probably know by now, all cmdlets in BC24 and above are PS7 with a bridge between PS5.1 and PS7. If you have your own scripts, you will need to do the same (or run PS5.1 always by setting I cannot do magic - SQLPS doesn't exist in PS7 - only the SqlServer module, and that isn't compatible. I have installed the SqlServer module in PS7 by default and added some aliases to get some common scripts to run. So,... - you are on your own here - if you run PS5.1 - your scripts probably works. If you want to run PS7 for performance - you need to modify your scripts to make them run. Sorry - but this is the best I can do. |
I am always open for good ideas, which can make life easier for everybody - feel free to suggest stuff - but not to make me load SQLPS on PS7 - that cannot be done. |
It can be done. But you must use PowerShell remoting to accomplish that ( This is bad: PS C:\Users\ernjus> Invoke-ScriptInBcContainer -containerName $ContainerName -scriptblock { Import-Module -Name SQLPS; Invoke-Sqlcmd -ServerInstance 'docker.softera.lt' -Query 'SELECT 1' -Username 'containeruser' -Password 'Password1.' }
Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.4.2.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Container Free Physical Memory: 13.3Gb
Disk C: Free 124Gb from 127Gb
Services in container bc123:
Exception: C:\Users\ernjus\OneDrive - Softera Baltic UAB\Documents\PowerShell\Modules\BcContainerHelper\6.0.18\ContainerHandling\Invoke-ScriptInNavContainer.ps1:301
Line |
301 | throw $errorMessage
| ~~~~~~~~~~~~~~~~~~~
| Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.4.2.500, Culture=neutral,
| PublicKeyToken=31bf3856ad364e35'. This is ok: PS C:\Users\ernjus> Invoke-ScriptInBcContainer -containerName $ContainerName -scriptblock { Import-Module -Name SQLPS -UseWindowsPowerShell; Invoke-Sqlcmd -
ServerInstance 'docker.softera.lt' -Query 'SELECT 1' -Username 'containeruser' -Password 'Password1.' }
RunspaceId Column1
---------- -------
0b40cdc5-eb64-474c-b386-a40b131e43f6 1 The main downside is performance hit because PowerShell needs a few seconds to create PowerShell 5 session and load the module there. Also, once you load the module, you don't need to call The slowness seems to be caused the way Invoke-ScriptInBcContainer works - if I import module and run query inside the container everything works nearly instantly. Maybe new parameter should be added to Invoke-ScriptInBcContainer to skip loading of BC modules or only load them once per PS session. |
There is nothing forcing you to use Invoke-ScriptInBcContainer. I decided against the -useWindowsPowershell mostly because it sounds like a giant hack - but maybe it isn't. Problem for me was that it took most of 4-6 weeks. |
Here we go again.
With reference to issue #3527, the same script is now failing when using BC v24.1 and BCCH 6.0.18. Building the container works fine, it fails when I'm using Invoce-ScriptInBcContainer, where I'm trying to Import-Module SQLPS.
Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.4.2.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Same scripts works fine for v23 and earlier. I can also see the same error reported in issue #3541.
Based on the version (7.4.2.500) I assume it has something to do with the PowerShell version?
So, let me start by asking once again. When should we be using PowerShell 5 vs 7?
When should we be specifying PWSH when invoking scripts in the container, and when not?
The text was updated successfully, but these errors were encountered: