SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
234 stars 66 forks source link

Exception Calling .CTOR with "3" arguments(s) "Cannot find the requested object" #268

Closed aktzdv closed 4 years ago

aktzdv commented 4 years ago

Describe the bug All commands always fail with the following error

PS C:\Windows\system32> Get-GSGmailProfile -Verbose VERBOSE: Building ServiceAccountCredential from P12Key as user 'redacted@redacted.com' Get-GSGmailProfile : Exception calling ".ctor" with "3" argument(s): "Cannot find the requested obj " At line:1 char:1

To Reproduce Steps to reproduce the behavior:

  1. Import-Module PSGSuite
  2. Type any command

Expected behavior For command to complete executing appears to be failing on new-googleservice

Screenshots PS C:\Windows\system32> Show-PSGSuiteConfig

ConfigName : Default P12KeyPath : C:\scripts\psgsuite\psgsuite.p12 P12Key : {1} P12KeyPassword : P12KeyObject : ClientSecretsPath : ClientSecrets : AppEmail : redacted@gam-project-redacted.iam.gserviceaccount.com AdminEmail : redacted@domain.com
CustomerID : redacted Domain : redacted.com
Preference : CustomerID ServiceAccountClientID : redacted Chat : {Webhooks, Spaces} ConfigPath : C:\Users\redacted\AppData\Local\powershell\SCRT HQ\PSGSuite\Configuration.psd1

PS C:\Windows\system32> Get-GSGmailProfile -Verbose VERBOSE: Building ServiceAccountCredential from P12Key as user 'redacted@redacted.com' Get-GSGmailProfile : Exception calling ".ctor" with "3" argument(s): "Cannot find the requested obj " At line:1 char:1

Environment (please complete the following information):

Additional context Attempted the processs on two different OS's with 2 different accounts both admininstrator and non-administrator.

scrthq commented 4 years ago

@aktzdv Can you please make sure you are explicitly importing the module first?

  1. Start a new PowerShell session
  2. Run this:
Import-Module PSGSuite
Get-GSGmailProfile -Verbose
aktzdv commented 4 years ago

Thank you for assisting.

Here are the results

Import-Module PSGSuite get-GSGMailProfile -verbose (or any other command)

VERBOSE: Building ServiceAccountCredential from P12Key as user 'redacted@redacted.com' get-GSGmailProfile : Exception calling ".ctor" with "3" argument(s): "Cannot find the requested object. " At line:1 char:1

scrthq commented 4 years ago

Let's try this after you get that error:

[System.AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object {$_.Location -match '(Google|BouncyCastle|MimeKit)'} |
ForEach-Object {
    [PSCustomObject]@{
        Path = $_.Location -replace [RegEx]::Escape((Resolve-Path ~).Path),'~'
        Version = (Get-Item $_.Location).VersionInfo.FileVersion
    }
}

Should output something like this:

Path                                                                                                           Version
----                                                                                                           -------
~\Documents\PowerShell\Modules\PSChef\0.4.2\lib\BouncyCastle.Crypto.dll                                        1.8.6.1
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\MimeKit.dll                                  1.10.1.0
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.dll                              1.44.0.0
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Admin.Directory.directory_v1.dll 1.44.0.1736
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Admin.Reports.reports_v1.dll     1.44.0.1747
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Auth.dll                         1.44.0.0
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Auth.PlatformServices.dll        1.44.0.0
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Calendar.v3.dll                  1.44.0.1879
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Classroom.v1.dll                 1.44.0.1881
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Core.dll                         1.44.0.0
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Docs.v1.dll                      1.44.0.1877
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Drive.v3.dll                     1.44.0.1874
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Gmail.v1.dll                     1.44.0.1859
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Groupssettings.v1.dll            1.44.0.1666
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.HangoutsChat.v1.dll              1.44.0.1875
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Licensing.v1.dll                 1.44.0.1719
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Oauth2.v2.dll                    1.44.0.1869
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.PeopleService.v1.dll             1.44.0.1883
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Script.v1.dll                    1.44.0.1882
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Sheets.v4.dll                    1.44.0.1877
~\Documents\PowerShell\Modules\PSGSuite\2.36.2\lib\netstandard1.3\Google.Apis.Slides.v1.dll                    1.44.0.1875
scrthq commented 4 years ago

@aktzdv for the value for (Show-PSGSuiteConfig).P12Key, is that literally only one byte or did you redact the rest but it's actually full? It should be a byte array

If it is, try running the following to correct it:

Set-PSGSuiteConfig -P12KeyPath (Show-PSGSuiteConfig).P12KeyPath
aktzdv commented 4 years ago

Hi @scrthq thanks for the assist. Here is the output of the first command

Path                                                                                                              Version
----                                                                                                              -------
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\BouncyCastle.Crypto.dll                      1.8.15362.1
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\MimeKit.dll                                  1.10.1.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.dll                              1.44.0.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Core.dll                         1.44.0.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Admin.Directory.directory_v1.dll 1.44.0.1736
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Admin.Reports.reports_v1.dll     1.44.0.1747
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Auth.dll                         1.44.0.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Auth.PlatformServices.dll        1.44.0.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Calendar.v3.dll                  1.44.0.1879
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Classroom.v1.dll                 1.44.0.1881
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Docs.v1.dll                      1.44.0.1877
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Drive.v3.dll                     1.44.0.1874
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Gmail.v1.dll                     1.44.0.1859
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Groupssettings.v1.dll            1.44.0.1666
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.HangoutsChat.v1.dll              1.44.0.1875
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Licensing.v1.dll                 1.44.0.1719
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Oauth2.v2.dll                    1.44.0.1869
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.PeopleService.v1.dll             1.44.0.1883
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.PlatformServices.dll             1.44.0.0
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Script.v1.dll                    1.44.0.1882
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Sheets.v4.dll                    1.44.0.1877
C:\Program Files\WindowsPowerShell\Modules\PSGSuite\2.36.2\lib\net45\Google.Apis.Slides.v1.dll                    1.44.0.1875

It also looked like the Set-PSGSuiteConfig -P12KeyPath (Show-PSGSuiteConfig).P12KeyPath actually put in the correct values. I had not redacted them. They were just not there. Even though I had set them in the config.

I'll let you know.

scrthq commented 4 years ago

got it! so definitely sounds like a broken section for the P12Key then, which would cause issues when trying to build the service where your error was being thrown. Try the commands out now that you've updated and let me know!

scrthq commented 4 years ago

hey @aktzdv - Checking in --- let me know if you're still having an issue with this!