A PowerShell module for the Microsoft Graph API
This is a PowerShell module API wraper for the Microsoft Graph API.
The Microsoft Graph API is a REST API provided by Microsoft for integrating and managing Office 365 Exchange Online, OneDrive for Business, and Azure AD. It allows for application developers to integrate their apps with those Microsoft Services. Management of the environment is also possible but requires understanding of OAuth and REST.
This module is an API wrapper. It seeks to take the "foreign" concepts of REST and OAuth and make them accessible and usable in PowerShell. This module strives to make PowerShell administration and automation tasks via the Microsoft Graph API more like other PowerShell commands.
Invoke-GraphRequest
(and all the functions that utalize it) automatically track the renewal needs for your Access Tokens and will automatically refresh them when needed.PSMSGraph is available on the PowerShell Gallery.
To Inspect:
Save-Module -Name PSMSgraph -Path <path>
To install:
Install-Module -Name PSMSgraph
Documentation Site: psmsgraph.readthedocs.io
https://localhost/
)Import-Module -name 'PSMSGraph'
#In the credential prompt, provide your application's Client ID as the username and Client Secret as the password
$ClientCredential = Get-Credential
$GraphAppParams = @{
Name = 'My Graph Application!'
ClientCredential = $ClientCredential
RedirectUri = 'https://localhost/'
Tenant = 'adatum.onmicrosoft.com'
}
$GraphApp = New-GraphApplication @GraphAppParams
# This will prompt you to log in with your O365/Azure credentials.
# This is required at least once to authorize the application to act on behalf of your account
# The username and password is not passed back to or stored by PowerShell.
$AuthCode = $GraphApp | Get-GraphOauthAuthorizationCode
# see the following help for what resource to use.
# get-help Get-GraphOauthAccessToken -Parameter Resource
$GraphAccessToken = $AuthCode | Get-GraphOauthAccessToken -Resource 'https://graph.windows.net'
$GraphAccessToken | Export-GraphOAuthAccessToken -Path 'c:\MyGraphApp\AccessToken.XML'
Import-Module -name 'PSMSGraph'
$GraphAccessToken = Import-GraphOAuthAccessToken -Path 'c:\MyGraphApp\AccessToken.XML'
$GraphAccessToken | Update-GraphOAuthAccessToken -Force
$AADUsers = Get-AADUserAll -AccessToken $GraphAccessToken
$AADUsers |
Select-Object -Property * -ExcludeProperty _AccessToken |
Export-Csv -Path 'c:\MyGraphApp\AADUsers.csv' -NoTypeInformation
$GraphAccessToken | Export-GraphOAuthAccessToken -Path 'c:\MyGraphApp\AccessToken.XML'
https://github.com/markekraus/PSMSGraph/blob/master/RELEASE.md
https://github.com/markekraus/PSMSGraph/blob/master/docs/ChangeLog.md