ADAL and PowerShell

ADAL v2 was just released. This is a library that makes it super easy to auth against Azure AD in an application.  Here’s a link to a very quick demo.

Well, if it can be done in WPF, surely we can do this in PowerShell. The first thing you have to do is make sure you have the Nuget command line tool installed.

Then you just run this command -

nuget install Microsoft.IdentityModel.Clients.ActiveDirectory


After that, you can find the 2 dll’s you need in the Microsoft.IdentityModel.Clients.ActiveDirectory.2.9.10826.1824\lib\net45 directory.

Now comes the fun part.


Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll 
Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll 
$tenant = "" 
$resource = "" 
$clientID = "dfbf167a-add-your-own-clientid-here" 
$redirect = new-object System.Uri("http://powershell") #as long as this is unique in your tenant, all good 
$AuthContext = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("$tenant") 
$result = $AuthContext.AcquireToken($resource,$clientID,$redirect) 

Comments (1) -

Comments are closed