Problems with Connect-AzureAD - IIS 404 (NotFound)

Product: PowerShell Universal
Version: 5.0.8

Hi,

I´m new to Powershell Universal and we are in a POC with version 5.0.8 on IIS at the moment.

We have a problem to connect with AzureAD. Please take a look:

Import-Module AzureADPreview

# Variable
$CredAAD = $secret:SCAAD
Connect-AzureAD -credential $CredAAD

Error information:

One or more errors occurred.
Response status code does not indicate success: 404 (NotFound). 
One or more errors occurred.
You must call the Connect-AzureAD cmdlet before calling any other cmdlets.

The module AzureADPreview is installed and we use PS5.1 as Environment.

When i test it outside of powershell universal, it is possible to connect to Azure AD over ISE.

We also tried a web request in the same script and it works fine:

Invoke-WebRequest -Uri https://adminwebservice.microsoftonline.com/ProvisioningService.svc

Result:

StatusCode        : 200
StatusDescription : OK
Content           : <HTML><HEAD><STYLE type="text/css">#content{ FONT-SIZE: 
                    0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 
                    30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: 
                    #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: wh...
RawContent        : HTTP/1.1 200 OK
                    Strict-Transport-Security: max-age=31536000; 
                    includeSubDomains
                    X-Content-Type-Options: nosniff
                    Content-Length: 6437
                    Content-Type: text/html; charset=UTF-8
                    Date: Fri, 11 Oct 2024 0...
Forms             : {}
Headers           : {[Strict-Transport-Security, max-age=31536000; 
                    includeSubDomains], [X-Content-Type-Options, nosniff], 
                    [Content-Length, 6437], [Content-Type, text/html; 
                    charset=UTF-8]...}
Images            : {}
InputFields       : {}
Links             : {@{innerHTML=http://go.microsoft.com/fwlink/?LinkId=65455; 
                    innerText=http://go.microsoft.com/fwlink/?LinkId=65455; 
                    outerHTML=<A href="http://go.microsoft.com/fwlink/?LinkId=6
                    5455">http://go.microsoft.com/fwlink/?LinkId=65455</A>; 
                    outerText=http://go.microsoft.com/fwlink/?LinkId=65455; 
                    tagName=A; 
                    href=http://go.microsoft.com/fwlink/?LinkId=65455}}
ParsedHtml        : System.__ComObject
RawContentLength  : 6437

I could not find any solution yet.

I would be grateful for your help.

Best regards

Marco

Its been a while since i last tackled with this issue.

I recall Connect-AzureAD giving that error if the sign in was unsuccessful.

Are you sure this works?

$CredAAD = $secret:SCAAD
Connect-AzureAD -credential $CredAAD

How about:
Connect-AzureAD -credential $secret:SCAAD

Thanks for your advice,

sadly i have got the same error message.

It may seem minute but I think it would be worth verifying the permissions on the secret store. In the script, I would add a Write-Debug (or similar) line just outputting the $Secret:SCAAD values (username/pw). I’ve had issues with this and -RunAs behavior in some of my scripts due to locking down the access to the variable itself.

Good evening, thanks for the advice. The problem was probably in front of the PC. :slight_smile: I should have provided the complete domain in the secret, “user@example.com” instead of “domain\user”. Thank you for the support. Now everything works.

Best regards
Marco