Public/Get-AuthToken.ps1

function Get-AuthToken
{
#https://blogs.technet.microsoft.com/paulomarques/2016/03/21/working-with-azure-active-directory-graph-api-from-powershell/

   # param

    # (

   # [Parameter(Mandatory=$true)]

 # $TenantName

 # )

 

 # Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll
# Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll
    #$tenant = "yourdomainhere.onmicrosoft.com"
#$resource = "https://graph.windows.net"
#$clientID = "00d16af4-d0c7-460a-a9dc-fd350eb4b100"
#$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("https://login.windows.net/$TenantName")
#$clientCredential = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential($clientID, "pvkFSHLLotliGU23557]^(]")
#$result = $AuthContext.AcquireTokenAsync($resource,$clientCredential)
#$result


      # return $authResult

         
    param
        (
        [Parameter(Mandatory=$true)]
        $TenantName
        )
    Import-Module Azure
    $clientId = "00d16af4-d0c7-460a-a9dc-fd350eb4b100" 
    $redirectUri = "urn:ietf:wg:oauth:2.0:oob"
    $resourceAppIdURI = "https://graph.microsoft.com"
    $authority = "https://login.microsoftonline.com/$TenantName"
    $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
    $Credential = Get-Credential
    $AADCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" -ArgumentList $credential.UserName,$credential.Password
    $authResult = $authContext.AcquireTokenASync($resourceAppIdURI,$AADCredential)
    return $authResult

} Export-ModuleMember -Function Get-AuthToken