/MSGraphFunctions

PowerShell Functions to query the Microsoft Graph API

Primary LanguagePowerShellMIT LicenseMIT

6/25/20: MSGraphFunctions is no longer maintained

This PowerShell Module has once been created for the IntuneBackupAndRestore PowerShell Module to function. As of the version 2.0.0 release of that module, it has been rewritten to use the Microsoft.Graph.Intune PowerShell Module instead. Now that the MSGraphFunctions PowerShell module is no longer a prerequisite, it is also no longer maintained by the author.

MSGraphFunctions

PowerShell Gallery PowerShell Gallery

PowerShell Functions to query the Microsoft Graph API.

Note that these functions run on the Microsoft Graph beta endpoint by default. For version 1, specify the -apiVersion "v1.0" switch.

Installing MSGraphFunctions

# Install MSGraphFunctions from the PowerShell Gallery
Install-Module -Name MSGraphFunctions

Prerequisites

  • Requires Azure AD Module installed.

Authenticate to Microsoft Graph

Import-Module MSGraphFunctions

# Authenticate for the first time and grant permissions for the "Microsoft Intune PowerShell" Enterprise Application. (Interactive Authentication (Supports MFA))
Connect-Graph -AdminConsent $true

# Interactive Authentication (Supports MFA)
Connect-Graph

# Non Interactive Authentication (Supports Automation Goals)
$Credential = Get-Credential
Connect-Graph -Credential $Credential

Examples

Example 01 - List all Intune Device Compliance Policies

$compliancePolicies = Get-GraphDeviceCompliancePolicy
$compliancePolicies

Example 02 - Duplicate an Intune Device Configuration Policy

$deviceConfiguration = Get-GraphDeviceConfiguration -id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
$requestBody = $deviceConfiguration | ConvertTo-Json

New-GraphDeviceConfiguration -requestBody $requestBody

Example 03 - Retrieve PowerShell Script Content

# Content of a Single Script
Get-GraphDeviceManagementScript -Id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Get-GraphDeviceManagementScriptContent

# Or
Get-GraphDeviceManagementScriptContent -Id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

# Output PowerShell Script Content of all Uploaded Scripts
Get-GraphDeviceManagementScript | Get-GraphDeviceManagementScriptContent

Example 04 - Delete an Intune Device Compliance Policy

Get-GraphDeviceComplaincePolicy -Id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Remove-GraphDeviceComplaincePolicy