Mar 21 2023 10:16 AM
Hello,
I try to run a runbook in Hybrid Worker to collect info from Azure Registered Apps. For that activity I connect to MS Graph with certificate and execute Get-MgApplication cmdlet. However, I see "Welcome to Microsoft Graph!" response and then:
Get-MgApplication : Method not found: 'Void Microsoft.Graph.TokenCredentialAuthProvider..ctor(Azure.Core.TokenCredential, System.Collections.Generic.IEnumerable`1<System.String>)'. At line:24 char:1 + $SApps = Get-MgApplication -all + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-MgApplication_List], MissingMethodException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgApplication_List
My current version module is 2.0.0-preview5, but I also tried other versions and got different results (but never successful). All cmdlets, including connecting via certificate, can be executed successfully locally and within Azure runbook.
I run out of ideas. Any ideas?
Mar 21 2023 07:34 PM - edited Mar 21 2023 11:10 PM
I'd only expect to see that kind of error under the following conditions:
I'm inclined to think it'll be the second case, in which case you can run the following script to remove all currently-installed versions (this is based on Windows PowerShell, not PowerShell) and re-install them (see the note in the comments about scope):
I don't use beta/pre-release versions and I am aware they sometimes need manual eviction. I haven't catered to this scenario in the script below.
<#
Local administration rights are required for the "-Scope AllUsers" option to work. Otherwise, remove that option from the commandlets to do a per user refresh.
#>
try
{
$Scope = "AllUsers";
# Enumerate the currently-installed modules from the AllUsers scope.
$Modules = (Get-Module -ListAvailable -Name "Microsoft.Graph.*" -ErrorAction:Stop).Name | Select-Object -Unique;
# Output the list to the pipeline as a "just in case".
Write-Warning -Message "Modules detected:";
$Modules;
# Now, chuck 'em all in the bin.
$Modules |
ForEach-Object {
Uninstall-Module -Name $_ -AllVersions -Force -ErrorAction:Stop;
}
# The authentication module is a prerequisite for all the other Graph modules (which throw a warning on installation if this one isn't already present), hence breaking it out to be first to be re-installed.
Install-Module -Name "Microsoft.Graph.Authentication" -Scope $Scope -Force -ErrorAction:Stop;
# Re-install the rest, excluding the authentication module from above.
$Modules |
ForEach-Object {
if ($_ -ne "Microsoft.Graph.Authentication")
{
Install-Module -Name $_ -Scope $Scope -Force -ErrorAction:Stop;
}
}
}
catch
{
throw;
}
Cheers,
Lain
Mar 22 2023 12:36 AM
Mar 22 2023 03:20 AM - edited Mar 22 2023 07:30 AM
@LainRobertson @VasilMichev
Alright. I wiped out module repository and reinstalled all modules (MSGraph 1.23), including Azure.Core.dll which is a part of Az.Accounts (2.12.1). That didn't help and I started getting "Connect-MgGraph : <ThumbprintId> certificate was not found or has expired".
Then I tried to import a certificate using Runbook into CurrentUser with "Import-PfxCertificate
Locally and from Runbook all working well. I just run out of ideas what else could be wrong.
Mar 22 2023 07:49 AM
I'd expect this to be about the placement of the certificate - as per the other thread.
As I mentioned there, I don't use the hybrid runbook server meaning I can't perform a like-for-like test, but I'm not having any issues with certificate-based authentication under version 1.23.0.
It tested successfully for me - using an Azure servicePrincipal - both from the certificate store as well as from file, but keep in mind (as per the link in the other thread) that the hybrid runbook documentation specifies a more unique location than the CurrentUser\My or LocalMachine\My stores, so it's got some of its own peculiarities to navigate.
I'd suggest running your own test outside of the runbook scenario as a cross-reference. If that works - and I'd wager it will - then at least that'll be fairly solid evidence (as much as anything ever is) it's not the Graph PowerShell modules.
Cheers,
Lain
Jul 13 2023 04:08 AM
Hey, still i am getting the same error . Please can you help@Alex_Rechs
Jul 14 2023 03:19 AM - edited Jul 14 2023 03:19 AM
Eventually I installed Microsoft Graph version 1.24.0 on Hybrid Worker machine
I remember I installed that certificate under system account and Hybrid Worker account, but I don't recall what worked and at this point I'm afraid to touch it 🙂
The way I connect to Graph is:
Connect-MgGraph -CertificateThumbprint "<certThumbprint>" -ClientID "<clientID>" -TenantID "<tenantID>"
Select-MgProfile -name Beta
I hope that helps.