Azure Function App using certificate authentication falls to authenticate when executing Connect-MgGraph

I was recently contacted by someone to inform me that the Function App I provided in my previous post written on July 25, 2022:

Create an automated report for Office 365 / Microsoft 365 license usage with friendly names using Azure a Function App and Logic Apps
https://blog.terenceluk.com/2022/07/create-automated-report-for-office-365.html

… no longer worked so I had a look at the Function App and confirmed that it would fail with the following error message:

2022-09-05T10:29:27Z [Error] ERROR: Could not load file or assembly ‘Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’. The system cannot find the file specified.

 

Exception :

Type : System.IO.FileNotFoundException

Message : Could not load file or assembly ‘Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’. The system cannot find the file specified.

FileName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

TargetSite :

Name : MoveNext

DeclaringType : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph+<ProcessRecordAsync>d__56, Microsoft.Graph.Authentication, Version=1.11.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

MemberType : Method

Module : Microsoft.Graph.Authentication.dll

StackTrace :

at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()

Source : Microsoft.Graph.Authentication

HResult : -2147024894

CategoryInfo : NotSpecified: (:) [Connect-MgGraph], FileNotFoundException

FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph

InvocationInfo :

MyCommand : Connect-MgGraph

ScriptLineNumber : 85

OffsetInLine : 1

HistoryId : 1

ScriptName : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

Line : Connect-MgGraph -ClientID $appId -TenantId $tenantID -CertificateThumbprint $thumb ## Or -CertificateName “M365-License”

 

PositionMessage : At C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1:85 char:1

+ Connect-MgGraph -ClientID $appId -TenantId $tenantID -CertificateThum …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PSScriptRoot : C:homesitewwwrootHttpTrigger-Get-Licenses

PSCommandPath : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

InvocationName : Connect-MgGraph

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 85

PipelineIterationInfo :

 

2022-09-05T10:29:36Z [Error] ERROR: Authentication needed, call Connect-MgGraph.

 

Exception :

Type : System.Security.Authentication.AuthenticationException

TargetSite :

Name : GetGraphHttpClient

DeclaringType : Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers

MemberType : Method

Module : Microsoft.Graph.Authentication.dll

StackTrace :

at Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(InvocationInfo invocationInfo, IAuthContext authContext)

at Microsoft.Graph.PowerShell.Module.BeforeCreatePipeline(InvocationInfo invocationInfo, HttpPipeline& pipeline)

at Microsoft.Graph.PowerShell.Module.CreatePipeline(InvocationInfo invocationInfo, String parameterSetName)

at Microsoft.Graph.PowerShell.Cmdlets.GetMgSubscribedSku_List1.ProcessRecordAsync()

Message : Authentication needed, call Connect-MgGraph.

Source : Microsoft.Graph.Authentication

HResult : -2146233087

CategoryInfo : NotSpecified: (:) [Get-MgSubscribedSku_List1], AuthenticationException

FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgSubscribedSku_List1

InvocationInfo :

MyCommand : Get-MgSubscribedSku_List1

ScriptLineNumber : 34

OffsetInLine : 1

HistoryId : 1

ScriptName : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

Line : $licenseUsage = Get-MgSubscribedSku | Select-Object -Property SkuPartNumber,CapabilityStatus,@{Name=”PrepaidUnits”;expression={$_.PrepaidUnits.Enabled -join “;”}},ConsumedUnits,SkuId,AppliesTo

 

PositionMessage : At C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1:34 char:1

+ $licenseUsage = Get-MgSubscribedSku | Select-Object -Property SkuPart …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PSScriptRoot : C:homesitewwwrootHttpTrigger-Get-Licenses

PSCommandPath : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

InvocationName : Get-MgSubscribedSku

CommandOrigin : Internal

ScriptStackTrace : at Get-MgSubscribedSku<Process>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Identity.DirectoryManagement1.10.0exportsv1.0ProxyCmdletDefinitions.ps1: line 12245

at Get-LicenseUsage, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 34

at <ScriptBlock>, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 88

PipelineIterationInfo :

the logs revealed

Going through the logs revealed the two lines below which suggest that there was something wrong with using the Connect-MgGraph cmdlet to connect to Microsoft Graph:

Microsoft.Graph.Authentication, Version=1.11.1.0

2022-09-05T10:29:36Z [Error] ERROR: Authentication needed, call Connect-MgGraph.

