From 0cbfc3ae879ce8a0d44005304689cdd4a65ad302 Mon Sep 17 00:00:00 2001 From: Micke Date: Wed, 3 Jul 2019 06:52:59 +1000 Subject: [PATCH] Fixed issue with installing Intune module Added support for viewing object info --- Extensions/AppProtection.psm1 | 22 +++- Extensions/Apps.psm1 | 11 +- Extensions/AutoPilot.psm1 | 11 +- Extensions/AzureBranding.psm1 | 11 +- Extensions/Baseline.psm1 | 14 ++- Extensions/CompliancePolicies.psm1 | 11 +- Extensions/ConditionalAccess.psm1 | 18 +++- Extensions/ConfigurationItems.psm1 | 11 +- Extensions/EnrollmentStatusPage.psm1 | 11 +- Extensions/GroupPolicy.psm1 | 11 +- Extensions/MDM_MAM.psm1 | 11 +- Extensions/MSGraphIntune.psm1 | 154 +++++++++++++++++++++++++-- Extensions/PowerShellScripts.psm1 | 20 +++- Extensions/TermsAndConditions.psm1 | 12 ++- PSExtensionsHost.ps1 | 2 +- 15 files changed, 305 insertions(+), 25 deletions(-) diff --git a/Extensions/AppProtection.psm1 b/Extensions/AppProtection.psm1 index 10bdcf7..4a3e463 100644 --- a/Extensions/AppProtection.psm1 +++ b/Extensions/AppProtection.psm1 @@ -100,7 +100,7 @@ function Get-AppProtections $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-AppProtection}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-AppProtection}) -ViewFullObject ([scriptblock]{Get-AppProtectionObject $global:dgObjects.SelectedItem.Object}) -ForceFullObject } function Get-AppProtectionObjects @@ -108,6 +108,26 @@ function Get-AppProtectionObjects Get-GraphObjects -Url "/deviceAppManagement/managedAppPolicies" } +function Get-AppProtectionObject +{ + param($object, $additional = "") + + if(-not $object.id) { return } + + $objType = Get-AppProtectionObjectType $object."@odata.type" + + $expand = "" + if($objType -eq "targetedManagedAppConfigurations") + { + $expand = "?`$expand=Apps" + } + + if($objType) + { + Invoke-GraphRequest -Url "/deviceAppManagement/$objType/$($object.id)$($expand)" + } +} + function Export-AllAppProtections { param($path = "$env:Temp") diff --git a/Extensions/Apps.psm1 b/Extensions/Apps.psm1 index cf8a701..2619986 100644 --- a/Extensions/Apps.psm1 +++ b/Extensions/Apps.psm1 @@ -146,7 +146,7 @@ function Get-Applications $script:importParams = @{} $script:importParams.Add("Extension", $importExtension) - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles @script:importParams}) # -copy ([scriptblock]{Copy-Application}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles @script:importParams}) -ViewFullObject ([scriptblock]{Get-ApplicationObject $global:dgObjects.SelectedItem.Object}) } function Get-ApplicationObjects @@ -154,6 +154,15 @@ function Get-ApplicationObjects Get-GraphObjects -Url "/deviceAppManagement/mobileApps?`$filter=(microsoft.graph.managedApp/appAvailability%20eq%20null%20or%20microsoft.graph.managedApp/appAvailability%20eq%20%27lineOfBusiness%27%20or%20isAssigned%20eq%20true)&`$orderby=displayName" } +function Get-ApplicationObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceAppManagement/mobileApps/$($Object.id)$additional" +} + function Export-AllApplications { param($path = "$env:Temp") diff --git a/Extensions/AutoPilot.psm1 b/Extensions/AutoPilot.psm1 index a0dbfb5..3db94d1 100644 --- a/Extensions/AutoPilot.psm1 +++ b/Extensions/AutoPilot.psm1 @@ -100,7 +100,7 @@ function Get-AutoPilots $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-AutoPilot}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-AutoPilot}) -ViewFullObject ([scriptblock]{Get-AutoPilotObject $global:dgObjects.SelectedItem.Object}) } function Get-AutoPilotObjects @@ -108,6 +108,15 @@ function Get-AutoPilotObjects Get-GraphObjects -Url "/deviceManagement/windowsAutopilotDeploymentProfiles" } +function Get-AutoPilotObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceManagement/windowsAutopilotDeploymentProfiles/$($Object.id)$additional" +} + function Export-AllAutoPilots { param($path = "$env:Temp") diff --git a/Extensions/AzureBranding.psm1 b/Extensions/AzureBranding.psm1 index c92f8b8..a43e64d 100644 --- a/Extensions/AzureBranding.psm1 +++ b/Extensions/AzureBranding.psm1 @@ -102,7 +102,7 @@ function Get-AZBrandings $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -ViewFullObject ([scriptblock]{Get-AZBrandingObject $global:dgObjects.SelectedItem.Object}) } function Get-AZBrandingObjects @@ -114,6 +114,15 @@ function Get-AZBrandingObjects } } +function Get-AZBrandingObject +{ + param($object, $additional = "") + + if(-not $Object.locale) { return } + + Invoke-AzureNativeRequest "LoginTenantBrandings/$($Object.locale)$additional" +} + function Export-AllAZBrandings { param($path = "$env:Temp") diff --git a/Extensions/Baseline.psm1 b/Extensions/Baseline.psm1 index c9a0eb1..0b12afc 100644 --- a/Extensions/Baseline.psm1 +++ b/Extensions/Baseline.psm1 @@ -125,7 +125,7 @@ function Get-BaselineProfiles $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude @("*_Settings.json","*_assignments.json")) } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-BaselineProfile}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-BaselineProfile}) -ViewFullObject ([scriptblock]{Get-BaselineProfileObject $global:dgObjects.SelectedItem.Object}) } function Get-BaselineProfileObjects @@ -133,6 +133,18 @@ function Get-BaselineProfileObjects Get-GraphObjects -Url "/deviceManagement/intents" } +function Get-BaselineProfileObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + $profile = Invoke-GraphRequest -Url "/deviceManagement/intents/$($Object.id)" + $settings = Invoke-GraphRequest -Url "/deviceManagement/intents/$($Object.id)/Settings" + + @($profile, $settings) +} + function Export-AllBaselineProfiles { param($path = "$env:Temp") diff --git a/Extensions/CompliancePolicies.psm1 b/Extensions/CompliancePolicies.psm1 index 8598de9..29a66bc 100644 --- a/Extensions/CompliancePolicies.psm1 +++ b/Extensions/CompliancePolicies.psm1 @@ -100,7 +100,7 @@ function Get-CompliancePolicies $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-CompliancePolicy}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-CompliancePolicy}) -ViewFullObject ([scriptblock]{Get-CompliancePolicyObject $global:dgObjects.SelectedItem.Object}) } function Get-CompliancePolicyObjects @@ -108,6 +108,15 @@ function Get-CompliancePolicyObjects Get-GraphObjects -Url "/deviceManagement/deviceCompliancePolicies" } +function Get-CompliancePolicyObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceManagement/deviceCompliancePolicies/$($Object.id)$additional" +} + function Export-AllCompliancePolicies { param($path = "$env:Temp") diff --git a/Extensions/ConditionalAccess.psm1 b/Extensions/ConditionalAccess.psm1 index c8aabd7..d4aeec2 100644 --- a/Extensions/ConditionalAccess.psm1 +++ b/Extensions/ConditionalAccess.psm1 @@ -99,7 +99,7 @@ function Get-ConditionalAccess $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -ViewFullObject ([scriptblock]{Get-ConditionalAccessObject $global:dgObjects.SelectedItem.Object}) } function Get-ConditionalAccessObjects @@ -108,6 +108,22 @@ function Get-ConditionalAccessObjects Get-AzureNativeObjects "Policies/Policies?top=10&nextLink=null&appId=&includeBaseline=true" -property @('policyName') } +function Get-ConditionalAccessObject +{ + param($object, $additional = "") + + if(-not $Object.policyId) { return } + + if($Object.baselineType -eq 0) + { + Invoke-AzureNativeRequest "Policies/$($Object.policyId)$additional" + } + else + { + Invoke-AzureNativeRequest "BaselinePolicies/$($Object.policyId)$additional" + } +} + function Export-AllConditionalAccess { param($path = "$env:Temp") diff --git a/Extensions/ConfigurationItems.psm1 b/Extensions/ConfigurationItems.psm1 index 23543d0..cff05cd 100644 --- a/Extensions/ConfigurationItems.psm1 +++ b/Extensions/ConfigurationItems.psm1 @@ -99,7 +99,7 @@ function Get-DeviceConfigurations $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-DeviceConfiguration}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-DeviceConfiguration}) -ViewFullObject ([scriptblock]{Get-DeviceConfigurationObject $global:dgObjects.SelectedItem.Object}) } function Get-DeviceConfigurationObjects @@ -107,6 +107,15 @@ function Get-DeviceConfigurationObjects Get-GraphObjects -Url "/deviceManagement/deviceConfigurations"#,"/deviceManagement/groupPolicyConfigurations" } +function Get-DeviceConfigurationObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceManagement/deviceConfigurations/$($Object.id)$additional" +} + function Export-AllDeviceConfigurations { param($path = "$env:Temp") diff --git a/Extensions/EnrollmentStatusPage.psm1 b/Extensions/EnrollmentStatusPage.psm1 index b8e7a57..8b0f730 100644 --- a/Extensions/EnrollmentStatusPage.psm1 +++ b/Extensions/EnrollmentStatusPage.psm1 @@ -100,7 +100,7 @@ function Get-ESPs $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-ESP}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-ESP}) -ViewFullObject ([scriptblock]{Get-ESPObject $global:dgObjects.SelectedItem.Object}) } function Get-ESPObjects @@ -108,6 +108,15 @@ function Get-ESPObjects Get-GraphObjects -Url "/deviceManagement/deviceEnrollmentConfigurations" } +function Get-ESPObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceManagement/deviceEnrollmentConfigurations/$($Object.id)$additional" +} + function Export-AllESPs { param($path = "$env:Temp") diff --git a/Extensions/GroupPolicy.psm1 b/Extensions/GroupPolicy.psm1 index c61b7e4..543c0e4 100644 --- a/Extensions/GroupPolicy.psm1 +++ b/Extensions/GroupPolicy.psm1 @@ -101,7 +101,7 @@ function Get-GPOSettings $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-GPOSetting}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-GPOSetting}) -ViewFullObject ([scriptblock]{Get-GPOSettingObject $global:dgObjects.SelectedItem.Object}) } function Get-GPOSettingObjects @@ -109,6 +109,15 @@ function Get-GPOSettingObjects Get-GraphObjects -Url "/deviceManagement/groupPolicyConfigurations" } +function Get-GPOSettingObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + @((Invoke-GraphRequest -Url "/deviceManagement/groupPolicyConfigurations/$($Object.id)$additional"),(Get-GPOObjectSettings $Object)) +} + function Export-AllGPOSettings { param($path = "$env:Temp") diff --git a/Extensions/MDM_MAM.psm1 b/Extensions/MDM_MAM.psm1 index 3b80ab5..37b4701 100644 --- a/Extensions/MDM_MAM.psm1 +++ b/Extensions/MDM_MAM.psm1 @@ -99,7 +99,7 @@ function Get-MDMMAM $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -ViewFullObject ([scriptblock]{Get-MDMMAMObject $global:dgObjects.SelectedItem.Object}) } function Get-MDMMAMObjects @@ -107,6 +107,15 @@ function Get-MDMMAMObjects Get-AzureNativeObjects "MdmApplications" -property @('appDisplayName') } +function Get-MDMMAMObject +{ + param($object, $additional = "") + + if(-not $Object.objectId) { return } + + Invoke-AzureNativeRequest "/MdmApplications/$($Object.objectId)$additional" +} + function Export-AllMDMMAM { param($path = "$env:Temp") diff --git a/Extensions/MSGraphIntune.psm1 b/Extensions/MSGraphIntune.psm1 index a1c66ed..fa0b866 100644 --- a/Extensions/MSGraphIntune.psm1 +++ b/Extensions/MSGraphIntune.psm1 @@ -3,7 +3,7 @@ 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?`n`nYes = Install intune module (Requires admin or it will fail)`nNo = Contune without module (Nothing will work)`nCancel = Quit", "Error", "YesNoCancel", "Error") + $ret = [System.Windows.MessageBox]::Show("Intune PowerShell module not found!`n`nDo you want to install it?`n`nYes = Install intune module (Requires admin or it will fail)`nNo = Contune without module (No Azure modules will be loaded)`nCancel = Quit", "Error", "YesNoCancel", "Error") if($ret -eq "Yes") { try @@ -11,7 +11,7 @@ function Invoke-InitializeModule Install-Module -Name Microsoft.Graph.Intune -Force -ErrorAction SilentlyContinue } catch {} - if(-not (Get-Module -Name Microsoft.Graph.Intune)) + 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 @@ -21,6 +21,10 @@ function Invoke-InitializeModule { exit } + else + { + return + } } if(-not $global:authentication) @@ -31,9 +35,24 @@ function Invoke-InitializeModule } } + 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 + } + + $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 + } + $global:Organization = (Invoke-GraphRequest "Organization").Value + $global:graphURL = "https://graph.microsoft.com/beta" -# Add settings + # Add settings $global:appSettingSections += (New-Object PSObject -Property @{ Title = "Intune" Id = "IntuneAzure" @@ -113,9 +132,6 @@ function Invoke-InitializeModule Script = [ScriptBlock]{ Show-ExportAllForm } }) - $global:Me = Invoke-GraphRequest "ME" - $global:Organization = (Invoke-GraphRequest "Organization").Value - $global:UpdateJsonForMigration = $true } @@ -617,9 +633,57 @@ function Add-DefaultObjectButtons [scriptblock] $import, [scriptblock] - $copy + $copy, + [scriptblock] + $viewFullObject, + [switch] + $ForceFullObject, + [switch] + $hideview ) + if($hideview -ne $true) + { + $newBtn = New-Object System.Windows.Controls.Button + #View button + $newBtn.Content = 'View' + $newBtn.Name = 'btnView' + $newBtn.Margin = "5,0,0,0" + $newBtn.Width = "100" + $spSubMenu.AddChild($newBtn) + + $script:viewFullObject = $viewFullObject + $script:ForceFullObject = ($ForceFullObject -eq $true) + + if($view) + { + $newBtn.Add_Click($view) + } + else + { + $newBtn.Add_Click([scriptblock]{ + if(-not $global:dgObjects.SelectedItem) { return } + + if(-not $global:dgObjects.SelectedItem.Object) { return } + + if($script:ForceFullObject -eq $true -and $script:ViewFullObject) + { + Write-Status "Loading full object info" + $objFullInfo = Invoke-Command -ScriptBlock $script:ViewFullObject + Write-Status "" + if($objFullInfo) + { + Show-ObjectInfo -object $objFullInfo -NoLoadFull + } + } + else + { + Show-ObjectInfo -Object $global:dgObjects.SelectedItem.Object + } + }) + } + } + if($copy) { $newBtn = New-Object System.Windows.Controls.Button @@ -665,6 +729,82 @@ function Add-DefaultObjectButtons } } +function Show-ObjectInfo +{ + param( + $FormTitle = "Object info", + $object, + [switch]$NoLoadFull) + + if(-not $object) { return } + + [xml]$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 diff --git a/Extensions/PowerShellScripts.psm1 b/Extensions/PowerShellScripts.psm1 index 8b04e70..15c98d0 100644 --- a/Extensions/PowerShellScripts.psm1 +++ b/Extensions/PowerShellScripts.psm1 @@ -126,7 +126,7 @@ function Get-PowerShellScripts $script:exportParams.Add("Extension", $exportExtension) - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-PowerShellScript}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-PowerShellScript}) -ViewFullObject ([scriptblock]{Get-PowerShellScriptObject $global:dgObjects.SelectedItem.Object}) #Add download button $btnDownload = New-Object System.Windows.Controls.Button @@ -146,6 +146,14 @@ function Get-PowerShellScriptObjects Get-GraphObjects -Url "/deviceManagement/deviceManagementScripts" } +function Get-PowerShellScriptObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($object.id)$additional" +} + function Export-AllPowerShellScripts { param($path = "$env:Temp") @@ -185,7 +193,8 @@ function Export-SinglePowerShellScript if(Test-Path $path) { Write-Status "Export $($psObj.displayName)" - $obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($psObj.id)?`$expand=assignments" + $obj = Get-PowerShellScriptObject -object $psObj -additional "?`$expand=assignments" + #$obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($psObj.id)?`$expand=assignments" if($obj) { $fileName = "$path\$((Remove-InvalidFileNameChars $obj.displayName)).json" @@ -215,7 +224,8 @@ function Copy-PowerShellScript { # Export profile Write-Status "Export $($dgObjects.SelectedItem.displayName)" - $obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($dgObjects.SelectedItem.id)" + $obj = Get-PowerShellScriptObject -object $dgObjects.SelectedItem.Object + #$obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($dgObjects.SelectedItem.id)" if($obj) { # Import new profile @@ -289,7 +299,9 @@ function Import-PowerShellScriptObjects function Invoke-DownloadScript { if(-not $global:dgObjects.SelectedItem.Object.id) { return } - $obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($global:dgObjects.SelectedItem.Object.id)" + + $obj = Get-PowerShellScriptObject -object $dgObjects.SelectedItem.Object + #$obj = Invoke-GraphRequest -Url "/deviceManagement/deviceManagementScripts/$($global:dgObjects.SelectedItem.Object.id)" if($obj.scriptContent) { Write-Log "Download PowerShell script '$($obj.FileName)' from $($obj.displayName)" diff --git a/Extensions/TermsAndConditions.psm1 b/Extensions/TermsAndConditions.psm1 index d4caa47..5e6eccb 100644 --- a/Extensions/TermsAndConditions.psm1 +++ b/Extensions/TermsAndConditions.psm1 @@ -26,7 +26,6 @@ function Get-SupportedImportObjects }) } - function Get-SupportedExportObjects { $global:exportObjects += (New-Object PSObject -Property @{ @@ -101,7 +100,7 @@ function Get-TermsAndConditions $global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json") } - Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-TermsAndCondition}) + Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -copy ([scriptblock]{Copy-TermsAndCondition}) -ViewFullObject ([scriptblock]{Get-TermsAndConditionObject $global:dgObjects.SelectedItem.Object}) } function Get-TermsAndConditionObjects @@ -109,6 +108,15 @@ function Get-TermsAndConditionObjects Get-GraphObjects -Url "/deviceManagement/termsAndConditions" } +function Get-TermsAndConditionObject +{ + param($object, $additional = "") + + if(-not $Object.id) { return } + + Invoke-GraphRequest -Url "/deviceManagement/termsAndConditions/$($Object.id)$additional" +} + function Export-AllTermsAndConditions { param($path = "$env:Temp") diff --git a/PSExtensionsHost.ps1 b/PSExtensionsHost.ps1 index f9370a3..bff1711 100644 --- a/PSExtensionsHost.ps1 +++ b/PSExtensionsHost.ps1 @@ -292,7 +292,7 @@ function global:Show-InputDialog $script:inputBox.Close() }) - $ret = $inputBox.ShowDialog() + $inputBox.ShowDialog() | Out-null return $script:txtValue.Text }