We’re doing a AD migration soon, and I’m hoping to gather the users AD before/after information into one final hash table.
The logic I’m going with is gathering each user’s AD information prior to the actual migration in one hash table, then get their AD information again after they’re migrated, and hopefully join the two hashes together into one nice OGV.
The examples I’ve found on the 'net show more of combining hashes with like keys and unique values. I’m wanting to combine unique keys and unique values.
Can anyone offer any tips on how I might join the $userInfo and $newUserInfo hashes?
function Set-EADProperties { Import-Module ActiveDirectory $userADList = Get-ADUser -SearchBase "ou=example,dc=contoso,dc=com" -Properties Surname, DistinguishedName, GivenName, SamAccountName, Description, HomeDirectory, Department -Filter { Department -like "*IBD*" } | sort Surname $groupOfUsers = @() foreach ($individualUser in $userADList) { #Gather variables $samaccountName = $individualUser.samaccountname $distinguishedName = $individualUser.distinguishedName $firstName = $individualUser.GivenName $lastName = $individualUser.Surname $firstNameDotLastName = "$firstName.$LastName" $userInfo = [ordered]@{ LastName = $lastName FirstName = $firstName OldUserName = $individualUser.SamAccountname OldHomeDirectory = $individualUser.HomeDirectory } #rename samaccounts to rename fs12 folder name to match first.last, change samaccountname, displayname, and clear profile path attribute. #finally move to new OU if ($samAccountName -ne $firstNameDotLastName) { #Close open files Invoke-Command -ComputerName fileserver12 -ScriptBlock { openfiles /disconnect /a $using:samaccountName } #Do Work Get-ADUser $samAccountName | Set-ADUser -SamAccountName $firstNameDotLastName -DisplayName "$lastName, $firstname - ARS" -HomeDirectory $null -PassThru | Rename-ADObject -Identity $distinguishedName -NewName "$lastName, $firstname - ARS" | Move-ADObject -TargetPath "ou=new,ou=example,dc=contoso,dc=com" -WhatIf } Start-Sleep 15 $newuserADList = Get-ADUser -SearchBase "ou=new,ou=example,dc=contoso,dc=com" -Properties Surname, GivenName, SamAccountName, Description, HomeDirectory, Department -Filter { Department -like "*IBD*" } | sort Surname $newgroupOfUsers = @() foreach ($newindividualUser in $newuserADList) { #Gather variables $newsamaccountName = $newindividualUser.samaccountname $newfirstName = $newindividualUser.GivenName $newlastName = $newindividualUser.Surname $newfirstNameDotLastName = "$newfirstName.$newLastName" $newuserInfo = [ordered]@{ LastName = $newlastName FirstName = $newfirstName OldUserName = $newindividualUser.SamAccountname NewUserName = $newfirstNameDotLastName NewHomeDirectory = $newindividualUser.HomeDirectory } } #> } $groupOfUsers += New-Object -TypeName PSObject -Property $userInfo $newgroupOfUsers += New-Object -TypeName System.Management.Automation.PSObject -property $newuserInfo Get-ADUser -Properties DistinguishedName -filter * | where { $_.Surname -like $lastName -AND $_.GivenName -like $firstname } | Select Name, SamAccountName, DistinguishedName $groupOfUsers | ogv -Title "Old User Info" $newgroupOfUsers | ogv -Title "New User Info" }