Skip to content

svrooij/TokenMagician

Repository files navigation

TokenMagician 🪄

PowerShell gallery version PowerShell gallery downloads License

A PowerShell module that will help you get tokens from Entra ID using a managed identity as federated credential PowerShell Gallery.

Installation

You can install the module from the PowerShell Gallery by running the following command:

Install-Module -Name TokenMagician

Prerequisites

To use this module, you need to have an environment with support for managed identities, like Azure Functions, Azure App Services, or Azure Automation. And you need to configure an app registration in Entra ID as described here.

Usage

# Import the module
Import-Module TokenMagician

# Get a token
$token = Get-TmMsiToken -TenantId 'your-tenant-id' -ClientId 'your-client-id' -Scope 'https://graph.microsoft.com/.default'

# Use the token
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Users
Connect-MgGraph -AccessToken $token
Get-MgUser -Top 2

Module loader

Apperantly PowerShell shares all assemblies with all loaded modules, if a previously loaded module uses an assembly that you want to use, but it's a different version things fail.

This module uses code from Jordan Borean to load the module in its own "assembly context", see this repo