Graph-MgConnect error: Entry point was not found. Powershell 7.5.0
Describe the bug
I have a strange behavior using graph api. If i run a script through Visual Studio Code and Powershell extantion all works well but if i schedule the same script with task scheduler i get the entry point not found error. I'm using powershell 7.5.0 for both Visual Studio Code and task scheduler execution. I have a lot of script run with task scheduler and all have the same issue. As installed module i have only Graph module, MSAL.PS and SimplySql
This is the action configured on task scheduler: Program/script: "C:\Program Files\PowerShell\7\pwsh.exe" Add Arguments: -ExecutionPolicy Bypass -File "C:\script\test.ps1"
The execution policy is set to RemoteSign for both LocalMachine and CurrentUser
Expected behavior
If script execution works in visual studio code than it should also work with task scheduler
How to reproduce
schedule script with task scheduler
SDK Version
2.25.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```PowerShell transcript start Start time: 20250214192336 Username: CORPABSTR.... RunAs User: CORPABSTR.... Configuration Name: Machine: ABS-DC2 (Microsoft Windows NT 10.0.14393.0) Host Application: C:\Program Files\PowerShell\7\pwsh.dll -ExecutionPolicy Bypass -File C:\script\RenewConsultants\RenewConsultants.ps1 Process ID: 7048 PSVersion: 7.5.0 PSEdition: Core GitCommitId: 7.5.0 OS: Microsoft Windows 10.0.14393 Platform: Win32NT PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0 PSRemotingProtocolVersion: 2.3 SerializationVersion: 1.1.0.1 WSManStackVersion: 3.0
Transcript started, output file is C:\script\RenewConsultants\logs\transcript.txt DEBUG: ClientCertificateCredential.GetToken invoked. Scopes: [ https://graph.microsoft.com/.default ] ParentRequestId: DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] MSAL MSAL.NetCore with assembly version '4.66.1.0'. CorrelationId(922e791c-3626-46c6-ae91-aaadc725a01d) DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] === AcquireTokenForClientParameters === SendX5C: False ForceRefresh: False DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] === Request Data === Authority Provided? - True Scopes - https://graph.microsoft.com/.default Extra Query Params Keys (space separated) - ApiId - AcquireTokenForClient IsConfidentialClient - True SendX5C - False LoginHint ? False IsBrokerConfigured - False HomeAccountId - False CorrelationId - 922e791c-3626-46c6-ae91-aaadc725a01d UserAssertion set: False LongRunningOboCacheKey set: False Region configured: DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] === Token Acquisition (ClientCredentialRequest) started: Scopes: https://graph.microsoft.com/.default Authority Host: login.microsoftonline.com DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z] [Internal cache] Clearing app token cache accessor. DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] [Internal cache] Total number of cache partitions found while getting access tokens: 0 DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] [FindAccessTokenAsync] Discovered 0 access tokens in cache using partition key: d18e5660-6c3a-4084-8952-8ecc666c5592_5f4c80c0-58ee-4e80-8990-b80e85ad9e5b_AppTokenCache DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] [Instance Discovery] Instance discovery is enabled and will be performed DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-14 18:23:36Z - 922e791c-3626-46c6-ae91-aaadc725a01d] Fetching instance discovery from the network from host login.microsoftonline.com. DEBUG: Request [2a3c206e-8648-4401-815c-61718aa5c0f1] GET https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=REDACTED x-client-SKU:REDACTED x-client-Ver:REDACTED x-client-OS:REDACTED client-request-id:REDACTED return-client-request-id:REDACTED x-ms-client-request-id:2a3c206e-8648-4401-815c-61718aa5c0f1 x-ms-return-client-request-id:true User-Agent:azsdk-net-Identity/1.13.1 (.NET 9.0.1; Microsoft Windows 10.0.14393) client assembly: Azure.Identity Connect-MgGraph: C:\script\RenewConsultants\RenewConsultants.ps1:731 Line | 731 | Connect-MgGraph -ClientID $microsoftGraph.appID -TenantId $micros … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Entry point was not found. Connect-MgGraph: C:\script\RenewConsultants\RenewConsultants.ps1:731 Line | 731 | Connect-MgGraph -ClientID $microsoftGraph.appID -TenantId $micros … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Entry point was not found.
PowerShell transcript end End time: 20250214192337
</details>
### Configuration
$PSVersionTable output:
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
OS Version:
Edition: Windows Server 2016
Version: 1607
OS Build: 14393.7785
Architecture:
x64
### Other information
_No response_
Hi @alessandroere maybe you could be having library conflicts between MSAL and graph PowerShell. Please share the output of this command. [system.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location | Out-GridView
Hi @timayabi2020
This output is direct from Powershell via Visual Studio Code outFileFromPowershellCli.txt
This output is direct from task scheduler execution
outFileFromPowershellFromTaskScheduler.txt
Thank you
@alessandroere if you compare the two files, the output from the task scheduler is missing the Azure.Identity assembly hence the error.
Maybe you can try reinstalling the SDK with these parameters at the end -AllowClobber -Force or you can manually add the assembly in the script referenced by the task scheduler. i.e.
$IdentityLibPath = "C:\Program Files\PowerShell\Modules\Microsoft.Graph.Authentication\2.25.0\Dependencies"
Add-Type -AssemblyName (Join-Path $IdentityLibPath "Azure.Identity.dll")
Hi @timayabi2020, sorry for delay.
After removed MSAL.PS module the authentication worked but after a vm reboot the error still there. I tried to install again the sdk with -AllowClobber -Force without success
I tried to add the two rows to import the assemply manualy but the errore still there
Thank you for your time
Hi @timayabi2020, i note that when i run the script through task scheduler the debug from Connect-MgGraph show
DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] === Token Acquisition (ClientCredentialRequest) started: Scopes: https://graph.microsoft.com/.default Authority Host: login.microsoftonline.com DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z] [Internal cache] Clearing app token cache accessor. DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] [Internal cache] Total number of cache partitions found while getting access tokens: 0 DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] [FindAccessTokenAsync] Discovered 0 access tokens in cache using partition key: d18e5660-6c3a-4084-8952-8ecc666c5592_5f4c80c0-58ee-4e80-8990-b80e85ad9e5b_AppTokenCache DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] [Instance Discovery] Instance discovery is enabled and will be performed DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] [Region discovery] Not using a regional authority. DEBUG: False MSAL 4.66.1.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:52:38Z - edaa4e8d-bc6e-4273-876e-785e83d48844] Fetching instance discovery from the network from host login.microsoftonline.com. DEBUG: Request [aa183c0a-8065-4cac-b318-d57cad35f9a8] GET https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=REDACTED
it's using version 4.66.1.0 for MSAL.NetCore
Instead when i run the script throught visual studio code the debug from Connect-Mggraph show
DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z - bde3c7d4-b123-4afd-b28e-5b93756504eb] === Token Acquisition (ClientCredentialRequest) started: Scopes: https://graph.microsoft.com/.default Authority Host: login.microsoftonline.com DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z] [Internal cache] Clearing app token cache accessor. DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z - bde3c7d4-b123-4afd-b28e-5b93756504eb] [Internal cache] Total number of cache partitions found while getting access tokens: 0 DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z - bde3c7d4-b123-4afd-b28e-5b93756504eb] [FindAccessTokenAsync] Discovered 0 access tokens in cache using partition key: d18e5660-6c3a-4084-8952-8ecc666c5592_5f4c80c0-58ee-4e80-8990-b80e85ad9e5b_AppTokenCache DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z - bde3c7d4-b123-4afd-b28e-5b93756504eb] [Instance Discovery] Instance discovery is enabled and will be performed DEBUG: False MSAL 4.67.2.0 MSAL.NetCore .NET 9.0.1 Microsoft Windows 10.0.14393 [2025-02-25 10:55:33Z - bde3c7d4-b123-4afd-b28e-5b93756504eb] [Region discovery] Not using a regional authority. DEBUG: Request [7e35b09b-214d-4a29-97a2-542181e4cbee] POST https://login.microsoftonline.com/5f4c80c0-58ee-4e80-8990-b80e85ad9e5b/oauth2/v2.0/token
In this case it's using version 4.67.2.0 for MSAL.NetCore
I'm not expert about .dotnet i don't know how to force to use only version 4.67.2.0. Do you know how to do that? How can i remove the old version and use only the newer version?
I have only Microsoft .Net Runtime 9.0.2 installed. I supposed that MSAL.NetCore is as a part of this Runtime
Thank you
Please upgrade to the latest Microsoft Graph SDK version (2.26.1) and try again.
Hi @timayabi2020, i tried with Microsoft Graph SDK version (2.26.1) but i have the same problem. I tried to create a fresh Windows Server 2016 with only Graph Module end Powershell 7.5.0. The error it's the same.