I’ve ran into issues like this in the past which resulted in a lot of troubleshooting so I’m glad I’ve already gone through it before and immediately realized it must be because the Microsoft.Graph.Authentication module was updated and either intentionally or unintentionally no longer works with the certificate authentication I’m using. Browsing the PowerShell gallery for Microsoft.Graph (https://www.powershellgallery.com/packages/Microsoft.Graph/1.11.1) shows the latest version at the time of this writing was 1.11.1 and it was released in late August 2022, which the time I wrote the past was back in July. This lead me to believe that the latest 1.11.1 version is the reason for the error.

Reviewing the requirements.psd1 I had created for the Function App shows that any major version 1.* should be used:

‘JoinModule’ = ‘3.*’

‘Microsoft.Graph.Identity.DirectoryManagement’ = ‘1.*’

‘Microsoft.Graph.Authentication’ = ‘1.*’

}

reviewed the version of the

To correct the issue, I reviewed the version of the Microsoft.Graph.Authentication module I had on my local computer (version 1.10.0), tested the script locally to confirm it worked, then updated the requirements.psd1 for the function app to specify a specific version:

# ‘Az’ = ‘6.*’

‘JoinModule’ = ‘3.*’

‘Microsoft.Graph.Identity.DirectoryManagement’ = ‘1.10.0’

‘Microsoft.Graph.Authentication’ = ‘1.10.0’

}

documentation

Then as per the Microsoft documentation that explains how to target a specific version (https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#dependency-management), navigated into the profile.ps1 file in the App files:

mport statement to

.. added the import statement to import the modules:

Import-Module Microsoft.Graph.Identity.DirectoryManagement -RequiredVersion ‘1.10.0’
Import-Module Microsoft.Graph.Authentication -RequiredVersion ‘1.10.0’

nce the above steps

Reference article: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#target-specific-versions

attempting to execute

Once the above steps are completed, attempting to execute the function app may still fail to run and display the following error message:

2022-09-05T10:23:37Z [Error] ERROR: Assembly with same name is already loaded

 

Exception :

Type : System.IO.FileLoadException

Message : Assembly with same name is already loaded

TargetSite :

Name : LoadBinaryModule

DeclaringType : Microsoft.PowerShell.Commands.ModuleCmdletBase

MemberType : Method

Module : System.Management.Automation.dll

StackTrace :

at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)

at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)

at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)

at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found)

at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)

at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)

at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()

at System.Management.Automation.CommandProcessor.ProcessRecord()

Source : System.Management.Automation

HResult : -2146232799

CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException

FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

InvocationInfo :

MyCommand : Import-Module

ScriptLineNumber : 4

OffsetInLine : 9

HistoryId : 1

ScriptName : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

Line : $null = Import-Module -Name $ModulePath

 

PositionMessage : At C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1:4 char:9

+ $null = Import-Module -Name $ModulePath

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PSScriptRoot : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0

PSCommandPath : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

InvocationName : Import-Module

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 4

at <ScriptBlock>, C:homesitewwwrootprofile.ps1: line 20

 

2022-09-05T10:23:39Z [Warning] The Function app may be missing a module containing the ‘Get-ScriptCmdlet’ command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell 7. For more details, see https://aka.ms/functions-powershell-managed-dependency. If the module is installed but you are still getting this error, try to import the module explicitly by invoking Import-Module just before the command that produces the error: this will not fix the issue but will expose the root cause.

2022-09-05T10:23:39Z [Error] ERROR: The term ‘Get-ScriptCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

 

Exception :

Type : System.Management.Automation.CommandNotFoundException

ErrorRecord :

Exception :

Type : System.Management.Automation.ParentContainsErrorRecordException

Message : The term ‘Get-ScriptCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

HResult : -2146233087

TargetObject : Get-ScriptCmdlet

CategoryInfo : ObjectNotFound: (Get-ScriptCmdlet:String) [], ParentContainsErrorRecordException

FullyQualifiedErrorId : CommandNotFoundException

InvocationInfo :

ScriptLineNumber : 11

OffsetInLine : 36

HistoryId : 1

ScriptName : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1

Line : Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $CustomScriptPath) -Alias (Get-ScriptCmdlet -ScriptFolder $CustomScriptPath -AsAlias)

 

PositionMessage : At C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1:11 char:36

+ Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $Cu …

+ ~~~~~~~~~~~~~~~~

PSScriptRoot : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScripts

PSCommandPath : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1

InvocationName : Get-ScriptCmdlet

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1: line 11

at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 12

at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 11

at <ScriptBlock>, C:homesitewwwrootprofile.ps1: line 20

CommandName : Get-ScriptCmdlet

TargetSite :

Name : LookupCommandInfo

DeclaringType : System.Management.Automation.CommandDiscovery, System.Management.Automation, Version=7.0.11.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

MemberType : Method

Module : System.Management.Automation.dll

StackTrace :

at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)

at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)

at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)

at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)

at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)

at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)

at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Message : The term ‘Get-ScriptCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Data : System.Collections.ListDictionaryInternal

