Um Intune per PowerShell zu verwalten habe ich das folgende simple Skript erstellt. Es installiert das notwendige Modul und erteilt die Berechtigung zur Verwendung der Graph API (Admin Account erforderlich). Im Anschluss wird dann zum Tenant des UPN (User Principle Name) verbunden.
Graph ist die universelle API, die Microsoft in vielen neuen Produkten verwendet. Weitere Infos: //www.msxfaq.de/cloud/graph/index.htm
Unter den folgenden URLs könnt ihr euch weitere Infos und Beispiele zu cmdlets einholen.
//github.com/microsoft/Intune-PowerShell-SDK
//github.com/microsoftgraph/powershell-intune-samples
Es sind aktuell mehr als 900 Intune cmdlets verfügbar. Um alle Intune cmdlets aufzulisten muss folgendes eingegeben werden:
1 |
get-command -Module Microsoft.Graph.Intune |
Hier ist das vollständige Skript:
Hinweis: Sollte es zu Problemen kommen, müsst ihr evtl. die executionpolicy anpassen.
Github: https://github.com/cmehren/Intune-Powershell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#################################################################### # Connect_Intune_v1.0.ps1 by Christoph Mehren (23.06.19) # Info: # - Installs Graph API Module # - initiates Admin consent # - connect to MSGraph # # To get a list of commands for Intune run: # get-command -Module Microsoft.Graph.Intune # # more Infos at: //github.com/microsoft/Intune-PowerShell-SDK #################################################################### # Install Graph API Module If ((get-module -ListAvailable -Name Microsoft.Graph.Intune) -eq $null){ write-host "Installing Module: Microsoft.Graph.Intune" Install-Module -Name Microsoft.Graph.Intune -force } # Provide consent if needed (interactive prompt is needed) write-host "`n" write-host "`n" $Adminconsent= Read-Host -prompt "Admin consent already done? (Y/n)" switch ($Adminconsent) { y {} n {Connect-MSGraph -AdminConsent} Default {} } # Ask for credentials $UPN= Read-host -Prompt "Enter UPN: " $PW= Read-host -AsSecureString -Prompt "Enter password: " $cred = New-Object System.Management.Automation.PSCredential ($UPN, $PW) # Connect to MSGraph $connection = Connect-MSGraph -PSCredential $cred # Output connection details write-host "`n" if ($connection){write-host "connected sccessfull"} $connection |
Eine erfolgreiche Ausführung des Skripts sieht folgendermaßen aus:
1 Gedanke zu „Intune PowerShell über Graph API“