I have the following PowerShell code running in a Custom Command with the Microsoft.Graph
v2.6.1 PowerShell Modules installed in the AllUsers
scope of the Adaxes Service Server.
$UserId = try { [Guid]$Context.TargetObject.Get("adm-AzureID") } catch {}
try {
if($null -eq $UserId) {
throw 'User does not seem to be in Azure AD'
}
#Import-Module Microsoft.Graph
Connect-MgGraph -AccessToken ($Context.CloudServices.GetAzureAuthAccessToken("https://graph.microsoft.com/") | ConvertTo-SecureString -AsPlainText -Force) -NoWelcome
if(-not (Revoke-MgUserSignInSession -UserId $UserId)) {
$Context.Cancel("Failed to revoke Azure User sessions.")
}
} catch {
# Exception
$Context.Cancel("An exception has occured: $($_.Exception.Message)")
}
Unfortunately, it produces the warning Selected Microsoft Graph profile 'v1.0' does not exist for module 'Microsoft.Graph.Users.Actions'. No cmdlets were loaded.
and then the exception The term 'Revoke-MgUserSignInSession' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
. Import the Module (as per that comment, either before or after Connect-MgGraph
) does nothing.
If I open my own PowerShell 5.1 instance, outside of Adaxes, on the same server, then take an AccessToken
created by that GetAzureAuthAccessToken()
function and use it to connect with Microsoft Graph using Connect-MgGraph
, I can use Revoke-MgUserSignInSession
in said session without any problems.