This commit is contained in:
Mikael Karlsson
2024-01-24 21:25:53 +11:00
parent 6ac211a2bf
commit 47968b4219
30 changed files with 4643 additions and 2534 deletions

View File

@@ -10,7 +10,7 @@ This module manages Microsoft Grap fuctions like calling APIs, managing graph ob
#>
function Get-ModuleVersion
{
'3.9.3'
'3.9.5'
}
$global:MSGraphGlobalApps = @(
@@ -584,7 +584,7 @@ function Get-GraphObjects
if($SinglePage -eq $true)
{
#Use default page size or use below for a specific page size for testing
#$params.Add("pageSize",10) #!!!
#$params.Add("pageSize",5) #!!!
}
elseif($SingleObject -ne $true -and $SinglePage -ne $true)
{
@@ -1055,7 +1055,7 @@ function Get-GraphMetaData
$fi = [IO.FileInfo]$fileFullPath
$maxAge = (Get-Date).AddDays(-14)
if($fi.Exists -and ($fi.LastWriteTime -gt $maxAge -or $fi.CreationTime -gt $maxAge))
{
{
try
{
[xml]$global:metaDataXML = Get-Content $fi.FullName
@@ -1070,13 +1070,14 @@ function Get-GraphMetaData
$wc = New-Object System.Net.WebClient
$wc.Encoding = [System.Text.Encoding]::UTF8
$proxyURI = Get-ProxyURI
if($proxyURI)
{
$wc.Proxy = $proxyURI
}
try
{
if($proxyURI)
{
$wc.Proxy = [System.Net.WebProxy]::new($proxyURI)
}
[xml]$global:metaDataXML = $wc.DownloadString($url)
# Download to string and then use Save to format the XML output
$global:metaDataXML.Save($fi.FullName)
@@ -1090,6 +1091,16 @@ function Get-GraphMetaData
$wc.Dispose()
}
}
if(-not $global:metaDataXML -and $fi.Exists)
{
Write-Log "Using old version of Graph MetaData file" 2
try
{
[xml]$global:metaDataXML = Get-Content $fi.FullName
}
catch { }
}
}
}
@@ -1410,8 +1421,8 @@ function Start-GraphObjectExport
Write-Log "Start bulk export"
Write-Log "****************************************************************"
$tmpFolder = Expand-FileName (Get-XamlProperty $script:exportForm "txtExportPath" "Text")
Write-Log "Export root folder: $tmpFolder"
$script:exportRoot = Expand-FileName (Get-XamlProperty $script:exportForm "txtExportPath" "Text")
Write-Log "Export root folder: $script:exportRoot"
$global:AADObjectCache = $null
@@ -1425,10 +1436,11 @@ function Start-GraphObjectExport
$txtNameFilter = $global:txtExportNameFilter.Text.Trim()
Save-Setting "" "ExportNameFilter" $txtNameFilter
if($txtNameFilter) { Write-Log "Name filter: $txtNameFilter" }
try
{
$folder = Get-GraphObjectFolder $item.ObjectType (Get-XamlProperty $script:exportForm "txtExportPath" "Text") (Get-XamlProperty $script:exportForm "chkAddObjectType" "IsChecked") (Get-XamlProperty $script:exportForm "chkAddCompanyName" "IsChecked")
$folder = Get-GraphObjectFolder $item.ObjectType $script:exportRoot (Get-XamlProperty $script:exportForm "chkAddObjectType" "IsChecked") (Get-XamlProperty $script:exportForm "chkAddCompanyName" "IsChecked")
$folder = Expand-FileName $folder
@@ -2690,7 +2702,7 @@ function Add-GroupMigrationObject
if(-not $groupId) { return }
$path = Get-GraphMigrationTableFile $global:txtExportPath.Text
$path = Get-GraphMigrationTableFile $script:ExportRoot
if(-not $path) { return }
@@ -2731,7 +2743,7 @@ function Add-GraphMigrationObject
if(-not $objId) { return }
$path = Get-GraphMigrationTableFile $global:txtExportPath.Text
$path = Get-GraphMigrationTableFile $script:ExportRoot
if(-not $path) { return }
@@ -3072,7 +3084,7 @@ function Add-GraphDependencyObjects
$url = "$($url.Trim())&$($depObjectType.QUERYLIST.Trim())"
}
$depObjects = (Invoke-GraphRequest $url -ODataMetadata "none").Value
$depObjects = (Invoke-GraphRequest $url -ODataMetadata "none" -AllPages).Value
$arrDepObjects = @()
foreach($depObject in $depObjects)
{
@@ -3126,8 +3138,8 @@ function Export-GraphObjects
$objectType = $global:curObjectType
Write-Status "Export $($objectType.Title)"
$global:ExportRoot = (Get-XamlProperty $script:exportForm "txtExportPath" "Text")
$folder = Get-GraphObjectFolder $objectType $global:ExportRoot (Get-XamlProperty $script:exportForm "chkAddObjectType" "IsChecked") (Get-XamlProperty $script:exportForm "chkAddCompanyName" "IsChecked")
$script:ExportRoot = (Get-XamlProperty $script:exportForm "txtExportPath" "Text")
$folder = Get-GraphObjectFolder $objectType $script:ExportRoot (Get-XamlProperty $script:exportForm "chkAddObjectType" "IsChecked") (Get-XamlProperty $script:exportForm "chkAddCompanyName" "IsChecked")
$folder = Expand-FileName $folder
@@ -3158,7 +3170,7 @@ function Export-GraphObjects
}
Save-Setting "" "LastUsedFullPath" $folder
Save-Setting "" "LastUsedRoot" $global:ExportRoot
Save-Setting "" "LastUsedRoot" $script:ExportRoot
Write-Status ""
}
@@ -3466,14 +3478,14 @@ function Get-GraphBatchObjects
if($batchArr.Count -eq 0) { return }
$batchResults = (Invoke-GraphBatchRequest $batchArr $objectType.Title).body
$batchResults = @((Invoke-GraphBatchRequest $batchArr $objectType.Title).body)
if($batchResults.Count -ne ($objects.Count - $skipped))
if(($batchResults | measure).Count -ne ($objects.Count - $skipped))
{
Write-Log "Not all batch objects returned. Expected $($objects.Count - $skipped) but only got $($batchResults.Count)"
Write-Log "Not all batch objects returned. Expected $($objects.Count - $skipped) but only got $(($batchResults | measure).Count)"
}
if($objectType -and $batchResults.Count -gt 0)
if($objectType -and ($batchResults | measure).Count -gt 0)
{
$batchResultsTmp = $batchResults
$batchResults = Add-GraphObjectProperties $batchResultsTmp $objectType -property $objectType.ViewProperties
@@ -4397,7 +4409,7 @@ function Save-GraphObjectToFile
function Get-GraphObjectFile
{
param($obj, $objectType, $path)
$fileName = (Get-GraphObjectName $obj $objectType)
$fileName = (Get-GraphObjectName $obj $objectType).Trim('.')
if((Get-SettingValue "AddIDToExportFile") -eq $true -and $obj.Id)
{