Source : System.Management.Automation

HResult : -2146233087

TargetObject : Get-ScriptCmdlet

CategoryInfo : ObjectNotFound: (Get-ScriptCmdlet:String) [], CommandNotFoundException

FullyQualifiedErrorId : CommandNotFoundException

InvocationInfo :

ScriptLineNumber : 11

OffsetInLine : 36

HistoryId : 1

ScriptName : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1

Line : Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $CustomScriptPath) -Alias (Get-ScriptCmdlet -ScriptFolder $CustomScriptPath -AsAlias)

 

PositionMessage : At C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1:11 char:36

+ Export-ModuleMember -Function (Get-ScriptCmdlet -ScriptFolder $Cu …

+ ~~~~~~~~~~~~~~~~

PSScriptRoot : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScripts

PSCommandPath : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1

InvocationName : Get-ScriptCmdlet

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0StartupScriptsExportCustomCommands.ps1: line 11

at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 12

at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 11

at <ScriptBlock>, C:homesitewwwrootprofile.ps1: line 20

 

2022-09-05T10:23:39Z [Warning] The Function app may be missing a module containing the ‘Get-ModuleCmdlet’ command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell 7. For more details, see https://aka.ms/functions-powershell-managed-dependency. If the module is installed but you are still getting this error, try to import the module explicitly by invoking Import-Module just before the command that produces the error: this will not fix the issue but will expose the root cause.

2022-09-05T10:23:39Z [Error] ERROR: The term ‘Get-ModuleCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

 

Exception :

Type : System.Management.Automation.CommandNotFoundException

ErrorRecord :

Exception :

Type : System.Management.Automation.ParentContainsErrorRecordException

Message : The term ‘Get-ModuleCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

HResult : -2146233087

TargetObject : Get-ModuleCmdlet

CategoryInfo : ObjectNotFound: (Get-ModuleCmdlet:String) [], ParentContainsErrorRecordException

FullyQualifiedErrorId : CommandNotFoundException

InvocationInfo :

ScriptLineNumber : 17

OffsetInLine : 30

HistoryId : 1

ScriptName : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

Line : Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath) -Alias (Get-ModuleCmdlet -ModulePath $ModulePath -AsAlias)

 

PositionMessage : At C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1:17 char:30

+ Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath …

+ ~~~~~~~~~~~~~~~~

PSScriptRoot : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0

PSCommandPath : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

InvocationName : Get-ModuleCmdlet

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 17

at <ScriptBlock>, C:homesitewwwrootprofile.ps1: line 20

CommandName : Get-ModuleCmdlet

TargetSite :

Name : LookupCommandInfo

DeclaringType : System.Management.Automation.CommandDiscovery, System.Management.Automation, Version=7.0.11.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

MemberType : Method

Module : System.Management.Automation.dll

StackTrace :

at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)

at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)

at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)

at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)

at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)

at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)

at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Message : The term ‘Get-ModuleCmdlet’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Data : System.Collections.ListDictionaryInternal

Source : System.Management.Automation

HResult : -2146233087

TargetObject : Get-ModuleCmdlet

CategoryInfo : ObjectNotFound: (Get-ModuleCmdlet:String) [], CommandNotFoundException

FullyQualifiedErrorId : CommandNotFoundException

InvocationInfo :

ScriptLineNumber : 17

OffsetInLine : 30

HistoryId : 1

ScriptName : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

Line : Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath) -Alias (Get-ModuleCmdlet -ModulePath $ModulePath -AsAlias)

 

PositionMessage : At C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1:17 char:30

+ Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath …

+ ~~~~~~~~~~~~~~~~

PSScriptRoot : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0

PSCommandPath : C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1

InvocationName : Get-ModuleCmdlet

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Authentication1.10.0Microsoft.Graph.Authentication.psm1: line 17

at <ScriptBlock>, C:homesitewwwrootprofile.ps1: line 20

 

2022-09-05T10:23:40Z [Error] Errors reported while executing profile.ps1. See logs for detailed errors. Profile location: C:homesitewwwrootprofile.ps1.

2022-09-05T10:23:40Z [Information] INFORMATION: PowerShell HTTP trigger function processed a request.

2022-09-05T10:23:42Z [Error] ERROR: Could not load file or assembly ‘Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’. The system cannot find the file specified.

 

Exception :

Type : System.IO.FileNotFoundException

Message : Could not load file or assembly ‘Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’. The system cannot find the file specified.

FileName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

TargetSite :

Name : MoveNext

DeclaringType : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph+<ProcessRecordAsync>d__56, Microsoft.Graph.Authentication, Version=1.11.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

MemberType : Method

Module : Microsoft.Graph.Authentication.dll

