This commit is contained in:
Mikael Karlsson
2022-11-22 21:54:51 +11:00
parent 2dc5eca089
commit 897309e48e
21 changed files with 368 additions and 2258 deletions

View File

@@ -11,7 +11,7 @@ Objects can be compared based on Properties or Documentatation info.
function Get-ModuleVersion
{
'1.0.9'
'1.0.10'
}
function Invoke-InitializeModule
@@ -422,8 +422,8 @@ function Invoke-BulkCompareNamedObjects
Write-Log "Compare $($item.ObjectType.Title) objects"
Write-Log "----------------------------------------------------------------"
$graphObjects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
[array]$graphObjects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
$nameProp = ?? $item.ObjectType.NameProperty "displayName"
foreach($graphObj in ($graphObjects | Where { $_.Object."$($nameProp)" -imatch [regex]::Escape($sourcePattern) }))
@@ -561,7 +561,7 @@ function Start-BulkCompareExportObjects
{
Save-Setting "" "LastUsedFullPath" $folder
$graphObjects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
[array]$graphObjects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
foreach ($fileObj in @(Get-GraphFileObjects $folder -ObjectType $item.ObjectType))
{

View File

@@ -1,6 +1,6 @@
function Get-ModuleVersion
{
'1.0.1'
'1.0.2'
}
function Invoke-InitializeModule
@@ -106,7 +106,7 @@ function Start-BulkCopyObjects
Write-Log "Copy $($item.ObjectType.Title) objects"
Write-Log "----------------------------------------------------------------"
$graphObjects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
[array]$graphObjects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
$nameProp = ?? $item.ObjectType.NameProperty "displayName"

View File

@@ -3,7 +3,7 @@
#https://docs.microsoft.com/en-us/office/vba/api/overview/word
function Get-ModuleVersion
{
'1.3.0'
'1.4.0'
}
function Invoke-InitializeModule
@@ -610,6 +610,7 @@ function Invoke-WordProcessItem
$settingProps += ("Settings." + $objProp)
}
}
$params.Add("AddCategories", $true)
}
else
{
@@ -649,6 +650,7 @@ function Invoke-WordProcessItem
if($fi.Exists)
{
$script:doc.Application.Selection.InlineShapes.AddOLEObject("",$fi.FullName,$false,$true,"$($env:WinDir)\System32\Notepad.exe",0,$fi.Name)
$script:doc.Application.Selection.TypeParagraph()
try { $fi.Delete() } catch {} # Cleanup
}
}
@@ -666,12 +668,18 @@ function Set-DocTableSettingsItems
$secondColumn = $firstColumn + 1
$script:docTable.Cell(1, $firstColumn).Range.Text = (Invoke-WordTranslateColumnHeader "Settings")
$script:docTable.Cell(1, $firstColumn).Range.Text = (Invoke-DocTranslateColumnHeader "Settings")
$script:docTable.Cell(1, $secondColumn).Range.Text = ""
$row = 2
foreach($itemObj in $items)
{
#if($script:docTable.Rows($row).Cells.Count -eq 1) { $row++;continue } # Category / Sub-category
while($script:docTable.Cell($row,1).Next.RowIndex -gt $row)
{
# Category / Sub-category
$row++;
}
$script:docTable.Cell($row, $firstColumn).Range.Text = ""
$script:docTable.Cell($row, $secondColumn).Range.Text = ""
$script:docTable.Cell($row, $firstColumn).Split($properties.Count,1)
@@ -680,7 +688,7 @@ function Set-DocTableSettingsItems
$cellRow = $row
foreach($settingProp in $properties)
{
$script:docTable.Cell($cellRow, $firstColumn).Range.Text = (Invoke-WordTranslateColumnHeader ($settingProp.Split('.')[-1]))
$script:docTable.Cell($cellRow, $firstColumn).Range.Text = (Invoke-DocTranslateColumnHeader ($settingProp.Split('.')[-1]))
$propArr = $settingProp.Split('.')
$tmpObj = $itemObj
@@ -690,7 +698,8 @@ function Set-DocTableSettingsItems
$tmpObj = $tmpObj."$($propArr[$x])"
}
$script:docTable.Cell($cellRow, $secondColumn).Column.Cells($cellRow).Range.Text = "$($tmpObj.$propName)"
#$script:docTable.Cell($cellRow, $secondColumn).Column.Cells($cellRow).Range.Text = "$($tmpObj.$propName)"
$script:docTable.Cell($cellRow, $secondColumn).Range.Text = "$($tmpObj.$propName)"
$cellRow++
}

