function Invoke-InitializeModule { $module = Get-Module -Name Microsoft.Graph.Intune -ListAvailable if(-not $module) { $ret = [System.Windows.MessageBox]::Show("Intune PowerShell module not found!`n`nDo you want to install it as admin?`n`nYes = Install intune module as Admin (Requires admin or it will fail)`nNo = Install module for current user`nCancel = Quit", "Error", "YesNoCancel", "Error") if($ret -eq "Cancel") { exit } $params = @{} if($ret -eq "No") { $params.Add("Scope", "CurrentUser") } try { Install-Module -Name Microsoft.Graph.Intune -Force -ErrorAction SilentlyContinue @params } catch {} if(-not (Get-Module -Name Microsoft.Graph.Intune -ListAvailable -Refresh)) { [System.Windows.MessageBox]::Show("Failed to install Intune PowerShell module!`n`nRestart this as admin and try again`nor`nStart PowerShell as admin and run:`nInstall-Module -Name Microsoft.Graph.Intune", "Error", "OK", "Error") exit } } if(-not $global:authentication) { if((Get-Command Connect-MSGraph -ErrorAction SilentlyContinue)) { $global:authentication = Connect-MSGraph -PassThru } } if(-not $global:authentication) { [System.Windows.MessageBox]::Show("Failed to connect to Azure with Intune PowerShell module!`n`nNo Intune extensions will be imported", "Error", "OK", "Error") return } Write-Log "Get current user" $global:Me = Invoke-GraphRequest "ME" if(-not $global:Me) { [System.Windows.MessageBox]::Show("Failed to get information about current logged on Azure user!`n`nVerify connection and try again`n`nNo Intune modules will be imported!", "Error", "OK", "Error") return } Write-Log "Get organization info" $global:Organization = (Invoke-GraphRequest "Organization").Value $global:graphURL = "https://graph.microsoft.com/beta" # Add settings $global:appSettingSections += (New-Object PSObject -Property @{ Title = "Intune" Id = "IntuneAzure" Values = @() }) Write-Log "Add settings and menu items" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Root folder" Key = "IntuneRootFolder" Type = "Folder" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "App packages folder" Key = "IntuneAppPackages" Type = "Folder" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Add object type" Key = "AddObjectType" Type = "Boolean" DefaultValue = $true Description = "Default setting for adding object type to the export folder" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Add company name" Key = "AddCompanyName" Type = "Boolean" DefaultValue = $true Description = "Default setting for adding company name to the export folder" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Export Assignments" Key = "ExportIntuneAssignments" Type = "Boolean" DefaultValue = $true Description = "Default setting for exporting assignments" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Create groups" Key = "CreateIntuneGroupOnImport" Type = "Boolean" DefaultValue = $true Description = "Default setting for creating groups during import" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Convert synced groups" Key = "ConvertIntuneSyncedGroupOnImport" Type = "Boolean" DefaultValue = $true Description = "Convert AD synched groups to Azure AD group during import if the group does not exist" }) "IntuneAzure" Add-SettingsObject (New-Object PSObject -Property @{ Title = "Import Assignments" Key = "ImportAssignments" Type = "Boolean" DefaultValue = $true }) "IntuneAzure" #Add menu group and items Add-MenuSection (New-Object PSObject -Property @{ Title = "Intune/Azure Objects"; ID="IntuneGraphAPI"; Order = 10}) Add-MenuSection (New-Object PSObject -Property @{ Title = "Intune/Azure Management"; ID="IntuneGraphAPIEX"; Order = 20}) # Add default menu items Add-MenuItem (New-Object PSObject -Property @{ Title = 'Bulk Import' MenuID = "IntuneGraphAPIEX" Script = [ScriptBlock]{ Show-ImportAllForm } }) # Add default menu items Add-MenuItem (New-Object PSObject -Property @{ Title = 'Bulk Export' MenuID = "IntuneGraphAPIEX" Script = [ScriptBlock]{ Show-ExportAllForm } }) $global:UpdateJsonForMigration = $true } function Show-ExportAllForm { param($Extension) $xmlStr = @" $($Extension.Xaml) $($Extension.Xaml) "@ $reader = (New-Object System.Xml.XmlNodeReader $xaml) $script:inputBox = [Windows.Markup.XamlReader]::Load($reader) $script:txtValue = $script:inputBox.FindName("txtValue") $btnOk = $script:inputBox.FindName("btnOk") $btnCopy = $script:inputBox.FindName("btnCopy") $btnFull = $script:inputBox.FindName("btnFull") $script:txtValue.Text = (ConvertTo-Json $Object -Depth 5) $btnOk.Add_Click({ $script:inputBox.Close() }) $btnCopy.Add_Click({ $script:txtValue.Text | Clip }) if($script:ViewFullObject -and $NoLoadFull -ne $true) { $btnFull.Visibility = "Visible" $btnFull.Add_Click({ Write-Status "Loading full object info" $objFullInfo = Invoke-Command -ScriptBlock $script:ViewFullObject Write-Status "" if($objFullInfo) { $script:inputBox.Close() Show-ObjectInfo -object $objFullInfo -NoLoadFull } }) } $inputBox.ShowDialog() | Out-Null } ######################################################################## # # Export functions # ######################################################################## function Show-DefaultExportGrid { param( [ScriptBlock]$ExportAllScript, [ScriptBlock]$ExportSelectedScript, $Extension, $DisplayColumn) $exportGrid = [System.Windows.Markup.XamlReader]::Parse(@" $($Extension.Xaml) $($Extension.Xaml)