Skip to content
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

[Bug]: Monkey365 causes exception when SharePoint url is not detected #107

Closed
olivierdumon opened this issue Jul 17, 2024 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@olivierdumon
Copy link

What happened?
Error message when attempting a sharepoint online message

How to reproduce it

  1. What command are you running?
    Invoke-Monkey365 -Instance Microsoft365 -Analysis ExchangeOnline -ExportTo HTML -Compress
    or
    Invoke-Monkey365 -Instance Microsoft365 -Analysis ExchangeOnline -ExportTo HTML -Compress -DeviceCode:$true

  2. See error
    Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:182
    Line |
    182 | … 365Object.auth_tokens.SharePointOnline = Connect-MonkeySPO @p -RootSi …
    | ~~
    | Cannot bind argument to parameter 'Endpoint' because it is an empty string.
    Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:184
    Line |
    184 | … bject.auth_tokens.SharePointAdminOnline = Connect-MonkeySPO @p -Admin
    | ~~
    | Cannot bind argument to parameter 'Endpoint' because it is an empty string.
    Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:186
    Line |
    186 | … $O365Object.auth_tokens.OneDrive = Connect-MonkeySPO @p -OneDri …
    | ~~
    | Cannot bind argument to parameter 'Endpoint' because it is an empty string.

Expected behavior
Normal report creation as with other modules

Screenshots or Logs
VERBOSE: Loading module from path 'C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psd1'.
VERBOSE: Removing the imported "New-MonkeyMSALApplicationClientOptions" function.
VERBOSE: Removing the imported "New-MonkeyMsalApplication" function.
VERBOSE: Removing the imported "Get-MonkeyMSALToken" function.
VERBOSE: Removing the imported "Convert-SecureStringToPlainText" function.
VERBOSE: Loading module from path 'C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psm1'.
VERBOSE: [09:15:48:294] - [monkeymsal.psm1] - Windows OS detected. Loading MSAL Core - verbose - xxxxxx -
VERBOSE: Exporting function 'Get-CoreLib'.
VERBOSE: Exporting function 'Get-DeskLibForCore'.
VERBOSE: Exporting function 'Get-DesktopLib'.
VERBOSE: Exporting function 'Install-MsalLibrary'.
VERBOSE: Exporting function 'Convert-SecureStringToPlainText'.
VERBOSE: Exporting function 'Get-LocalizedData'.
VERBOSE: Exporting function 'Get-OsInfo'.
VERBOSE: Exporting function 'New-MonkeyMSALApplicationClientOptions'.
VERBOSE: Exporting function 'Get-MonkeyMSALToken'.
VERBOSE: Exporting function 'New-MonkeyMsalApplication'.
VERBOSE: Importing function 'Convert-SecureStringToPlainText'.
VERBOSE: Importing function 'Get-MonkeyMSALToken'.
VERBOSE: Importing function 'New-MonkeyMsalApplication'.
VERBOSE: Importing function 'New-MonkeyMSALApplicationClientOptions'.
VERBOSE: [09:15:55:846] - [Get-MonkeyMSGraphObject] - Getting organization from microsoft graph - verbose - xxxxxxx -
VERBOSE: [09:15:59:249] - [Get-TenantInformation] - Getting tenant information from xxxxxxxxxxxxxx Id - verbose - xxxxxx - AADTenantInfo
VERBOSE: [09:15:59:940] - [Get-MonkeyMSGraphObject] - Getting organization from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:00:666] - [Get-MonkeyMSGraphObject] - Getting subscribedSkus from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:01:241] - [Get-MonkeyMSGraphObject] - Getting domains from microsoft graph - verbose - xxxxxx -
Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:182
Line |
182 | … 365Object.auth_tokens.SharePointOnline = Connect-MonkeySPO @p -RootSi …
| ~~
| Cannot bind argument to parameter 'Endpoint' because it is an empty string.
Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:184
Line |
184 | … bject.auth_tokens.SharePointAdminOnline = Connect-MonkeySPO @p -Admin
| ~~
| Cannot bind argument to parameter 'Endpoint' because it is an empty string.
Connect-MonkeySPO: C:\temp\monkey365\core\api\auth\microsoft365\Connect-MonkeyM365.ps1:186
Line |
186 | … $O365Object.auth_tokens.OneDrive = Connect-MonkeySPO @p -OneDri …
| ~~
| Cannot bind argument to parameter 'Endpoint' because it is an empty string.
VERBOSE: [09:16:01:747] - [Get-MonkeyMSGraphUserDirectoryRole] - Getting user's information from xxxxxx - verbose - xxxxxx - AzureGraphDirectoryRoleByUserId
VERBOSE: [09:16:02:317] - [Get-MonkeyMSGraphObject] - Getting users/xxxxxx/transitiveMemberOf from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:02:893] - [Get-MonkeyMSGraphObject] - Getting users from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:03:647] - [Get-MonkeyMSGraphObject] - Getting groups from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:04:216] - [Get-MonkeyMSGraphObject] - Getting me from microsoft graph - verbose - xxxxxx -
VERBOSE: [09:16:04:773] - [Stop-Logger] - Stopping logger - verbose - xxxxxx -