View File

@@ -11,7 +11,7 @@ This module is for the Endpoint Manager/Intune View. It manages Export/Import/Co
#>
function Get-ModuleVersion
{
'3.7.3'
'3.7.4'
}
function Invoke-InitializeModule
@@ -141,6 +141,7 @@ function Invoke-InitializeModule
API = "/identityGovernance/termsOfUse/agreements"
Permissons=@("Agreement.ReadWrite.All")
PreImportCommand = { Start-PreImportTermsOfUse @args }
PostExportCommand = { Start-PostExportTermsOfUse @args }
GroupId = "ConditionalAccess"
})
}
@@ -166,6 +167,7 @@ function Invoke-InitializeModule
PostListCommand = { Start-PostListEndpointSecurity @args }
PostExportCommand = { Start-PostExportEndpointSecurity @args }
PostFileImportCommand = { Start-PostFileImportEndpointSecurity @args }
PostGetCommand = { Start-PostGetEndpointSecurity @args }
#PreCopyCommand = { Start-PreCopyEndpointSecurity @args }
PostCopyCommand = { Start-PostCopyEndpointSecurity @args }
PreUpdateCommand = { Start-PreUpdateEndpointSecurity @args }
@@ -254,6 +256,7 @@ function Invoke-InitializeModule
PreReplaceCommand = { Start-PreReplaceEnrollmentRestrictions @args } # Note: Uses same PreReplaceCommand as restrictions
PostReplaceCommand = { Start-PostReplaceEnrollmentRestrictions @args } # Note: Uses same PostReplaceCommand as restrictions
PreFilesImportCommand = { Start-PreFilesImportEnrollmentRestrictions @args } # Note: Uses same PreFilesImportCommand as restrictions
PreImportAssignmentsCommand = { Start-PreImportAssignmentsEnrollmentRestrictions @args } # Note: Uses same PreFilesImportCommand as restrictions
PostListCommand = { Start-PostListESP @args }
#PreUpdateCommand = { Start-PreUpdateEnrollmentRestrictions @args } # Note: Uses same PreUpdateCommand as restrictions
#QUERYLIST = "`$filter=endsWith(id,'Windows10EnrollmentCompletionPageConfiguration')"
@@ -277,6 +280,7 @@ function Invoke-InitializeModule
PostReplaceCommand = { Start-PostReplaceEnrollmentRestrictions @args }
PreFilesImportCommand = { Start-PreFilesImportEnrollmentRestrictions @args }
PostListCommand = { Start-PostListEnrollmentRestrictions @args }
PreImportAssignmentsCommand = { Start-PreImportAssignmentsEnrollmentRestrictions @args }
#PreUpdateCommand = { Start-PreUpdateEnrollmentRestrictions @args }
PropertiesToRemoveForUpdate = @('priority')
Permissons=@("DeviceManagementServiceConfig.ReadWrite.All")
@@ -448,6 +452,8 @@ function Invoke-InitializeModule
PreUpdateCommand = { Start-PreUpdateApplication @args }
PreImportCommand = { Start-PreImportCommandApplication @args }
DetailExtension = { Add-DetailExtensionApplications @args }
PreImportAssignmentsCommand = { Start-PreImportAssignmentsApplications @args }
PreDeleteCommand = { Start-PreDeleteApplications @args }
GroupId = "Apps"
ScopeTagsReturnedInList = $false
})
@@ -863,7 +869,7 @@ function Set-EMViewPanel
$global:btnLoadAllPages.add_click({
Write-Status "Loading $($global:curObjectType.Title) objects"
$graphObjects = @(Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -AllPages)
[array]$graphObjects = Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -AllPages
$graphObjects | ForEach-Object { $global:dgObjects.ItemsSource.AddNewItem($_) | Out-Null }
$global:dgObjects.ItemsSource.CommitNew()
Set-GraphPagesButtonStatus
@@ -873,7 +879,7 @@ function Set-EMViewPanel
$global:btnLoadNextPage.add_click({
Write-Status "Loading $($global:curObjectType.Title) objects"
$graphObjects = @(Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -SinglePage)
[array]$graphObjects = Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -SinglePage
$graphObjects | ForEach-Object { $global:dgObjects.ItemsSource.AddNewItem($_) | Out-Null }
$global:dgObjects.ItemsSource.CommitNew()
Set-GraphPagesButtonStatus
@@ -1000,17 +1006,19 @@ function Start-PostListEndpointSecurity
if(-not $script:baseLineTemplates) { return }
foreach($obj in $objList)
{
{
if(-not $obj.Object.templateId) { continue }
if($obj.Object.templateId -ne $baseLineTemplate.Id)
{
$baseLineTemplate = $script:baseLineTemplates | Where Id -eq $obj.Object.templateId
}
if($baseLineTemplate)
{
$obj | Add-Member -MemberType NoteProperty -Name "Type" -Value $baseLineTemplate.displayName
$obj | Add-Member -MemberType NoteProperty -Name "Category" -Value (?: ($baseLineTemplate.templateSubtype -eq "none") $baseLineTemplate.templateType $baseLineTemplate.templateSubtype)
}
}
$objList
}
@@ -1028,7 +1036,7 @@ function Start-PostExportEndpointSecurity
$settings = Invoke-GraphRequest -Url "$($objectType.API)/$($obj.id)/settings"
$settingsJson = "{ `"settings`": $((ConvertTo-Json $settings.value -Depth 20 ))`n}"
$fileName = "$path\$((Remove-InvalidFileNameChars $fileName))_Settings.json"
$settingsJson | Out-File -LiteralPath $fileName -Force
Save-GraphObjectToFile $settingsJson $fileName
}
function Start-PostFileImportEndpointSecurity
@@ -1039,7 +1047,7 @@ function Start-PostFileImportEndpointSecurity
if($settings)
{
Start-GraphPreImport $settings
Invoke-GraphRequest -Url "$($objectType.API)/$($obj.id)/updateSettings" -Body ($settings | ConvertTo-Json -Depth 20) -Method "POST"
Invoke-GraphRequest -Url "$($objectType.API)/$($obj.id)/updateSettings" -Body ($settings | ConvertTo-Json -Depth 50) -Method "POST"
}
}
@@ -1123,6 +1131,18 @@ function Start-PreUpdateEndpointSecurity
Remove-Property $obj "templateId"
}
function Start-PostGetEndpointSecurity
{
param($obj, $objectType)
Add-EndpointSecurityInfo $obj
}
function local:Add-EndpointSecurityInfo
{
param($obj, $baseLineTemplate = $null)
}
#endregion
#region
@@ -1133,7 +1153,7 @@ function Start-PostFileImportDeviceConfiguration
if($obj.'@OData.Type' -like "#microsoft.graph.windows10GeneralConfiguration")
{
$tmpObj = Get-Content -LiteralPath $importFile | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $importFile
if(($tmpObj.privacyAccessControls | measure).Count -gt 0)
{
@@ -1829,15 +1849,23 @@ function Start-PostFileImportApplications
{
param($obj, $objectType, $file)
$tmpObj = Get-Content -LiteralPath $file | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $file
if(-not ($obj.PSObject.Properties | Where Name -eq '@odata.type'))
{
# Add @odata.type property if it is missing. Required by app package import
$obj | Add-Member -MemberType NoteProperty -Name '@odata.type' -Value $objectType.'@odata.type'
}
$fi = [IO.FileInfo]$file
$tmpFilName = $fi.DirectoryName + "\" + $obj.FileName
if([IO.File]::Exists($tmpFilName) -eq $false)
{
$tmpFilName = $null
}
Start-ImportApp $obj
Start-ImportApp $obj $tmpFilName
}
function local:Start-ImportApp
@@ -1982,6 +2010,30 @@ function Add-DetailExtensionApplications
}
}
function Start-PreImportAssignmentsApplications
{
param($obj, $objectType, $file, $assignments)
if($obj.'@odata.type' -eq "#microsoft.graph.windowsMicrosoftEdgeApp")
{
foreach($assignment in $assignments)
{
Remove-Property $assignment.target "deviceAndAppManagementAssignmentFilterId"
Remove-Property $assignment.target "deviceAndAppManagementAssignmentFilterType"
}
@{"Assignments"=$assignments}
}
}
function Start-PreDeleteApplications
{
if($obj.'@odata.type' -eq "#microsoft.graph.microsoftStoreForBusinessApp")
{
# Don't delete Microsoft Store for Business Apps
@{ "Delete" = $false }
}
}
#endregion
#region Group Policy/Administrative Templates functions
@@ -2187,7 +2239,7 @@ function Start-PostExportAdministrativeTemplate
}
$fileName = "$path\$((Remove-InvalidFileNameChars $fileName))_Settings.json"
ConvertTo-Json $settings -Depth 20 | Out-File -LiteralPath $fileName -Force
Save-GraphObjectToFile $settings $fileName
}
function Start-PostCopyAdministrativeTemplate
@@ -2208,7 +2260,7 @@ function Start-PostFileImportAdministrativeTemplate
$settings = Get-EMSettingsObject $obj $objectType $file -settingsProperty "definitionValues" -SettingsArray
if($settings)
{
$tmpObj = (Get-Content -LiteralPath $file) | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $file
Import-GPOSetting $obj $settings -CustomADMX:($tmpObj.policyConfigurationIngestionType -eq "Custom")
}
@@ -2222,8 +2274,8 @@ function Start-LoadAdministrativeTemplate
$fi = [IO.FileInfo]$fileName
if($fi.Exists -eq $false) { return }
$obj = Get-Content -LiteralPath $fi.FullName | ConvertFrom-Json
$obj = Get-GraphObjectFromFile $fi.FullName
if($obj.definitionValues)
{
@@ -2234,7 +2286,7 @@ function Start-LoadAdministrativeTemplate
if([IO.File]::Exists($settingsFile))
{
$definitionValues = Get-Content -LiteralPath $settingsFile | ConvertFrom-Json
$definitionValues = Get-GraphObjectFromFile $settingsFile
$obj | Add-Member Noteproperty -Name "definitionValues" -Value $definitionValues -Force
}
@@ -2444,7 +2496,7 @@ function Start-PostExportRoleDefinitions
$fileName = "$path\$((Remove-InvalidFileNameChars $fileName)).json"
if([IO.File]::Exists($fileName))
{
$tmpObj = Get-Content -LiteralPath $fileName | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $fileName
}
else
{
@@ -2468,7 +2520,7 @@ function Start-PostExportRoleDefinitions
if($roleAssignmentsArr.Count -gt 0)
{
$tmpObj.RoleAssignments = $roleAssignmentsArr
$tmpObj | ConvertTo-Json -Depth 20 | Out-File -LiteralPath $fileName
Save-GraphObjectToFile $tmpObj $fileName
}
}
}
@@ -2485,7 +2537,7 @@ function Start-PostFileImportRoleDefinitions
{
param($obj, $objectType, $file)
$tmpObj = Get-Content -LiteralPath $file | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $file
$loadedScopeTags = $global:LoadedDependencyObjects["ScopeTags"]
if(($tmpObj.RoleAssignments | measure).Count -gt 0 -and ($loadedScopeTags | measure).Count -gt 0)
@@ -2551,7 +2603,7 @@ function Start-PostFileImportNotifications
{
param($obj, $objectType, $file)
$tmpObj = Get-Content -LiteralPath $file | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $file
foreach($localizedNotificationMessage in $tmpObj.localizedNotificationMessages)
{
@@ -2705,6 +2757,17 @@ function Start-PostListEnrollmentRestrictions
}
}
function Start-PreImportAssignmentsEnrollmentRestrictions
{
param($obj, $objectType, $file, $assignments)
if($obj.Priority -eq 0)
{
# Skip Assignment for Default Policy
@{ "Import" = $false }
}
}
#endregion
#region
@@ -2815,7 +2878,7 @@ function Save-EMDefaultPolicy
# Clean up from old version of the script that used the wrong name for Default policies
try { [IO.File]::Delete($oldFile) | Out-Null } Catch {}
}
$obj | ConvertTo-Json -Depth 20 | Out-File -LiteralPath "$path\$((Remove-InvalidFileNameChars $fileName)).json"
Save-GraphObjectToFile $obj "$path\$((Remove-InvalidFileNameChars $fileName)).json"
}
}
catch {}
@@ -2831,7 +2894,7 @@ function Get-EMSettingsObject
if($fi.Exists)
{
# Settings property removed during import so lets try exported file first
$tmpObj = (Get-Content -LiteralPath $fi.FullName) | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $fi.FullName
if($SettingsArray -eq $true)
{
# Only the an array of settings is expected
@@ -2855,9 +2918,8 @@ function Get-EMSettingsObject
{
Write-Log "Settings file '$($fiSettings.FullName)' was not found" 2
return
}
(Get-Content -LiteralPath $fiSettings.FullName) | ConvertFrom-Json
}
Get-GraphObjectFromFile $fiSettings.FullName
}
else
{
@@ -2880,7 +2942,7 @@ function Add-EMAssignmentsToExportFile
Write-Log "File not found: $fileName. Could not add assignments to file" 3
return
}
$tmpObj = Get-Content -LiteralPath $fileName | ConvertFrom-Json
$tmpObj = Get-GraphObjectFromFile $fileName
if(-not $url)
{
@@ -2897,7 +2959,7 @@ function Add-EMAssignmentsToExportFile
{
$tmpObj.Assignments = $assignments
}
ConvertTo-Json $tmpObj -Depth 20 | Out-File -LiteralPath $fileName -Force
Save-GraphObjectToFile $tmpObj $fileName
}
}
@@ -3094,12 +3156,32 @@ function Start-PreImportTermsOfUse
return
}
Write-Log "Add file data: $pdfFile"
$bytes = [IO.File]::ReadAllBytes($pdfFile)
$file.fileData = [PSCustomObject]@{
data = [Convert]::ToBase64String($bytes)
}
}
}
function Start-PostExportTermsOfUse
{
param($obj, $objectType, $path)
foreach($file in $obj.Files)
{
$url = "agreements/$($obj.id)/file/localizations('$($file.id)')/fileData/data"
$data = (Invoke-GraphRequest -Url $url -ODataMetadata "Minimal").Value
if($data)
{
Write-Log "Save file $($file.FileName)"
$fileName = "$path\$($file.FileName)"
[IO.File]::WriteAllBytes($fileName, [System.Convert]::FromBase64String($data))
}
}
}
#endregion
#region ADMXFiles
@@ -3174,7 +3256,6 @@ function Start-PreDeleteADMXFiles
@{ "Delete" = $false }
}
#nedregion
#endregion
Export-ModuleMember -alias * -function *

