Update User attributes

Please provide some guidance and I have started learning powershell but something has been thrown at me and I haven’t reached upto that level yet.

We are in middle of domain/forest migration project and we have migrated all user accounts but noticed that some exchange related attributes are missing on user object because we didn’t buy migration licenses for exchange. We need to copy some exchange attributes (msExchMailboxGUID, msExchRecipientDisplayType, msExchRecepientTypeDetails and few more). We need to extract these attributes for all users (roughly 1100) and inject to migrated user account on new domain. Username is same on target domain and SIDhistory was migrated if it makes any difference.

Also how do I reveal remaining value for msExchMailboxGUID attributes? I have tried running below command in many formats (list, table) but some part of value are never shown.
Get-ADUser -identity User1 -properties * | Select msExchMailboxGUID
Generally the output is { 02 23 32 …}

Select-Object (aliased to Select as well) by default creates a new object with the selected property or properties. In order to extract the value of a property, you need to use the -ExpandProperty parameter:

Get-ADUser -Identity User1 -Properties MsExchMailboxGUID | Select-Object -ExpandProperty MsExchMailboxGUID

I can see that I can use various user properties using Set-ADuser command but not all properties are available this way. There is another forum which discusses how to set manager field by using -manager but there is nothing available for exchange parameters like msExchMailboxGUID, msExchRecipientDisplayType, msExchRecepientTypeDetails.

Thanks

You’ll have to set those with the -Add or -Replace parameters:

Set-ADUser -Identity "Joe Smith" -Add @{
    msExchMailboxGUID = $NewGUID
    msExchRecipitentDisplayType = $NewType
}
If you're not sure whether the properties will exist already, I'd opt for -Replace (the syntax is the same, just the parameter name changes).

I ran into other issue while using Explandproperty parameter.
Select-Object -ExpandProperty MsExchMailboxGUID
It creates an output in for each number in different line like below rather in one line and when I export it to CSV there is no output in the file.

60
239
253
60
33
229
210
70
151
19
46
117
41
144
94
23

Thanks Joel.

There is some behavior that changes the value when I run export to csv but when it is displayed on screen it shows correct values.

PS C:\Windows\system32> $Users = Get-ADUser -Filter * -SearchBase “OU=Temp,OU=Users,OU=Temp ,OU=temp,DC=abc,DC=com,DC=au” -Properties * | Select-Object Samaccountname, msexchmailboxguid
$string = $user.msexchmailboxguid
$bytes = [System.Text.Encoding]::Unicode.GetBytes($string)
$userguid = [System.Text.Encoding]::ASCII.GetString($bytes)
$users.samAccountName, $userguid | Format-List #| Export-Csv C:\temp\guid.csv
Test.Migration2
1 4 5 2 4 3 1 9 8 1 7 8 2 1 6 2 4 8 1 5 1 7 0 1 2 9 8 0 7 4 2 3 1 4 0 3 6 2 9 4 0

Output above is correct but when I export to csv here is what I get. Although I have to work on format to be able to use file to import values but the guid is completely different. I have checked properties in ADSI edit. It is neither hex,decimal or octal.

#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
“ClassId2e4f51ef21dd47e99d3c952918aff9cd”,“formatEntryInfo”,“outOfBand”,“writeStream”
“27c87ef9bbda4f709f6b4002fa4af63c”,“Microsoft.PowerShell.Commands.Internal.Format.RawTextFormatEntry”,“True”,“None”
“27c87ef9bbda4f709f6b4002fa4af63c”,“Microsoft.PowerShell.Commands.Internal.Format.RawTextFormatEntry”,“True”,“None”

I have also noticed that spacing between guid displayed on console is not correct as well.
1 4 5 2 4 3 1 9 8 1 7 8 2 1 6 2 4 8 1 5 1 7 0 1 2 9 8 0 7 4 2 3 1 4 0 3 6 2 9 4 0

It should be like
145 243 198 178 216 248 151 701 298 074 231 403 629 40

Tried this but output in file is still weird.

$Users = Get-ADUser -Filter * -SearchBase “OU=Temp,OU=Users,OU=Temp ,OU=temp,DC=abc,DC=com,DC=au” -Properties * | Select-Object Samaccountname, msexchmailboxguid
$string = $user.msexchmailboxguid
$line = [string]$string
$users.samAccountName, $line | Export-csv C:\temp\guid1.csv

Onscreen in separate lines.
Test.Migration2
145 243 198 178 216 248 151 70 129 80 74 231 40 36 29 40

In CSV.
#TYPE System.String
“Length”
“15”
“56”

I was able to get Mailbox Guid from Exchange shell. And now trying to inject MSExchMailboxGuid to user attrubute in new domain but getting error.

PS C:\Windows\system32> $guid = ‘23794e57-1369-4463-843d-56d3350146af’
PS C:\Windows\system32> Set-ADUser -Identity “test.migration2” -Add @{msExchMailboxGUID=$guid}
Set-ADUser : A value for the attribute was not in the acceptable range of values
At line:1 char:1

  • Set-ADUser -Identity “test.migration2” -Add @{msExchMailboxGUID=$guid …
  •   + CategoryInfo          : NotSpecified: (test.migration2:ADUser) [Set-ADUser], ADException
      + FullyQualifiedErrorId : ActiveDirectoryServer:8322,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Give this a go chap

$results = @()

foreach ($user in (Get-ADUser -Filter * -SearchBase 'OU=Users,OU=Company,DC=domain,DC=local' -Properties * | Where-Object {$_.msexchmailboxguid -ne $null})) {
    [System.Guid]$a = $user.msexchmailboxguid
    $member = New-Object -TypeName PSObject
    $member | Add-Member -MemberType NoteProperty -Name samAccountName -Value $user.samaccountname
    $member | Add-Member -MemberType NoteProperty -Name msExchMailboxGuid -Value $a
    $results += $member
}

$results | Select-Object samaccountname,msexchmailboxguid |  Export-Csv results.csv -NoTypeInformation

To Import the guids you’ll need to cast the type as a guid when using set-aduser to add them to the new domain.

Thanks Alex.
It worked exactly as I wanted.