Open guru08 opened 7 years ago
I know this is a little late, but can you provide some more details?
I'm trying to call the script from SQL agent and getting the following error: Executed as user: XXXXXX$. A job step received an error at line xx in a PowerShell script. The corresponding line is ' $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto") '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception calling "AcquireToken" with "4" argument(s): "Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application." '. Process Exit Code -1. The step failed.
Script works in ISE
Can't see where a modal dialog box is implicity created.
If you leave the PromptBehavior [the "Auto" in $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")] to "Auto", it will by default prompt the user for sign-on credentials. This creates a modal box much like the one generated when you sign on to the on-prem gateway. If you want the authorization to not prompt the user (thereby creating the modal), you need to set the parameter to something like "RefreshSession" or "Never". See the enum definition at https://docs.microsoft.com/en-us/dotnet/api/microsoft.identitymodel.clients.activedirectory.promptbehavior?view=azure-dotnet for the full Enum list. FYI: This behaviour changed in v3 of the ADAL and is no longer relevant to updated ADAL clients. AcquireToken has been deprecated in favor of AcquireTokenAsync. In doing this, the signature was also changed. The last parameter is now a PlatformParameters Object which needs to be constructed with the PromptBehavior Object passed as an argument, As so: $promptBehav = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto $platParam = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList $promptBehav $authenticationTask = $authContext.AcquireTokenAsync($resourceAppIdURI, $clientId, $redirectUri, $platParam)
When trying to schedule the power shell script, it shows as successful but data is not being refreshed.
Please help me