StackTrace :

at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()

Source : Microsoft.Graph.Authentication

HResult : -2147024894

CategoryInfo : NotSpecified: (:) [Connect-MgGraph], FileNotFoundException

FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph

InvocationInfo :

MyCommand : Connect-MgGraph

ScriptLineNumber : 85

OffsetInLine : 1

HistoryId : 1

ScriptName : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

Line : Connect-MgGraph -ClientID $appId -TenantId $tenantID -CertificateThumbprint $thumb ## Or -CertificateName “M365-License”

 

PositionMessage : At C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1:85 char:1

+ Connect-MgGraph -ClientID $appId -TenantId $tenantID -CertificateThum …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PSScriptRoot : C:homesitewwwrootHttpTrigger-Get-Licenses

PSCommandPath : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

InvocationName : Connect-MgGraph

CommandOrigin : Internal

ScriptStackTrace : at <ScriptBlock>, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 85

PipelineIterationInfo :

 

2022-09-05T10:23:42Z [Error] ERROR: Authentication needed, call Connect-MgGraph.

 

Exception :

Type : System.Security.Authentication.AuthenticationException

TargetSite :

Name : GetGraphHttpClient

DeclaringType : Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers

MemberType : Method

Module : Microsoft.Graph.Authentication.dll

StackTrace :

at Microsoft.Graph.PowerShell.Authentication.Helpers.HttpHelpers.GetGraphHttpClient(InvocationInfo invocationInfo, IAuthContext authContext)

at Microsoft.Graph.PowerShell.Module.BeforeCreatePipeline(InvocationInfo invocationInfo, HttpPipeline& pipeline)

at Microsoft.Graph.PowerShell.Module.CreatePipeline(InvocationInfo invocationInfo, String parameterSetName)

at Microsoft.Graph.PowerShell.Cmdlets.GetMgSubscribedSku_List1.ProcessRecordAsync()

Message : Authentication needed, call Connect-MgGraph.

Source : Microsoft.Graph.Authentication

HResult : -2146233087

CategoryInfo : NotSpecified: (:) [Get-MgSubscribedSku_List1], AuthenticationException

FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgSubscribedSku_List1

InvocationInfo :

MyCommand : Get-MgSubscribedSku_List1

ScriptLineNumber : 34

OffsetInLine : 1

HistoryId : 1

ScriptName : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

Line : $licenseUsage = Get-MgSubscribedSku | Select-Object -Property SkuPartNumber,CapabilityStatus,@{Name=”PrepaidUnits”;expression={$_.PrepaidUnits.Enabled -join “;”}},ConsumedUnits,SkuId,AppliesTo

 

PositionMessage : At C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1:34 char:1

+ $licenseUsage = Get-MgSubscribedSku | Select-Object -Property SkuPart …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PSScriptRoot : C:homesitewwwrootHttpTrigger-Get-Licenses

PSCommandPath : C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1

InvocationName : Get-MgSubscribedSku

CommandOrigin : Internal

ScriptStackTrace : at Get-MgSubscribedSku<Process>, C:homedataManagedDependencies2209042059148689947.rMicrosoft.Graph.Identity.DirectoryManagement1.10.0exportsv1.0ProxyCmdletDefinitions.ps1: line 12245

at Get-LicenseUsage, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 34

at <ScriptBlock>, C:homesitewwwrootHttpTrigger-Get-Licensesrun.ps1: line 88

PipelineIterationInfo :

Assembly with the

The error message Assembly with the same name is already loaded is caused by the newer module that has already been downloaded, which is causing the older module we are trying to import to fail. One of the ways to resolve this is remove the new module with Kudu.

Every app that is created has a companion app created for it (https://docs.microsoft.com/en-us/azure/app-service/resources-kudu#access-kudu-for-your-app) and this app named Kudu can be accessed via:

Go to: https://<app-name>.scm.azurewebsites.net

directories of the app

You can browse the directories of the app but clicking on Debug console > PowerShell:

the directories of the app but clicking

Navigate to: data

ManagedDependencies

Then: ManagedDependencies

ou may find several folders in this directory:

You may find several folders in this directory:

browse into these folders

Proceed to browse into these folders and you’ll likely see the newer 1.11.1:

button to review thebutton to review the contents of requirements

Using the edit button to review the contents of requirements.psd1 will also show the older version using 1.* for the modules:

delete the old ManagedDependencies folder

Proceed to delete the old ManagedDependencies folder:

remaining ManagedDependencies folder

Then delete the newer 1.11.1 folder in the remaining ManagedDependencies folder:

With the newer module removed, we should now be able to run the function app:

anyone who may

Hope this helps anyone who may have used my previous post and noticed it did not work.