View File

@@ -10,7 +10,7 @@ This module manages Application objects in Intune e.g. uploading application fil
#>
function Get-ModuleVersion
{
'3.4.0'
'3.7.4'
}
#########################################################################################
@@ -362,21 +362,32 @@ function Send-IntuneFileToAzureStorage
$currentChunk = $chunk + 1
Write-Status "Uploading file to Azure Storage`n`nUploading chunk $currentChunk of $chunks ($(($currentChunk / $chunks*100))%)"
Write-Status "Uploading file to Azure Storage`n`nUploading chunk $currentChunk of $chunks ($(("{0:N2}" -f ($currentChunk / $chunks*100)))%)"
Write-AzureStorageChunk $sasUri $id $bytes
if((Write-AzureStorageChunk $sasUri $id $bytes) -eq $false)
{
Write-Log "Upload failed. Abourting..." 3
break
}
if ($currentChunk -lt $chunks -and $sasRenewalTimer.ElapsedMilliseconds -ge 450000)
{
Request-RenewAzureStorageUpload $fileUri
$sasRenewalTimer.Restart()
}
}
$reader.Close()
}
}
catch
{
Write-Log "Failed to send file to Intune. $($_.Exception.Message)" 3
}
finally
{
if ($reader -ne $null) { $reader.Dispose() }
if ($reader -ne $null)
{
$reader.Close()
$reader.Dispose()
}
}
# Finalize the upload.
@@ -443,15 +454,39 @@ function Write-AzureStorageChunk
$curProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
try
{
$response = Invoke-WebRequest $uri -Method Put -Headers $headers -Body $encodedBody
}
catch
{
Write-Log "Failed to upload file chunk. $($_.Exception.Message)" 3
}
$success = $false
$retryCount = 0
while($true)
{
try
{
$response = Invoke-WebRequest $uri -Method Put -Headers $headers -Body $encodedBody
if($retryCount -gt 0)
{
Write-Log "Chunk uploaded successfully"
}
$success = $true
break
}
catch
{
if($_.Exception.HResult -eq -2146233079 -and $retryCount -lt 6)
{
Write-Log "Failed to upload file chunk. Retry in 10 s" 2
$retryCount++
Start-Sleep -Seconds 10
}
else
{
Write-Log "Failed to upload file chunk. $($_.Exception.Message)" 3
break
}
}
}
$ProgressPreference = $curProgressPreference
$success
}
function Get-IntuneKey

