Instead I followed the following steps to install the Azure AD module within my windows powershell
Error returned when you execute the following step
PS C:\WINDOWS\system32> $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList "https://login.windows.net/my-masked-tenant-id"
New-Object : Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]: verify that the assembly containing this type is loaded.
At line:1 char:16
- ... thContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirecto ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
- FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
This is because Azure AD module is not present in WindowsPowershell module and needed to be installed.
PS>Install-Module -Name AzureAD -AllowClobber
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS C:\users\dushy\downloads> Import-Module -Name AzureAD
PS C:\users\dushy\downloads> Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\AzureAD\2.0.2.140\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
PS C:\users\dushy\downloads> $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList "https://login.windows.net/fc8d76e4-1122-4fe8-b519-4722b314cffc"
PS C:\users\dushy\downloads> $SecureStringPassword = ConvertTo-SecureString -String mypasswordString -AsPlainText -Force
PS C:\users\dushy\downloads> $secureSecretObject = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.SecureClientSecret" -ArgumentList $SecureStringPassword
PS C:\users\dushy\downloads> $app = New-AzADApplication -DisplayName my-cs-app -Password $SecureStringPassword
PS C:\users\dushy\downloads> $clientCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential" -ArgumentList $app.ApplicationId, $secureSecretObject
PS C:\users\dushy\downloads> $token=$authContext.AcquireTokenAsync("https://cognitiveservices.azure.com/", $clientCredential).Result
PS C:\users\dushy\downloads> $token
AccessTokenType : Bearer
AccessToken : accesstoken returned value
ExpiresOn : 9/8/2021 2:03:56 AM +00:00
ExtendedLifeTimeToken : False
TenantId :
UserInfo :
IdToken :
Authority : https://login.windows.net/my-masked-tenant-id/
POST https://my-masked-custom-subdomain.cognitiveservices.azure.com/text/analytics/v3.0/languages
Raw body
{
"documents": [
{
"id": "1",
"text": "Bonjour tout le monde"
},
{
"id": "2",
"text": "Hello world. How are you today"
},
{
"id": "3",
"text": "La carretera estaba atascada. Había mucho tráfico el día de ayer."
}
]
}
Use bearer token
Content-type = application/json
Response
{
"documents": [
{
"id": "1",
"detectedLanguage": {
"name": "French",
"iso6391Name": "fr",
"confidenceScore": 0.88
},
"warnings": []
},
{
"id": "2",
"detectedLanguage": {
"name": "English",
"iso6391Name": "en",
"confidenceScore": 1.0
},
"warnings": []
},
{
"id": "3",
"detectedLanguage": {
"name": "Spanish",
"iso6391Name": "es",
"confidenceScore": 1.0
},
"warnings": []
}
],
"errors": [],
"modelVersion": "2021-01-05"
}