This is great tool and helps us a lot. In the latest version, 1.3.1, we find it can't run using certification.
Seems you missed a $ at line 371 in GetTokenWithCertificate function.
function GetTokenWithCertificate
{
We use MSAL with certificate auth
if (!script:msalApiLoaded) <===== should be if (!$script:msalApiLoaded)
{
$msalLocation = @()
$script:msalApiLoaded = $(LoadLibraries -searchProgramFiles $false -dllNames @("Microsoft.Identity.Client.dll") -dllLocations ([ref]$msalLocation))
if (!$script:msalApiLoaded)
{
Log "Failed to load MSAL. Cannot continue with certificate authentication." Red
exit
}
}
after adding the $, I failed in line 351, in LoadLibraries function.
try
{
LogVerbose ([string]::Format("Loading {2} v{0} found at: {1}", $dll.VersionInfo.FileVersion, $dll.VersionInfo.FileName, $dllName))
Write-Host "debug here1" -ForegroundColor Yellow
Add-Type -Path $dll.VersionInfo.FileName
if ($dllLocations)
{
$dllLocations.value += $dll.VersionInfo.FileName
ReportError
}
}
catch
{
ReportError "LoadLibraries"
return $false
}
Error is like below:
Try to run Add-Type manually to get LoaderExceptions:
PS C:\Users\hongzhou\Downloads\MergeFolderTest> try {
Add-Type -Path C:\Users\hongzhou\Downloads\MergeFolderTest\Microsoft.Identity.Client.dll
}
catch {
Write-Host "Message: $($.Exception.Message)"
Write-Host "StackTrace: $($.Exception.StackTrace)"
Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
}
Message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
StackTrace: at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes)
at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I've put these dlls within the same folder.
Mode LastWriteTime Length Name
Hi David,
This is great tool and helps us a lot. In the latest version, 1.3.1, we find it can't run using certification.
function GetTokenWithCertificate {
We use MSAL with certificate auth
Error is like below:
Try to run Add-Type manually to get LoaderExceptions: PS C:\Users\hongzhou\Downloads\MergeFolderTest> try { Add-Type -Path C:\Users\hongzhou\Downloads\MergeFolderTest\Microsoft.Identity.Client.dll } catch { Write-Host "Message: $($.Exception.Message)" Write-Host "StackTrace: $($.Exception.StackTrace)" Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)" } Message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. StackTrace: at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes) at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing() at System.Management.Automation.CommandProcessorBase.Complete() LoaderExceptions: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I've put these dlls within the same folder. Mode LastWriteTime Length Name
d----- 2023/10/18 17:07 Microsoft.IdentityModel.Abstractions.6.22.0
d----- 2023/10/18 17:10 System.Runtime.4.3.1
-a---- 2023/10/18 15:17 91328 Merge-MailboxFolder.ps1
-a---- 2021/11/19 2:44 108504 Microsoft.Identity.Client.Desktop.dll
-a---- 2023/4/14 16:39 1632728 Microsoft.Identity.Client.dll
-a---- 2021/11/19 2:44 1524176 Microsoft.Identity.Client.dll.37
-a---- 2023/9/8 16:17 1600968 Microsoft.Identity.Client.dll.new
-a---- 2023/3/28 14:12 65928 Microsoft.Identity.Client.Extensions.Msal.dll
-a---- 2022/7/27 11:08 18824 Microsoft.IdentityModel.Abstractions.dll
-a---- 2023/9/8 16:17 1081728 Microsoft.IdentityModel.Clients.ActiveDirectory.dll
-a---- 2023/9/8 16:17 89480 Microsoft.IdentityModel.JsonWebTokens.dll
-a---- 2023/9/8 16:17 34224 Microsoft.IdentityModel.Logging.dll
-a---- 2023/9/8 16:17 989064 Microsoft.IdentityModel.Tokens.dll
Please help, thanks.