Powershell Console fails to load modules

This forum is for Office365 for LabTech (Ver 2) support. When posting remember to include screenshots of any relevant information.
Post Reply
User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

Powershell Console fails to load modules

Post by Cubert »

Receiving errors when launching POSH shell from plugin.

Copyright (C) Microsoft Corporation. All rights reserved.

Opening up a connection to Office365
import-module : Could not load file or assembly 'file:///C:\Program
Files\WindowsPowerShell\Modules\MSOnline\1.1.183.57\Microsoft.Online.Administration.Automation.PSModule.dll' or one of
its dependencies. An attempt was made to load a program with an incorrect format.
At C:\temp\Office365\Office365_Plugin.ps1:26 char:1
+ import-module MSOnline
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], BadImageFormatException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Importing modules from Office365
Connect-Msolservice : The 'Connect-Msolservice' command was found in the module 'MSOnline', but the module could not
be loaded. For more information, run 'Import-Module MSOnline'.
At C:\temp\Office365\Office365_Plugin.ps1:36 char:2
+ Connect-Msolservice -cred $cred -ea silentlyContinue -WarningActi ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-Msolservice:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Importing modules from Sharepoint
Connect-SPOService : Cannot contact web site 'https://dibtec-admin.sharepoint.com/' or the web site does not support
SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are
'X-SharePointHealthScore=2, X-MSDAVEXT_Error=917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+f
irst+browse+to+the+web+site+and+select+the+option+to+login+automatically.,
SPRequestGuid=af2ded9f-d097-1000-14ec-6e68101e869b, request-id=af2ded9f-d097-1000-14ec-6e68101e869b,
MS-CV=n+0tr5fQABAU7G5oEB6Gmw.0, Strict-Transport-Security=max-age=31536000, SPRequestDuration=27, SPIisLatency=0,
MicrosoftSharePointTeamServices=16.0.0.21625, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly,
X-Cache=CONFIG_NOCACHE, X-MSEdge-Ref=Ref A: 70841630C9814928B648DFB025F4FEFC Ref B: BLUEDGE1309 Ref C:
2021-09-07T14:34:02Z, Content-Length=0, Content-Type=text/plain; charset=utf-8, Date=Tue, 07 Sep 2021 14:34:02 GMT,
P3P=CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI",
X-Powered-By=ASP.NET'.
At C:\temp\Office365\Office365_Plugin.ps1:43 char:3
+ Connect-SPOService -Url $SharePointURL -credential $credentia ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService

User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

Re: Powershell Console fails to load modules

Post by Cubert »

Looking at updating the modules loaded.

It’s the same issue when multifactor was introduced. Scripts stop working unless you moved to the new module. When using the installer you used even using the msonline module its reverting to basic authentication its easy to tell based on the login prompt. One is the basic old login

User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

Re: Powershell Console fails to load modules

Post by Cubert »

After a review of the code base I am electing to do a wide variety of updates to this program. I will post in the office365 forum updates on progress and any test releases we push out for those who may want to play with the functions.

We are starting on this now so should see some results over the next week or so.

User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

Re: Powershell Console fails to load modules

Post by Cubert »

Good News,

We figured out the Powershell console launching issues and have fixed it.

The issues came down to the Automate console (a 32 bit application) trying to launch a native 64bit powershell console.

Even though we called "${env:windir}\System32" in a 64 bit environment PowerShell would redirect down to a 32 bit shell causing the modules to fail to load.

To correct this we updated the script in several ways.
  • #1 Added in support to define Powershell Version must be 3 or higher
  • #2 Added SSL error and TLS 1.1, 1.2, 1.3 handling
  • #3 Added Environment test and redirection to 64bit console in 32 bit environment.
  • #4 Added MSOnline module test and auto install from NuGet is missing.

What we get from these updates is a functional 64 bit shell launched from a 32 bit application. Problem resolved!
Capture.PNG
Capture.PNG (35.56 KiB) Viewed 5785 times

This and many more updates due out in a short bit. We are taking the time to fully update the collection process across the plugin.

Post Reply

Return to “Office365 for LabTech”