From where are you running Monkey365?
Please, complete the following information:

  • Resource: workstation
  • OS: Windows
  • PowerShell Version : Core 7.4.2
  • Monkey365 Version: latest 0.91.3
  • Others:

Additional context
Add any other context about the problem here.
image

@olivierdumon olivierdumon added bug Something isn't working status/needs-triage Needs triage labels Jul 17, 2024
@silverhack
Copy link
Owner

silverhack commented Jul 17, 2024

Hey @olivierdumon, thanks for submitting this!

Seems that monkey365 is unable to get information from Microsoft Graph regarding available domains for SharePoint.

As a workaround, could you please include the -ScanSites param?

Invoke-Monkey365 -Instance Microsoft365 -Analysis SharePointOnline `
                 -ScanSites https://**yourdomain**.sharepoint.com `
                 -DeviceCode -Verbose -Debug `
                 -InformationAction Continue -Compress

Additionaly, and due that your main OS is Windows and PowerShell core, you can also force monkey365 to load MSAL libraries for Windows desktop and omit the DeviceCode, as shown below:

Invoke-Monkey365 -Instance Microsoft365 -Analysis SharePointOnline `
                 -ScanSites https://**yourdomain**.sharepoint.com `
                 -Verbose -Debug `
                 -InformationAction Continue -Compress -ForceMSALDesktop

Could you please try and do let me know?
Cheers,

@olivierdumon
Copy link
Author

olivierdumon commented Jul 18, 2024

Hi @silverhack
That's seems to be much better with the '-ScanSites' parameter
The report generation is OK
Many thanks !

Any idea on what's causing this behaviour ?
(For information, I've the same problem with 2 another tenants)

Good day

@olivierdumon
Copy link
Author

And for information here is the result of the command with the '-ForceMSALDesktop' parameter.
It seems that I have another problem !! 😅

CONSOLE: [13:25:08:254] - [New-Logger] - Initializing loggers - info - XXXXXX - MonkeyLog
CONSOLE: [13:25:08:270] - [Initialize-File] - Log file monkey365_exceptions_20240718052508.log created successfully on C:\Temp\MONKEY365 - info - XXXXXX - MonkeyLog
CONSOLE: [13:25:08:284] - [New-Logger] - Log enabled - info - XXXXXX - MonkeyLog
CONSOLE: [13:25:08:299] - [Invoke-Monkey365] - Importing MSAL authentication library - info - XXXXXX - Monkey365LoadMSAL
VERBOSE: Loading module from path 'C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psd1'.
VERBOSE: Removing the imported "New-MonkeyMSALApplicationClientOptions" function.
VERBOSE: Removing the imported "New-MonkeyMsalApplication" function.
VERBOSE: Removing the imported "Get-MonkeyMSALToken" function.
VERBOSE: Removing the imported "Convert-SecureStringToPlainText" function.
VERBOSE: Loading module from path 'C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psm1'.
Write-Error: [13:25:08:794] - [Install-MsalLibrary] - Assembly with same name is already loaded. LineNumber: At C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psm1:81 char:9 + Add-Type @params | Out-Null +

Exception: C:\temp\monkey365\Invoke-Monkey365.ps1:439
Line |
 439 |          Import-Module $MSAL -Scope Global -Force -ArgumentList $O365O …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to load MSAL library
Get-Command: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:44
Line |
  44 |  … tion.CommandMetaData" (Get-Command -Name "New-MonkeyMsalApplication")
     |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term 'New-MonkeyMsalApplication' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the
     | path is correct and try again.
New-Object: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:44
Line |
  44 |  … pMetadata = New-Object -TypeName "System.Management.Automation.Comman …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | A constructor was not found. Cannot find an appropriate constructor for type System.Management.Automation.CommandMetaData.
PropertyNotFoundException: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:47
Line |
  47 |          $param = $msalAppMetadata.Parameters.Keys
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'Parameters' cannot be found on this object. Verify that the property exists.
InvalidOperation: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:48
Line |
  48 |          foreach($p in $param.GetEnumerator()){
     |                        ~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
New-MonkeyMsalApplication: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:64
Line |
  64 |  …       $O365Object.msalapplication = New-MonkeyMsalApplication @app_pa …
     |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term 'New-MonkeyMsalApplication' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the
     | path is correct and try again.
PropertyNotFoundException: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:65
Line |
  65 |              $O365Object.isConfidentialApp = -NOT $O365Object.msalappl …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'isPublicApp' cannot be found on this object. Verify that the property exists.
Get-Command: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:67
Line |
  67 |  … Automation.CommandMetaData" (Get-Command -Name "Get-MonkeyMSALToken")
     |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term 'Get-MonkeyMSALToken' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is
     | correct and try again.
New-Object: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:67
Line |
  67 |  … pMetadata = New-Object -TypeName "System.Management.Automation.Comman …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | A constructor was not found. Cannot find an appropriate constructor for type System.Management.Automation.CommandMetaData.
PropertyNotFoundException: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:70
Line |
  70 |              $param = $msalAppMetadata.Parameters.Keys
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'Parameters' cannot be found on this object. Verify that the property exists.
InvalidOperation: C:\temp\monkey365\core\init\Initialize-AuthenticationParam.ps1:71
Line |
  71 |              foreach($p in $param.GetEnumerator()){
     |                            ~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
Get-MSALTokenForGraphV2: C:\temp\monkey365\core\api\auth\msgraph\Connect-MonkeyMSGraph.ps1:40
Line |
  40 |          Get-MSALTokenForGraphV2 @p
     |                                  ~~
     | Cannot bind argument to parameter 'PublicApp' because it is null.
CONSOLE: [13:25:09:231] - [Invoke-Monkey365] - Total time for JOBs: 0,02 Minutes - info - XXXXXX - Monkey365FinishedJobs
VERBOSE: [13:25:09:322] - [Stop-Logger] - Stopping logger - verbose - XXXXXX -
CONSOLE: [13:25:09:326] - [New-Logger] - Stopping loggers - info - XXXXXX - MonkeyLog
CONSOLE: [13:25:09:366] - [New-Logger] - Logger stopped - info - XXXXXX - MonkeyLog

@silverhack
Copy link
Owner

Hey @olivierdumon,

This happens because you have tried to reload net libraries within the same session. You can see that in logs:

Write-Error: [13:25:08:794] - [Install-MsalLibrary] - Assembly with same name is already loaded. LineNumber: At C:\temp\monkey365\core\modules\monkeymsal\monkeymsal.psm1:81 char:9 + Add-Type @params | Out-Null +

This is by design in PowerShell, so the solution would be to start a new PowerShell session

@silverhack
Copy link
Owner

Hi @silverhack

That's seems to be much better with the '-ScanSites' parameter

The report generation is OK

Many thanks !

Any idea on what's causing this behaviour ?

(For information, I've the same problem with 2 another tenants)

Good day

An regarding domains, I believe that SharePoint domain is not tied to the root tenant. Monkey365 will try to find the SharePoint root url by appending the sharepoint.com dns suffix to the tenant name.

@silverhack silverhack changed the title [Bug]: Error Message "Cannot bind argument to parameter 'Endpoint' because it is an empty string" with Sharepoint Online Report [Bug]: Monkey365 causes exception when SharePoint url is not detected Jul 18, 2024
@silverhack silverhack removed the status/needs-triage Needs triage label Jul 18, 2024
@olivierdumon
Copy link
Author

OK, I note your answers.
thanks again for your availability

Good day

@silverhack
Copy link
Owner

My pleasure.

You too

@silverhack
Copy link
Owner

Hi,

Closing this as already implemented in main branch.

Thanks for using Monkey365!
Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants