This commit is contained in:
Mikael Karlsson
2021-10-07 20:06:31 +11:00
parent b852e9163c
commit 5976b0bffd
33 changed files with 1598 additions and 392 deletions

View File

@@ -1,4 +1,5 @@
<#
<#
.SYNOPSIS
Module for managing Intune objects
@@ -10,7 +11,7 @@ This module is for the Endpoint Manager/Intune View. It manages Export/Import/Co
#>
function Get-ModuleVersion
{
'3.1.11'
'3.1.12'
}
function Invoke-InitializeModule
@@ -117,12 +118,28 @@ function Invoke-InitializeModule
ViewID = "IntuneGraphAPI"
API = "/identity/conditionalAccess/policies"
Permissons=@("Policy.Read.All","Policy.ReadWrite.ConditionalAccess","Application.Read.All")
Dependencies = @("NamedLocations","Applications")
Dependencies = @("NamedLocations","Applications","TermsOfUse")
GroupId = "ConditionalAccess"
ImportExtension = { Add-ConditionalAccessImportExtensions @args }
PreImportCommand = { Start-PreImportConditionalAccess @args }
})
if((Get-SettingValue "PreviewFeatures" $false) -eq $true)
{
Add-ViewItem (New-Object PSObject -Property @{
Title = "Terms of use"
Id = "TermsOfUse"
ViewID = "IntuneGraphAPI"
ViewProperties = @("id", "displayName")
Expand = "files"
QUERYLIST = "`$expand=files"
API = "/identityGovernance/termsOfUse/agreements"
Permissons=@("Agreement.ReadWrite.All")
PreImportCommand = { Start-PreImportTermsOfUse @args }
GroupId = "ConditionalAccess"
})
}
Add-ViewItem (New-Object PSObject -Property @{
Title = "Named Locations"
Id = "NamedLocations"
@@ -777,6 +794,27 @@ function Invoke-FilterBoxChanged
$dgObjects.ItemsSource.Filter = $filter
$dgObjects.ItemsSource.Refresh()
}
$allObjectsCount = 0
if($dgObjects.ItemsSource.SourceCollection)
{
$allObjectsCount = $dgObjects.ItemsSource.SourceCollection.Count
}
$objCount = ($dgObjects.ItemsSource | measure).Count
if($objCount -gt 0)
{
$strAllObjectsInfo = ""
if($allObjectsCount -gt $objCount)
{
$strAllObjectsInfo = " ($($allObjectsCount))"
}
$global:txtEMObjects.Text = "Objects: $objCount$strAllObjectsInfo"
}
else
{
$global:txtEMObjects.Text = ""
}
}
#region Endpoint Security (Intents) functions
@@ -2491,4 +2529,50 @@ function Start-PreImportConditionalAccess
}
#endregion
#region Terms of use
function Start-PreImportTermsOfUse
{
param($obj, $objectType, $file, $assignments)
$pkgPath = Get-SettingValue "EMIntuneAppPackages"
if(-not $pkgPath -or [IO.Directory]::Exists($pkgPath) -eq $false)
{
Write-Log "Intune app directory is either missing or does not exist" 2
}
try
{
$fi = [IO.FileInfo]$file
} catch {}
foreach($file in $obj.Files)
{
$pdfFile = $null
if($fi.Directory.FullName)
{
$pdfFile = "$($fi.Directory.FullName)\$($file.fileName)"
}
if($null -eq $pdfFile -or [IO.File]::Exists($pdfFile) -eq $false)
{
$pdfFile = "$($pkgPath)\$($file.fileName)"
}
if([IO.File]::Exists($pdfFile) -eq $false)
{
Write-Log "Terms of use file $($file.fileName) not found. The Terms of Use object will not be imported." 2
@{"Import" = $false}
return
}
$bytes = [IO.File]::ReadAllBytes($pdfFile)
$file.fileData = [PSCustomObject]@{
data = [Convert]::ToBase64String($bytes)
}
}
}
#endregion
Export-ModuleMember -alias * -function *

View File

