Created
May 15, 2024 12:29
-
-
Save DanClowry/893b97b33805a17bd64f4b316e246412 to your computer and use it in GitHub Desktop.
Duplicate the IDs between two IntuneManager JSON exports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $true, | |
Position = 0, | |
HelpMessage = "Path to exported files from the tenant.")] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$TenantExportPath, | |
[Parameter(Mandatory = $true, | |
Position = 1, | |
HelpMessage = "Path to the policies you want to compare with.")] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$BaselinePath | |
) | |
$tenantExportFiles = Get-ChildItem $TenantExportPath -Recurse -Name | |
$baselineFiles = Get-ChildItem $BaselinePath -Recurse -Name | |
$diff = Compare-Object -ReferenceObject $tenantExportFiles -DifferenceObject $baselineFiles -ExcludeDifferent | |
foreach ($file in $diff) { | |
if ($file.InputObject.EndsWith(".json") -eq $false) { | |
continue | |
} | |
$baselineFilePath = Join-Path -Path $BaselinePath -ChildPath $file.InputObject | |
$baselineObj = Get-Content $baselineFilePath | ConvertFrom-Json | |
$tenantFilePath = Join-Path -Path $TenantExportPath -ChildPath $file.InputObject | |
$tenantObj = Get-Content $tenantFilePath | ConvertFrom-Json | |
$tenantObj.id = $baselineObj.id | |
$tenantObj | ConvertTo-Json -Depth 100 | Out-File -FilePath $tenantFilePath | |
Write-Host "Set $($file.InputObject) as $($baselineObj.id)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment