Setting up a new identity system from scratch is so easy.. but we know that kinda never happens… we are always migrating from an old system to new or changing an existing system due to business changes.
We went through the same process whereby we went from an OpenLDAP (ODSEE) being our primary source to FIM/MIM pushing out to AD. We were syncing identities manually from ODSEE to AD via Perl scripts in the old days..
So after the original migration done we have a lot of identities in AD not joined to MIM i.e. Disconnectors as we know them. This was because as per our policy we always added / modified from ODSEE -> AD but never a delete. Thus it left a lot of users and groups in AD which never came across in the initial migration.
So once the migration was complete, the big mammoth task came to migrate the unknowns from AD -> MIM and then join the identities in AD.
Using few wonderful tools suite called Lithnet written by @RyanLNewington
NOTE: Always remember, my script are as-is and have lots of rules and logics specific to my environment and business needs. Its there to give a basic understanding on what can be done. You will obviously have to modify it for your environment and needs.
REQUIREMENTS
- Migrate AD Disconnectors to MIM Service
- Join them to AD
- Make sure no existing values are overwritten in AD like sAMAccountName, DN, DisplayName etc
- Make sure membership (member) is not lost. memberOf is not cared for atm as that will take care of itself (Point 4 below).
- Sync Engine SHOULD NOT be provisioning. Stop the syncs (not service itself)
LOGIC
I wrote two different scripts – one to migrate users and one to migrate groups. There are some things to note here
- We have our own business rules engine called ACMA to which we provision all our identities which then generates all the required attribute values according to our business rules. So you will see each object being written to both FIMService and ACMA DB (SQL). Do have a look at it.. Its powerful yet so simple… Must have…
- We have a unique ID which is pushed to all system called monashObjectID which is basically a random guid which is generated in ACMA DB. We use this to have a constant ID between all system and thus later helpful to join ID etc.
- Due to the above point, my script assumes that all objects in AD , if they have monashObjectID means they are connected to FIM/MIM. Thus, on reverse, if they don’t have it means they have to be migrated.
- Simplification of OUs: Due to our previous messy environment we have over 100-200 OU’s in AD where all these objects exist. In the new age, we have simplified it and MIM only manages 8-10 OU’s. Therefore according to the “Type” of the object being migrated they are moved to the respective new OU in AD prior to migration (you need rights to do so in AD if you migration account doesn’t so already). Again you can comment out the whole function if its not required.
- Groups gets tricky. As they can be member of another group and if they group doesn’t already exist in MIM, it will loose membership once imported, I decided to get around it by scripting a check that if the group has members and if all of those members have monashObjectID then dump them in a CSV file. Thus this migration is run multiple times.
- Create 1st batch of CSV for those groups who don’t have members or which all members exist in MIM (by checking their monashObjectID as that comes from MIM)
- Migrate them
- Export to AD – this will write out monashObjectID for the newly migrated groups
- Repeat step a-c till all are done.
USER MIGRATION SCRIPT
Will start will user migrations as they can be members of a group. Again remember, loads of logic for our environment.
CSV Requirements
The CSV requires the following fields
1 |
Name,Type,OrgUnit,Owners |
- Name: sAMAccountName of the user to be migrated
- Type: We have accounttypes in our environment like person / service / custom etc. Need to mention that (or modify code to remove it)
- OrgUnit: We need to mention an OrgUnit DisplayName for each user to which it belongs to (our environment specific again)
- Owners: This is to mention the owner / supervisor of the user. They are sAMAccountName of already existing users in MIM. They can be multiple with ; separating them.
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
Import-Module LithnetRMA Import-Module ACMAPS Set-ResourceManagementClient -BaseAddress "http://{FIMService-Address}:5725" Function CheckADObjectInFIM($monashobjectid, $objectclass) { try { $obj = Get-Resource -ObjectType $objectclass -AttributeName monashObjectID -AttributeValue $monashobjectid -AttributesToGet ObjectID return ($obj.ObjectID.Value) } catch { throw "Resource Not Found in FIMService" } } Function SearchACMAFSObject($fsobjectid) { $dbQuery = New-AcmaQuery -AttributeName fimServiceObjectID -Operator Equals -Value $fsobjectid $acmaobjectid = Get-AcmaObjects -DBQuery $dbQuery return ([guid]$acmaobjectid.objectId.Guid) } Function CreateACMAGroup($fsObjectID, $username, $idmExpiryDate, $samaccountname, $unixgid, $addn, $orgUnitFSObjectID, $ownerFSObjectID, $idmPreferredName, $idmSn, $adupn) { Connect-AcmaEngine Lithnet.acma localhost D:\madata\acma\acma-prod.acmax D:\MAData\acma\Logs\Add-ACMAAccount-$username.log Debug $acmaaccount = Add-AcmaObject -ObjectClass account $acmaaccount.fimServiceObjectID = [guid]$fsObjectID $acmaaccount.displayName = $username $acmaaccount.idmPreferredName = $idmPreferredName if ($idmSn) { $acmaaccount.idmSn = $idmSn } elseif ($idmPreferredName) { $acmaaccount.idmSn = $idmPreferredName } else { $acmaaccount.idmSn = $username } $acmaaccount.accountName = $samaccountname $acmaaccount.userPrincipalName = $adupn $acmaaccount.idmExpiryDate = $idmExpiryDate.ToUniversalTime() $acmaaccount.idmOrganizationalUnit = SearchACMAFSObject($orgUnitFSObjectID) $acmaaccount.owner = SearchACMAFSObject($ownerFSObjectID) switch ($UserType) { service { $acmaaccount.accountType = 'service' } custom { $acmaaccount.accountType = 'custom' } external { $acmaaccount.accountType = 'external' } test { $acmaaccount.accountType = 'test' } external-student { $acmaaccount.accountType = 'external-student' } default { Write-Warning “Account Type not found for $username .. Not migrating"; return } } $acmaaccount.monashADDN = $addn if ($unixgid) { $acmaaccount.unixgid = $unixgid } try { Write-Host "Creating ACMA Object" -ForegroundColor Cyan Save-AcmaObject $acmaaccount } catch { Write-Warning ("Unable to create person in ACMA:" + $_.Exception.Message) return } $acmaObject = Get-AcmaObject -ObjectType person -AttributeName accountName -AttributeValue $samaccountname $Global:acmaObjectsList += ,$acmaObject.ObjectID } Function CreateFIMServiceUser { $adUser = Get-ADUser -Filter {samaccountname -eq $username} -Properties * $Global:userADDN +=, $adUser.DistinguishedName $FSUser = New-Resource -ObjectType Person $FSUser.activationDisabled = $true $FSUser.accountType = $UserType $FSUser.idmPreferredName = $adUser.GivenName if ($adUser.Surname) { $FSUser.idmSn = $aduser.Surname } elseif ($adUser.GivenName) { $FSUser.idmSn = $aduser.GivenName } else { $FSUser.idmSn = $adUser.Name } $FSUser.DisplayName = $adUser.Name $FSUser.Description = $adUser.Description switch ($UserType) { service { $FSUser.idmExpiryDate = [dateTime]"9999-12-31" } default { $expirydate = (Get-Date).AddDays(730).ToUniversalTime() $FSUser.idmExpiryDate = $expirydate } } $FSUser.Domain = $env:USERDOMAIN if ($UserOwners) { foreach ($owner in $UserOwners) { $adObj = Get-ADObject -Filter {sAMAccountName -eq $owner} -Properties * if ($adObj.monashobjectid) { switch ($adObj.ObjectClass) { user { $objClass = "Person" } group { $objClass = "Group" } } try { $ownerObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $FSUser.Owner.Add($ownerObjectID) } catch { Write-Warning ("Unable to retrive Owner: $adObj and will loose its membership" + $_.Exception.Message) } } else { Write-Warning "Owner of AD Group not in I@M System: $adObj and will loose its membership" } } $FSUser.DisplayedOwner = $FSUser.Owner[0] } else { if ($env:USERDOMAIN -eq 'MONASH') { #Default Value for FIM PROD (Unknown Owner Role Account) Write-Warning "Setting Unknown Owner Account as Owner in PROD" $FSUser.Owner.Add("<GUID OF THE DEFAULT OWNER>") $FSUser.DisplayedOwner = "<GUID OF THE DEFAULT OWNER>" } } if ($UserOrgUnit) { try { $OrgUnitObjectID = Get-Resource organizationalUnit DisplayName "$UserOrgUnit" $FSUser.idmOrganizationalUnit = $OrgUnitObjectID.ObjectID.Value } catch { Write-Warning "$OwningOrgUnit not found in I@M.. Defaulting to IDS in PROD else will have OR9999 for other Env" if ($env:USERDOMAIN -eq 'MONASH') { $FSUser.idmOrganizationalUnit = "<GUID OF THE DEFAULT ORGUNIT>" } } } else { if ($env:USERDOMAIN -eq 'MONASH') { Write-Warning "OrgUnit not given in CSV.. Defaulting to IDS as Owning Org Unit in PROD" $FSUser.idmOrganizationalUnit = "<GUID OF THE DEFAULT ORGUNIT>" } } try { Write-Host "Creating FIMSerivce Person:” $FSUser.DisplayName -ForegroundColor Cyan Save-Resource $FSUser } catch { Write-Warning ("Unable to create person in FIMService:" + $_.Exception.Message) return } $fimServiceObject = Get-Resource -ObjectType Person -AttributeName DisplayName -AttributeValue $FSUser.DisplayName $Global:fimServiceObjectsList += ,$fimServiceObject.ObjectID if ($adUser.MemberOf) { foreach ($member in $adUser.MemberOf) { $adObj = Get-ADObject $member -Properties * if ($adObj.monashobjectid) { switch ($adObj.ObjectClass) { user { $objClass = "Person" } group { $objClass = "Group" } } try { $parentgroupObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $parentgroup = Get-Resource -ID $parentgroupObjectID -AttributesToGet ExplicitMember, DisplayName $parentgroup.ExplicitMember.Add($fimServiceObject.ObjectID.Value) | Out-Null Save-Resource $parentgroup Write-Host "Added person to its memberOf Group:" $parentgroup.DisplayName -ForegroundColor Cyan } catch { Write-Warning ("Unable to retrive memberOf Group: $adObj " + $_.Exception.Message) } } else { Write-Warning ("memberOf AD Group not in I@M System:" + $adObj.Name) } } } CreateACMAGroup ($fimServiceObject.ObjectID) ($fimServiceObject.DisplayName) ($fimServiceObject.idmExpiryDate) ($adUser.SamAccountName) ($adUser.gidNumber) ($adUser.DistinguishedName) ($fimServiceObject.idmOrganizationalUnit.Value)($fimServiceObject.DisplayedOwner.Value)($fimServiceObject.idmPreferredName)($fimServiceObject.idmSn)($adUser.UserPrincipalName) } Function SyncMIMObjects() { Write-Host "Disabling MRE Provisioning" -ForegroundColor Cyan Set-MVProvisioningRulesExtension -Enabled $false; write-host "Delta import FIMService MA" -ForegroundColor Cyan Start-ManagementAgent FIMService DI $count = 0 write-host "Sync group FIMService object" -ForegroundColor Cyan foreach ($item in $fimServiceObjectsList) { Get-CSObject -MA FIMService -DN $item.Value | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Sycned $count of" $fimServiceObjectsList.Count } write-host "Delta import ACMA MA" -ForegroundColor Cyan Start-ManagementAgent ACMA DI $count = 0 write-host "Sync group ACMA Object" -ForegroundColor Cyan foreach ($item in $acmaObjectsList) { Get-CSObject -MA ACMA -DN $item.Guid | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Sycned $count of" $acmaObjectsList.Count } write-host "Delta import MonashAD MA" -ForegroundColor Cyan Start-ManagementAgent MonashAD DI $count = 0 write-host "Joining AD Object" -ForegroundColor Cyan foreach ($item in $userADDN) { Get-CSObject -MA MonashAD -DN $item | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Joined $count of" $userADDN.Count } Write-Host "Enabled MRE Provisioning" -ForegroundColor Cyan Set-MVProvisioningRulesExtension -Enabled $true; $count = 0 Write-Host "Doing Full Provision Cycle" -ForegroundColor Cyan foreach ($item in $acmaObjectsList) { Get-CSObject -MA ACMA -DN $item.Guid | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Provisioned $count of" $acmaObjectsList.Count } write-host "Clearing Full Sync Warnings" -ForegroundColor Cyan Clear-FullSyncWarning Write-Host "DONE!!!" -ForegroundColor Cyan } Function CheckUserInAD { try { $adUser = Get-ADUser -filter {samaccountname -eq $username} -Properties monashobjectid } catch { Write-Warning -Message "User not found in AD: $username" return; } if ($adUser.monashobjectid) { write-warning "User $username has a monashobjectid Might already exist in I@M.. Exiting" return; } Write-Host "User Found in AD: $username" -ForegroundColor Cyan CreateFIMServiceUser } Function MoveADUsers { try { $domain = (Get-ADDomain).DistinguishedName switch ($UserType) { service { $targetOU = "OU=ServiceAccounts,OU=Accounts,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName } custom { $targetOU = "OU=OtherAccounts,OU=Accounts,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName } external { $targetOU = "OU=External,OU=Accounts,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName } test { $targetOU = "OU=TestAccounts,OU=Accounts,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName } external-student { $targetOU = "OU=External,OU=Accounts,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName } default { Write-Warning "Group Type not found for $username .. Not migrating"; break } } $currentDN = (Get-ADUser -Filter {samaccountname -eq $username}).DistinguishedName $currentOU = $currentDN.Substring($currentDN.IndexOf("OU=")) if ($currentOU -ne $targetOU) { Move-ADObject $currentDN -TargetPath $targetOU Write-Host "Moved $username to" $targetOU -ForegroundColor Yellow } else { Write-Host "$username already in" $targetOU -ForegroundColor Green } } catch { Write-Error "Unable to move Group" + $_.Exception.Message return } } Function Get-File($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = "CSV (*.csv)| *.csv" $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.filename } function MigrateADUsers { $ServiceStatus = (Get-Service miisautosync).Status if ($ServiceStatus -ne "Stopped") { Write-Warning "Autosync still running. Make sure Autosync is stopped and no MA are running any profiles" exit } $inputFile = Get-File $users = Import-Csv $inputFile $leaf = Split-Path $inputFile -Leaf Start-Transcript -Path D:\ADUserMigration-$leaf.log -Append foreach ($item in $users) { $Global:username = $item.Name.Trim() $Global:UserType = $item.Type.Trim() $Global:UserOrgUnit = $item.OrgUnit.Trim() $Global:UserOwners = $item.Owners.Split(";").Trim() try { if (!$UserType) { Write-Warning "Group $username is missing Type in CSV.. Not Migrating" continue } MoveADUsers CheckUserInAD } catch { write-host "An error occurred with $username"; } } if ($fimServiceObjectsList) { SyncMIMObjects } } $acmaObjectsList = @() $fimServiceObjectsList = @() $userADDN = @() Measure-Command { MigrateADUsers } Stop-Transcript |
Rundown
- Script records everything via transcript command so you can set and forget, come back later and see what broke or potentially could break (loss of membership my main concern). Saves it to D:\ADUserMigration-{CSVFileName}.log
- Asks for CSV file on run.
- If the “Type” is missing in CSV it will skip that user (MUST in our logic)
- Moves the account to respective OU in AD as per the account type.
- Checks if the user doesn’t have monashObjectID – thus good to migrate.
- Creates the object in FIMService using LithnetRMA
- Depending on the type either we set expiry date to never (9999-12-31) or two years from date of migration
- Checks the owner if its a person or a group and then looks it up if it exits in MIM and adds it as owner.
- If no owner then we set a default account we have as owner
- Checks OrgUnit and if found it adds it to the object else sets a default OrgUnit.
- Checks if the memberOf exists in MIM and adds the user to those groups in MIM.
- Creates the object in ACMA
- Repeats the steps above for all users in the CSV
- Sync the identities in MIM via MIIS Powershell
- Disables MRE Provisioning
- DI the FIMService
- DS / Commit just the ones which were migrated into MV (as its prod others could come in from Portal which needs MRE rules and thus excluding them)
- DI ACMA MA
- DS / Commit just the ones which were migrated into MV – this should join them due to our join rules looking for same fimserviceobjectID which was written to ACMA DB during create
- DI AD MA – all moved objects will now show in correct OU in CS
- DS / Commit just the ones which were migrated into MV – this will join due to our join rules looking for same sAMAccountName.
- Enable provisioning
- DS all of them again to make sure MRE rules apply to those objects for any provisioning if required.
Done..
Speed
Can’t remember to be honest but was quite quick (had nearly none to do for accounts)
GROUP MIGRATION SCRIPT
Remember, loads of logic for our environment.
CSV Requirements
The CSV requires the following fields
1 |
Name,Type,ServiceID,Owners,OrgUnit |
- Name: sAMAccountName of the group to be migrated
- Type: We have account types in our environment like UserGroup / ServiceManagedGroup / IdMAuthZGroup etc. Need to mention that (or modify code to remove it)
- ServiceID: For our environment – mandatory.
- Owners: This is to mention the owner / supervisor of the user. They are sAMAccountName of already existing users in MIM. They can be multiple with ; separating them.
- OrgUnit: We need to mention an OrgUnit DisplayName for each user to which it belongs to (our environment specific again.
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
Import-Module LithnetRMA Import-Module ACMAPS Set-ResourceManagementClient -BaseAddress "http://{FIMService-Address}:5725" Function CheckADObjectInFIM($monashobjectid, $objectclass) { try { $obj = Get-Resource -ObjectType $objectclass -AttributeName monashObjectID -AttributeValue $monashobjectid -AttributesToGet ObjectID return ($obj.ObjectID.Value) } catch { throw "Resource Not Found in FIMService" } } Function CreateACMAGroup($fsObjectID, $groupName, $idmExpiryDate, $samaccountname, $unixgid, $addn) { Connect-AcmaEngine Lithnet.acma localhost D:\madata\acma\acma-prod.acmax D:\MAData\acma\Logs\Add-ACMAGroup-$groupName.log Debug $acmagroup = Add-AcmaObject -ObjectClass group $acmagroup.fimServiceObjectID = [guid]$fsObjectID $acmagroup.displayName = $groupName $acmagroup.accountName = $samaccountname $acmagroup.idmExpiryDate = $idmExpiryDate.ToUniversalTime() if ($GroupType -eq "UserGroup") { $acmagroup.accountType = "UserGroup" } if ($GroupType -eq "ServiceManagedGroup") { $acmagroup.accountType = "ServiceManagedGroup" } $acmagroup.monashADDN = $addn $acmagroup.groupScope = "Global" $acmagroup.groupType = "Security" if ($unixgid) { $acmagroup.unixgid = $unixgid } try { Write-Host "Creating ACMA Object" -ForegroundColor Cyan Save-AcmaObject $acmagroup } catch { Write-Warning ("Unable to create group in ACMA:" + $_.Exception.Message) return } $acmaObject = Get-AcmaObject -ObjectType group -AttributeName accountName -AttributeValue $groupName $Global:acmaObjectsList += ,$acmaObject.ObjectID } Function CreateFIMServiceGroup($groupname) { $adgroup = Get-ADGroup -filter {samaccountname -eq $groupname} -Properties * $Global:groupDN +=, $adgroup.DistinguishedName $group = New-Resource -ObjectType Group $group.activationOrNotificationMailSent = $true $group.DisplayName = $adgroup.Name $group.Description = $adgroup.Description switch ($groupType) { UserGroup { $expirydate = (Get-Date).AddDays(730).ToUniversalTime() $group.idmExpiryDate = $expirydate $group.accountType = "UserGroup" } ServiceManagedGroup { $group.idmExpiryDate = [dateTime]"9999-12-31" $group.accountType = "ServiceManagedGroup" $group.serviceID = $ServiceID } IdMAuthZGroup { $group.idmExpiryDate = [dateTime]"9999-12-31" $group.accountType = "IdMAuthZGroup" } default { $warning = "GroupType not found for " + $groupname Write-Warning $warning return } } $group.Type = "Security" $group.Domain = $env:USERDOMAIN $group.MembershipLocked = $false $group.Scope = 'Global' $group.MembershipAddWorkflow = "None" if ($Owners) { $ownercount = 0 foreach ($owner in $Owners) { $adObj = Get-ADObject -Filter {samaccountname -eq $owner} -Properties * if ($adObj.monashobjectid) { switch ($adObj.ObjectClass) { user { $objClass = "Person" } group { $objClass = "Group" } } try { $ownerObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $group.Owner.Add($ownerObjectID) $ownercount++ } catch { Write-Warning ("Unable to retrive Owner: $adObj and will loose its membership" + $_.Exception.Message) } } else { Write-Warning "Owner of AD Group not in I@M System: $adObj and will loose its membership" $ownercount++ } Write-Host "Done Owners: $ownercount of" $Owners.Count } $group.DisplayedOwner = $group.Owner[0] } else { if ($env:USERDOMAIN -eq 'MONASH') { Write-Warning "Setting Unknown Owner Account as Owner in PROD" #Default Value for FIM PROD (Unknown Owner Role Account) $group.Owner.Add("<GUID OF THE DEFAULT OWNER>") $group.DisplayedOwner = "<GUID OF THE DEFAULT OWNER>" } } if ($OwningOrgUnit) { try { $OrgUnitObjectID = Get-Resource organizationalUnit DisplayName "$OwningOrgUnit" $group.idmOrganizationalUnit = $OrgUnitObjectID.ObjectID.Value } catch { Write-Warning "$OwningOrgUnit not found in I@M.. Defaulting to IDS in PROD else will have OR9999 for other Env" if ($env:USERDOMAIN -eq 'MONASH') { $group.idmOrganizationalUnit = "<GUID OF THE DEFAULT ORGUNIT>" } } } else { if ($env:USERDOMAIN -eq 'MONASH') { $group.idmOrganizationalUnit = "<GUID OF THE DEFAULT ORGUNIT>" } } if ($adgroup.member) { $memberscount = 0 foreach ($member in $adgroup.member) { $adObj = Get-ADObject "$member" -Properties * switch ($adObj.ObjectClass) { computer { try { $fimComputerObjID = Get-Resource -ObjectType computer -AttributeName DisplayName -AttributeValue $adobj.Name -AttributesToGet ObjectID if ($fimComputerObjID.ObjectID.Value) { $group.ExplicitMember.Add($fimComputerObjID.ObjectID.Value) | Out-Null $memberscount++ } } catch { Write-Warning ("Unable to retrive computer in FIMService: $adObj will loose its membership") $memberscount++ } } user { $objClass = "Person" try { $memberObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $group.ExplicitMember.Add("$memberObjectID") | Out-Null $memberscount++ } catch { Write-Warning ("Unable to retrive user in FIMService: $adObj and will loose its membership") $memberscount++ } } group { $objClass = "Group" try { $memberObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $group.ExplicitMember.Add("$memberObjectID") | Out-Null $memberscount++ } catch { Write-Warning ("Unable to retrive group in FIMService: $adObj and will loose its membership") $memberscount++ } } deafult { Write-Warning ("This Objectclass of memeber $adObj is not catered for migration" + $adObj.ObjectClass) $memberscount++ } } Write-Host "Done Member: $memberscount of" $adgroup.member.Count } } try { Write-Host "Creating FIMSerivce Group:" $group.DisplayName -ForegroundColor Cyan Save-Resource $group } catch { Write-Warning ("Unable to create group in FIMService:" + $_.Exception.Message) return } $fimServiceObject = Get-Resource -ObjectType Group -AttributeName DisplayName -AttributeValue $group.DisplayName $Global:fimServiceObjectsList += ,$fimServiceObject.ObjectID if ($adgroup.MemberOf) { $memberofcount = 0 foreach ($member in $adgroup.MemberOf) { $adObj = Get-ADObject "$member" -Properties * if ($adObj.monashobjectid) { switch ($adObj.ObjectClass) { user { $objClass = "Person" } group { $objClass = "Group" } } try { $parentgroupObjectID = CheckADObjectInFIM ($adObj.monashobjectid) ($objClass) $parentgroup = Get-Resource -ID $parentgroupObjectID -AttributesToGet ExplicitMember, DisplayName $parentgroup.ExplicitMember.Add($fimServiceObject.ObjectID.Value) | Out-Null $memberofcount++ Save-Resource $parentgroup Write-Host "Added group to its memberOf Group:" $parentgroup.DisplayName -ForegroundColor Cyan } catch { Write-Warning ("Unable to retrive memberOf Group: $adObj " + $_.Exception.Message) $memberofcount++ } } else { Write-Warning ("memberOf AD Group not in I@M System:" + $adObj.Name) $memberofcount++ } Write-Host "Done memberOf: $memberofcount of" $adgroup.MemberOf.Count } } CreateACMAGroup ($fimServiceObject.ObjectID) ($fimServiceObject.DisplayName) ($fimServiceObject.idmExpiryDate) ($adgroup.SamAccountName) ($adgroup.gidNumber) ($adgroup.DistinguishedName) } Function SyncMIMObjects() { Write-Host "Disabling MRE Provisioning" -ForegroundColor Cyan Set-MVProvisioningRulesExtension -Enabled $false; write-host "Delta import FIMService MA" -ForegroundColor Cyan Start-ManagementAgent FIMService DI $count = 0 write-host "Sync group FIMService object" -ForegroundColor Cyan foreach ($item in $fimServiceObjectsList) { Get-CSObject -MA FIMService -DN $item.Value | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Synced $count of" $fimServiceObjectsList.Count } write-host "Delta import ACMA MA" -ForegroundColor Cyan Start-ManagementAgent ACMA DI $count = 0 write-host "Sync group ACMA Object" -ForegroundColor Cyan foreach ($item in $acmaObjectsList) { Get-CSObject -MA ACMA -DN $item.Guid | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Sycned $count of" $acmaObjectsList.Count } write-host "Delta import MonashAD MA" -ForegroundColor Cyan Start-ManagementAgent MonashAD DI $count = 0 write-host "Joining AD Object" -ForegroundColor Cyan foreach ($item in $groupDN) { Get-CSObject -MA MonashAD -DN $item | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Joined $count of" $groupDN.Count } Write-Host "Enabled MRE Provisioning" -ForegroundColor Cyan Set-MVProvisioningRulesExtension -Enabled $true; $count = 0 Write-Host "Provisioning to LDS" -ForegroundColor Cyan foreach ($item in $acmaObjectsList) { Get-CSObject -MA ACMA -DN $item.Guid | Sync-CSObject -Commit | Out-Null $count++ Write-Host "Provisioned $count of" $acmaObjectsList.Count } write-host "Clearing Full Sync Warnings" -ForegroundColor Cyan Clear-FullSyncWarning Write-Host "DONE!!!" -ForegroundColor Cyan } Function MigrateADGroup($groupName) { try { $group = Get-ADGroup -filter {samaccountname -eq $groupname} -Properties monashobjectid } catch { Write-Warning -Message "Group not found in AD: $groupname" return; } if ($group.monashobjectid) { write-warning "Group ($groupname) has a monashobjectid Might already exist in I@M.. Exiting" return; } Write-Host "Group Found in AD: $groupname" -ForegroundColor Cyan CreateFIMServiceGroup($groupname) } Function MoveADGroup($groupname) { try { $domain = (Get-ADDomain).DistinguishedName $targetOU = "OU=Public,OU=Groups,OU=IdM Managed Objects," + (Get-ADDomain).DistinguishedName $currentDN = (Get-ADGroup -filter {samaccountname -eq $groupname}).DistinguishedName $currentOU = $currentDN.Substring($currentDN.IndexOf("OU=")) if ($currentOU -ne $targetOU) { Move-ADObject $currentDN -TargetPath $targetOU Write-Host "Moved $groupname to" $targetOU -ForegroundColor Yellow } else { Write-Host "$groupname already in" $targetOU -ForegroundColor Green } } catch { Write-Error "Unable to move Group" + $_.Exception.Message return } } Function Get-File($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = "CSV (*.csv)| *.csv" $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.filename } function MigrateADGroups { $ServiceStatus = (Get-Service miisautosync).Status if ($ServiceStatus -ne "Stopped") { Write-Warning "Autosync still running. Make sure Autosync is stopped and no MA are running any profiles" exit } $counter = 0 $inputFile = Get-File $groups = Import-Csv $inputFile $leaf = Split-Path $inputFile -Leaf Start-Transcript -Path D:\ADGroupMigration-$leaf.log -Append foreach ($item in $groups) { $groupname = $item.Name.Trim() $Global:GroupType = $item.Type.Trim() $Global:ServiceID = $item.ServiceID.Trim() $Global:Owners = $item.Owners.Split(";").Trim() $Global:OwningOrgUnit = $item.OrgUnit.Trim() $counter++ try { if ($GroupType -eq "ServiceManagedGroup" -and (!$ServiceID)) { Write-Warning "Group $groupname is a ServiceManagedGroup but does not have a ServiceID in CSV.. Not Migrating" continue } MoveADGroup($groupname) MigrateADGroup($groupname) } catch { write-host "An error occurred with $groupname"; } Write-Host "Done $counter of" $groups.Count -ForegroundColor Red } if ($fimServiceObjectsList) { SyncMIMObjects } } $acmaObjectsList = @() $fimServiceObjectsList = @() $groupDN = @() Measure-Command { MigrateADGroups } Stop-Transcript |
Rundown
- Script records everything via transcript command so you can set and forget, come back later and see what broke or potentially could break (loss of membership my main concern). Saves it to D:\ADGroupMigration-{CSVFileName}.log
- Asks for CSV file on run.
- If the “serviceID” is missing in CSV for a ServiceManagedGroup it will skip that user (MUST in our logic)
- Moves the group to respective OU in AD as per the account type.
- Checks if the group doesn’t have monashObjectID – thus good to migrate.
- Creates the object in FIMService using LithnetRMA
- Depending on the type either we set expiry date to never (9999-12-31) or two years from date of migration
- Sets all as Security and Global groups.
- Checks the owner if its a person or a group and then looks it up if it exits in MIM and adds it as owner.
- If no owner then we set a default account we have as owner
- Checks OrgUnit and if found it adds it to the object else sets a default OrgUnit.
- Checks each member of the group and if they exist then adds them – else will spit out a warning that they will loose membership in AD (good to have logs eh?)
- Checks if the memberOf exists in MIM and adds the user to those groups in MIM.
- Creates the object in ACMA
- Repeats the steps above for all users in the CSV
- Sync the identities in MIM via MIIS Powershell
- Disables MRE Provisioning
- DI the FIMService
- DS / Commit just the ones which were migrated into MV (as its prod others could come in from Portal which needs MRE rules and thus excluding them)
- DI ACMA MA
- DS / Commit just the ones which were migrated into MV – this should join them due to our join rules looking for same fimserviceobjectID which was written to ACMA DB during create
- DI AD MA – all moved objects will now show in correct OU in CS
- DS / Commit just the ones which were migrated into MV – this will join due to our join rules looking for same sAMAccountName.
- Enable provisioning
- DS all of them again to make sure MRE rules apply to those objects for any provisioning if required.
Done..
Speed
This has varied for me. It really depends on number of members for the group.. about 3-5 groups / min .. I did about 1500 groups with 90% of them having 0-10 members but the last few having upto 1100 members in 6.5 hrs.
Hopefully this will help someone and see what can be done by combination of various tools out there.
0 Comments