Hello,
i need help to compare two hashtables:
Hashtable 1:
$replace = @{}
$replace['l'] = "Kempten"
$replace['Description'] ="Held des Tages"
$replace['sn'] = "Proper"
$replace['StreetAddress'] = "Landstrasse"
$replace['wWWHomePage'] = "www.google.de"
$replace['mail'] = "Test@contoso.com"
Hashtable 2
$props = Get-ADUser -Filter { DisplayName -eq "Meister Proper" } -Properties *
$propkey = @{ }
$propkey['l'] = $props.l
$propkey['Description'] = $props.Description
$propkey['sn'] = $props.sn
$propkey['StreetAddress'] = $props.StreetAddress
$propkey['wWWHomePage'] = $props.wWWHomepage
$propkey['mail'] = $props.mail
$output = $Replace| Out-String
Write-Host $output
$output2 = $propkey | Out-String
Write-Host $output2
compare $replace.Values $propkey.Values
Result:
Hashtable 1
Name Value
---- -----
Description Held des Tages
wWWHomePage www.google.de
mail Test@contoso.com
l Kempten
StreetAddress Landstrasse
sn Proper
Hashtable 2
Name Value
---- -----
Description wwww
wWWHomePage
mail MProper@kempten.de
l Kempten
StreetAddress
sn Proper
Compare-Result
InputObject SideIndicator
----------- -------------
{wwww, $null, MProper@kempten.de, Kempten...} =>
{Held des Tages, www.google.de, Test@contoso.com, Kempten...} <=
I need now the different between the hashtables as a new hashtable as example:
Key Value
l Kempten
Thx a lot.
Compare two hashtables
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Compare two hashtables
Use Compare-Object
https://technet.microsoft.com/en-us/lib ... 49941.aspx
https://technet.microsoft.com/en-us/lib ... 49941.aspx
- alwo23@hotmail.com
- Posts: 28
- Last visit: Tue Jun 06, 2023 2:43 am
Re: Compare two hashtables
Yes i know it, but i didnt have the result what i need.
I need a compare key by key and the different in a new hashtable with key an value filtert by SideIndicator.
I need a compare key by key and the different in a new hashtable with key an value filtert by SideIndicator.
- alwo23@hotmail.com
- Posts: 28
- Last visit: Tue Jun 06, 2023 2:43 am
Re: Compare two hashtables
Here is how to compare hash tables for all keys:
- $replace = @{
- l = "Kempten"
- Description = "Held des Tages"
- sn = "Proper"
- StreetAddress = "Landstrasse"
- wWWHomePage = "www.google.de"
- mail = "Test@contoso.com"
- }
- $propkey = @{
- l = '$props.l'
- Description = '$props.Description'
- sn = 'Proper'
- StreetAddress = '$props.StreetAddress'
- wWWHomePage = '$props.wWWHomepage'
- mail= '$props.mail'
- }
- Compare-Object ([PSCustomObject]$replace) ([PSCustomObject]$propkey) -Property sn, description, StreetAddress
- alwo23@hotmail.com
- Posts: 28
- Last visit: Tue Jun 06, 2023 2:43 am
Re: Compare two hashtables
Ok i have tested it, but the result is:
l : Kempten
Description : Held des Tages
sn : Proper
StreetAddress :
wwwhomepage :
mail : MProper@kempten.de
SideIndicator : =>
l : Kempten
Description : Held des Tages
sn : Proper
StreetAddress : Landstrasse
wwwhomepage : www.google.de
mail : Test@contoso.com
SideIndicator : <=
There are some properties with the same value but what i need is the different
l : Kempten
Description : Held des Tages
sn : Proper
StreetAddress :
wwwhomepage :
mail : MProper@kempten.de
SideIndicator : =>
l : Kempten
Description : Held des Tages
sn : Proper
StreetAddress : Landstrasse
wwwhomepage : www.google.de
mail : Test@contoso.com
SideIndicator : <=
There are some properties with the same value but what i need is the different
- alwo23@hotmail.com
- Posts: 28
- Last visit: Tue Jun 06, 2023 2:43 am
Re: Compare two hashtables
I will write back the different to the active directory. Only the changed thinks a need to be update in the active directory.
Re: Compare two hashtables
You do not need to do that. Just use "Replace" with the wholehash. D will only update the fiekds that are different.
Set-AdUser userid -Replace $replace
That is all we ever need to do. Let AD do the comparison for you.
Set-AdUser userid -Replace $replace
That is all we ever need to do. Let AD do the comparison for you.