View File

@@ -10,7 +10,7 @@ This module manages Authentication for the application with MSAL. It is also res
#>
function Get-ModuleVersion
{
'3.7.2'
'3.7.4'
}
$global:msalAuthenticator = $null
@@ -231,7 +231,7 @@ function Get-MSALUserInfo
$global:Me = $tmpMe
Write-Log "Get profile picture"
$global:profilePhoto = "$($env:LOCALAPPDATA)\CloudAPIPowerShellManagement\$($global:Me.Id).jpeg"
MSGraph\Invoke-GraphRequest "me/photos/48x48/`$value" -OutFile $global:profilePhoto -SkipAuthentication | Out-Null
MSGraph\Invoke-GraphRequest "me/photos/48x48/`$value" -OutFile $global:profilePhoto -SkipAuthentication -NoError | Out-Null
}
Write-Log "Get organization info"

View File

@@ -10,7 +10,7 @@ This module manages Microsoft Grap fuctions like calling APIs, managing graph ob
#>
function Get-ModuleVersion
{
'3.7.2'
'3.7.4'
}
$global:MSGraphGlobalApps = @(
@@ -451,7 +451,25 @@ function Invoke-GraphRequest
}
else
{
Write-LogError "Failed to invoke MS Graph with URL $Url (Request ID: $requestId). Status code: $($_.Exception.Response.StatusCode)" $_.Excption
$extMessage = $null
try
{
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$response = $reader.ReadToEnd() | ConvertFrom-Json
if($response.Error.Message)
{
$message = $response.Error.Message | ConvertFrom-Json
if($message.Message)
{
$extMessage = ". Response message: $($message.Message)"
}
}
}
catch{}
Write-LogError "Failed to invoke MS Graph with URL $Url (Request ID: $requestId). Status code: $($_.Exception.Response.StatusCode)$extMessage" $_.Excption
}
}
} while($retryRequest -eq $true)
@@ -559,21 +577,31 @@ function Get-GraphObjects
if($graphObjects -and ($graphObjects | GM -Name Value -MemberType NoteProperty))
{
$retObjects = $graphObjects.Value
$retObjects = $graphObjects.Value
}
else
{
$retObjects = $graphObjects
}
$graphObjects = Add-GraphObjectProperties $retObjects $objectType $property $exclude $SortProperty
if($SingleObject -ne $true -and $objectType.PostListCommand)
if($retObjects)
{
$graphObjects = & $objectType.PostListCommand $graphObjects $objectType
$graphObjects = Add-GraphObjectProperties $retObjects $objectType $property $exclude $SortProperty
if($SingleObject -ne $true -and $objectType.PostListCommand)
{
$graphObjects = & $objectType.PostListCommand $graphObjects $objectType
}
}
else
{
$graphObjects = $null
}
$graphObjects
if(($graphObjects | measure).Count -gt 0)
{
$graphObjects
}
}
function Add-GraphObjectProperties
@@ -693,12 +721,12 @@ function Show-GraphObjects
$script:nextGraphPage = $null
$graphObjects = @(Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -SinglePage -Filter $filter)
[array]$graphObjects = Get-GraphObjects -property $global:curObjectType.ViewProperties -objectType $global:curObjectType -SinglePage -Filter $filter
$dgObjects.AutoGenerateColumns = $false
$dgObjects.Columns.Clear()
if(($graphObjects | measure).Count -gt 0)
if($graphObjects)
{
$tmpObj = $graphObjects | Select -First 1
@@ -1335,7 +1363,7 @@ function Start-GraphObjectExport
$folder = Expand-FileName $folder
Write-Status "Get a list of all $($item.ObjectType.Title) objects" -SkipLog -Force
$objects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
[array]$objects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
if((Get-SettingValue "UseBatchAPI") -eq $true)
{
@@ -1345,6 +1373,7 @@ function Start-GraphObjectExport
$total = ($batchObjects | measure).Count
foreach($batchResult in $batchObjects)
{
if(-not $batchResult.Object) { continue }
$objName = Get-GraphObjectName $batchResult.Object $batchResult.ObjectType
Write-Status "Export $($item.Title): $objName ($($i)/$($total))" -Force
Export-GraphObject $batchResult.Object $batchResult.ObjectType $folder -IsFullObject
@@ -1621,7 +1650,7 @@ function Show-GraphImportForm
$navigationPropObjects = @()
foreach ($fileObj in $filesToImport)
{
if($allowUpdate -and $global:cbImportType.SelectedValue -ne "alwaysImport" -and (Reset-GraphObjet $fileObj $global:dgObjects.ItemsSource))
if($allowUpdate -and $global:cbImportType.SelectedValue -ne "alwaysImport" -and (Reset-GraphObject $fileObj $global:dgObjects.ItemsSource))
{
continue
}
@@ -1839,7 +1868,7 @@ function Start-GraphObjectImport
try
{
Write-Status "Get $($item.Title) objects" -Force
$graphObjects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
[array]$graphObjects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
}
catch {}
}
@@ -1864,7 +1893,7 @@ function Start-GraphObjectImport
continue
}
if($allowUpdate -and $global:cbImportType.SelectedValue -ne "alwaysImport" -and $graphObjects -and (Reset-GraphObjet $fileObj $graphObjects))
if($allowUpdate -and $global:cbImportType.SelectedValue -ne "alwaysImport" -and $graphObjects -and (Reset-GraphObject $fileObj $graphObjects))
{
$importedObjects++
continue
@@ -2048,7 +2077,7 @@ function Show-GraphBulkDeleteForm
Write-Log "Start bulk delete"
Write-Log "****************************************************************"
foreach($item in ($global:dgBulkDeleteObjects.ItemsSource | Where Selected -eq $true))
foreach($item in ($global:dgBulkDeleteObjects.ItemsSource | Where Selected -eq $true | sort-object -property @{e={$_.ObjectType.ImportOrder}} -Descending))
{
Write-Log "----------------------------------------------------------------"
Write-Log "Delete $($item.ObjectType.Title) objects"
@@ -2060,8 +2089,8 @@ function Show-GraphBulkDeleteForm
try
{
Write-Status "Get $($item.Title) objects" -Force
$objects = @(Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType)
Write-Status "Get $($item.ObjectType.Title) objects" -Force
[array]$objects = Get-GraphObjects -property $item.ObjectType.ViewProperties -objectType $item.ObjectType
foreach($obj in $objects)
{
$objName = Get-GraphObjectName $obj.Object $obj.ObjectType
@@ -2071,7 +2100,7 @@ function Show-GraphBulkDeleteForm
continue
}
Write-Status "Delete $($item.Title): $objName" -Force -SkipLog
Write-Status "Delete $($item.ObjectType.Title): $objName" -Force -SkipLog
Remove-GraphObject $obj.Object $obj.ObjectType $folder
}
}
@@ -2113,12 +2142,7 @@ function Get-GraphFileObjects
}
else
{
$json = Get-Content -LiteralPath $file.FullName -Raw
if($global:Organization.Id)
{
$json = $json -replace "%OrganizationId%",$global:Organization.Id
}
$graphObj = (ConvertFrom-Json $json)
$graphObj = Get-GraphObjectFromFile $file.FullName
}
$obj = New-Object PSObject -Property @{
@@ -2194,7 +2218,7 @@ function Import-GraphFile
}
}
function Reset-GraphObjet
function Reset-GraphObject
{
param($fileObj, $objectList)
@@ -2369,10 +2393,12 @@ function Import-GraphObjectAssignment
if($preConfig["Import"] -eq $false) { return } # Assignment managed manually so skip further processing
$api = ?? $preConfig["API"] "$($objectType.API)/$($newObj.Id)/assign"
$api = ?? $preConfig["API"] "$($objectType.API)/$($obj.Id)/assign"
$method = ?? $preConfig["Method"] "POST"
$clonedAssignments = ?? $preConfig["Assignments"] $clonedAssignments
$keepProperties = ?? $objectType.AssignmentProperties @("target")
$keepTargetProperties = ?? $objectType.AssignmentTargetProperties @("@odata.type","groupId","deviceAndAppManagementAssignmentFilterId","deviceAndAppManagementAssignmentFilterType")
@@ -2417,8 +2443,7 @@ function Import-GraphObjectAssignment
if($objectType.PostImportAssignmentsCommand)
{
& $objectType.PostImportAssignmentsCommand $obj $objectType $fromFile $objAssign
}
}
}
#endregion
@@ -2572,7 +2597,7 @@ function Add-GroupMigrationObject
if(-not $groupObj)
{
# Get group info
$groupObj = Invoke-GraphRequest "/groups/$groupId" -ODataMetadata "none"
$groupObj = Invoke-GraphRequest "/groups/$groupId" -ODataMetadata "none" -NoError
}
if($groupObj)
@@ -2587,9 +2612,13 @@ function Add-GroupMigrationObject
$grouspPath = Join-Path $path "Groups"
if(-not (Test-Path $grouspPath)) { mkdir -Path $grouspPath -Force -ErrorAction SilentlyContinue | Out-Null }
$fileName = "$grouspPath\$((Remove-InvalidFileNameChars $groupObj.displayName)).json"
ConvertTo-Json $groupObj -Depth 50 | Out-File $fileName -Force
Save-GraphObjectToFile $groupObj $fileName
}
}
else
{
Write-Log "No group found with ID $($groupId). It might be deleted." 2
}
}
function Add-GraphMigrationObject
@@ -2626,7 +2655,7 @@ function Add-GraphMigrationObject
$grouspPath = Join-Path $path "Groups"
if(-not (Test-Path $grouspPath)) { mkdir -Path $grouspPath -Force -ErrorAction SilentlyContinue | Out-Null }
$fileName = "$grouspPath\$((Remove-InvalidFileNameChars $graphObj.displayName)).json"
ConvertTo-Json $graphObj -Depth 50 | Out-File $fileName -Force
Save-GraphObjectToFile $graphObj $fileName
}
}
}
@@ -2769,7 +2798,7 @@ function Get-GraphMigrationObjectsFromFile
{
# ToDo: Create group from Json (could be a dynamic group)
# Warn if synched group
$groupObj = (Get-Content -LiteralPath $groupFi.FullName) | ConvertFrom-Json
$groupObj = Get-GraphObjectFromFile $groupFi.FullName
#isAssignableToRole - For Role assignment groupd.
$keepProps = @("displayName","description","mailEnabled","mailNickname","securityEnabled","membershipRule","groupTypes", "membershipRuleProcessingState")
@@ -3017,7 +3046,7 @@ function Export-GraphObject
[switch]$SkipAddID,
[switch]$PassThru)
if(-not $exportFolder) { return }
if(-not $exportFolder -or -not $objToExport -or -not $objectType) { return }
Write-Status "Export $((Get-GraphObjectName $objToExport $objectType))"
@@ -3057,14 +3086,7 @@ function Export-GraphObject
}
$fullPath = ([IO.Path]::Combine($exportFolder, (Remove-InvalidFileNameChars "$($fileName).json")))
$json = $obj | ConvertTo-Json -Depth 50
if($global:Organization.Id)
{
$json = $json -replace $global:Organization.Id, "%OrganizationId%"
}
$json | Out-File -LiteralPath $fullPath -Force
Save-GraphObjectToFile $obj $fullPath
if($objectType.PostExportCommand)
{
@@ -3097,12 +3119,11 @@ function Set-GraphNavigationPropertiesFromFile
}
# Reload data from file. Some object properties was removed before import...
$objFileInfo = (ConvertFrom-Json (Get-Content -LiteralPath $navPropObject.File.FileInfo.FullName -Raw))
$objFileInfo = Get-GraphObjectFromFile $navPropObject.File.FileInfo.FullName
if(-not ($objFileInfo.PSObject.Properties | Where { $_.Name -like "#CustomRef_*" })) { return }
Set-GraphNavigationProperties $navPropObject.ImportedObject $objFileInfo $navPropObject.File.ObjectType
}
function Set-GraphNavigationProperties
@@ -3264,6 +3285,7 @@ function Get-GraphBatchObjects
$batchArr = @()
$batchTotal = 0
$objectType = $null
foreach($obj in $objects)
{
$objectType = $obj.ObjectType
@@ -3460,7 +3482,11 @@ function Import-GraphObject
$newObj = (Invoke-GraphRequest -Url $strAPI -Content $json -HttpMethod $method @params)
if($newObj -and $method -eq "POST")
if($newObj -is [Boolean] -and $newObj -and $method -eq "PATCH")
{
$newObj = (Get-GraphObject -obj $obj -objectType $objectType -SkipAssignments).Object
}
elseif($newObj -and $method -eq "POST")
{
Write-Log "$($objectType.Title) object imported successfully with id: $($newObj.Id)"
}
@@ -4120,3 +4146,45 @@ function Get-GraphEntityTypeProperties
$properties
}
function Get-GraphObjectFromFile
{
param($fileName)
if(-not $fileName) { return }
if([System.IO.File]::Exists($fileName) -eq $false)
{
Write-LogDebug "File $fileName not found" 2
return
}
$json = Get-Content -LiteralPath $fileName -Raw
if($global:Organization.Id)
{
$json = $json -replace "%OrganizationId%",$global:Organization.Id
}
$json | ConvertFrom-Json
}
function Save-GraphObjectToFile
{
param($obj, $fileName)
$json = $obj | ConvertTo-Json -Depth 50
if($global:Organization.Id)
{
$json = $json -replace $global:Organization.Id, "%OrganizationId%"
}
try
{
$json | Out-File -LiteralPath $fileName -Force -ErrorAction Stop
}
catch
{
Write-LogError "Failed to save file $fileName" $_.Exception
}
}