@@ -9,7 +9,7 @@ Module for listing Intune assignments
#>
function Get-ModuleVersion
{
'1.0.0'
'1.0.1'
}
function Invoke-InitializeModule
@@ -59,8 +59,8 @@ function Show-EMToolsIntuneAssignments
$dlgSave = New-Object -Typename System.Windows.Forms.SaveFileDialog
#$dlgSave.InitialDirectory = Get-SettingValue "IntuneRootFolder" $env:Temp
$dlgSave.FileName = $obj.FileName
$sf.DefaultExt = "*.csv"
$sf.Filter = "CSV (*.csv)|*.csv|All files (*.*)| *.*"
$dlgSave.DefaultExt = "*.csv"
$dlgSave.Filter = "CSV (*.csv)|*.csv|All files (*.*)| *.*"
if($dlgSave.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $dlgSave.Filename)
{
$script:objAssignments | Select Name, Type, IncludedString, ExcludedString | ConvertTo-Csv -NoTypeInformation | Out-File -LiteralPath $dlgSave.Filename -Encoding UTF8 -Force
@@ -123,13 +123,22 @@ function Get-EMIntuneAssignments
Write-Status "Collect exported assignments"
$intuneViewObj = $global:viewObjects | Where { $_.ViewInfo.ID -eq "IntuneGraphAPI" }
$script:objAssignments = @()
foreach($fileObj in $script:fileArr)
{
$objectType = $null
$folderName = $fileObj.FileInfo.Directory.Name
if($folderName)
{
$objectType = $intuneViewObj.ViewItems | Where Id -eq $folderName
}
$obj = New-Object PSObject -Property @{
Object = $fileObj.Object
Name = $fileObj.Object.DisplayName
Name = $fileObj.Object."$((?? $objectType.NameProperty "displayName"))"
Type = $null
Included = $null
Excluded = $null

View File

@@ -10,7 +10,7 @@ This module manages Microsoft Grap fuctions like calling APIs, managing graph ob
#>
function Get-ModuleVersion
{
'3.1.6'
'3.1.7'
}
$global:MSGraphGlobalApps = @(
@@ -215,6 +215,9 @@ function Invoke-GraphRequest
$ODataMetadata = "full", # full, minimal, none or skip
[switch]
$AllPages,
[switch]
$NoError
)
@@ -288,21 +291,60 @@ function Invoke-GraphRequest
$Url = $Url -replace "%OrganizationId%", $global:Organization.Id
}
### !!!
### @odata.nextLink - ToDo: Support for paging
### https://docs.microsoft.com/en-us/graph/paging
<#
if($AllPages)
{
# Code to test paging - Force each page to size specified in top parameter below
# Kept for reference
if(($url.IndexOf('?')) -eq -1)
{
$url = "$($url.Trim())?"
}
else
{
$url = "$($url.Trim())&"
}
$url = "$($url.Trim())`$top=20"
}
#>
$ret = $null
try
{
Write-LogDebug "Invoke graph API: $Url (Request ID: $requestId)"
$ret = Invoke-RestMethod -Uri $Url -Method $HttpMethod @params
if($? -eq $false)
$allValues = @()
do
{
throw $global:error[0]
$ret = Invoke-RestMethod -Uri $Url -Method $HttpMethod @params
if($? -eq $false)
{
throw $global:error[0]
}
if($HttpMethod -eq "PATCH" -and [String]::IsNullOrempty($ret))
{
$ret = $true;
break;
}
elseif($AllPages -eq $true -and $HttpMethod -eq "GET" -and $ret.value -is [Array])
{
$allValues += $ret.value
if($ret.'@odata.nextLink')
{
$Url = $ret.'@odata.nextLink'
}
}
else
{
break
}
} while($ret.'@odata.nextLink')
if($allValues.Count -gt 0 -and $ret.value -is [Array])
{
$ret.value = $allValues
}
if($HttpMethod -eq "PATCH" -and [String]::IsNullOrempty($ret)) { $ret = $true }
}
catch
{
@@ -354,7 +396,12 @@ function Get-GraphObjects
{
$url = "$($url.Trim())&$($objectType.QUERYLIST.Trim())" # Risky...does not check that the parameter is already in use
}
}
}
if($SingleObject -ne $true)
{
$params.Add('AllPages',$true)
}
$graphObjects = Invoke-GraphRequest -Url $url @params
@@ -453,18 +500,52 @@ function Show-GraphObjects
}
$tableColumns = @()
# Add other columns
foreach($prop in ($tmpObj.PSObject.Properties | Where {$_.Name -notin @("IsSelected","Object","ObjectType")}))
$additionalColumns = @()
$additionalColsStr = Get-Setting "EndpointManager\ObjectColumns" "$($global:curObjectType.Id)"
if($additionalColsStr)
{
$binding = [System.Windows.Data.Binding]::new($prop.Name)
$additionalColumns += $additionalColsStr.Split(',')
}
if($additionalColumns.Count -eq 0 -or $additionalColumns[0] -ne "0")
{
# Add default columns
foreach($prop in ($tmpObj.PSObject.Properties | Where {$_.Name -notin @("IsSelected","Object","ObjectType")}))
{
$binding = [System.Windows.Data.Binding]::new($prop.Name)
$column = [System.Windows.Controls.DataGridTextColumn]::new()
$column.Header = $prop.Name
$column.IsReadOnly = $true
$column.Binding = $binding
$tableColumns += $prop.Name
$dgObjects.Columns.Add($column)
}
}
# Add custom columns
foreach($additionalCol in $additionalColumns)
{
if($additionalCol -eq "0" -or $additionalCol -eq "1") { continue }
$bindingProp,$colHeader = $additionalCol.Split('=')
if(-not $colHeader)
{
$colHeader = $bindingProp
}
$binding = [System.Windows.Data.Binding]::new("Object.$($bindingProp)")
$column = [System.Windows.Controls.DataGridTextColumn]::new()
$column.Header = $prop.Name
$column.Header = $colHeader
$column.IsReadOnly = $true
$column.Binding = $binding
$tableColumns += $prop.Name
$tableColumns += $colHeader
$dgObjects.Columns.Add($column)
}
$ocList = [System.Collections.ObjectModel.ObservableCollection[object]]::new($graphObjects)
$dgObjects.ItemsSource = [System.Windows.Data.CollectionViewSource]::GetDefaultView($ocList)
}
@@ -492,6 +573,7 @@ function Show-GraphObjects
function Clear-GraphObjects
{
$global:txtFormTitle.Text = ""
$global:txtEMObjects.Text = ""
$global:grdTitle.Visibility = "Collapsed"
$global:grdObject.Children.Clear()
$global:dgObjects.ItemsSource = $null