Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Compare-object when comparing an array

$
0
0

I’m migrating two DHCP scopes from two 2008 servers to one Windows 2012 server, which is load balance with another.  The reservations on the old 2008 aren’t the same on both so some get imported and some don’t. I have to merge the two Lease sections of the XML outputs to get one scope to import but I have to sync the missing reservations.  I have a script the pulls the DHCP reservations from the old two and merges them.  Sorts out any duplicates, because some were on both.  Gets the reservations on the new DHCP server and that were it goes wrong

I need to use Compare-Object I get this out

InputObject                                       SideIndicator

-----------                                              -------------

DhcpServerv4Reservation           <=                                                                             

DhcpServerv4Reservation           <=                                                                             

DhcpServerv4Reservation           <=                                                                              

DhcpServerv4Reservation           <=                                                                             

DhcpServerv4Reservation           <=       

This is my script so I suppose my question is when I sort and array of object how can I just pick say IP and leave me with just the ones that aren’t on DCHP01 and run those through the FprEach-Object loop

$DC01=Get-DhcpServerv4Reservation-ScopeId172.26.32.0-ComputerNamedc01

$DC03=Get-DhcpServerv4Reservation-ScopeId172.26.32.0-ComputerNamedc03

$DHCP01=Get-DhcpServerv4Reservation-ScopeId172.26.32.0-ComputerNamedhcp01

$Reservations=$DC01+$DC03

$Reservations=$Reservations|Sort-ObjectName|select-UniqueName,IPAddress,ScopeID,ClientId,Description

$Different=Compare-Object$Reservations$DHCP01

 

#$Different | ForEach-Object{

#Add-DhcpServerv4Reservation -ClientId $_.ClientId -IPAddress $_.IPAddress -ScopeId $_.ScopeId -ComputerName DHCP01 -Description $_.Description -Name $_.Name -Type Both

#}

 

This the data in my $DC01, $DC03 and $DHCP01 strings

PS C:\Windows\system32> Get-DhcpServerv4Reservation -ScopeId 172.26.32.0 -ComputerName dc01

 

IPAddress            ScopeId              ClientId             Name                 Type                 Description        

---------            -------              --------             ----                 ----                 -----------        

172.26.32.182        172.26.32.0          78-e3-b5-fa-4f-e2    mfp60901. Both                                    

172.26.32.5          172.26.32.0          00-27-0e-38-98-75    PC61045.  Dhcp                 Mike Waldron's PC  

172.26.32.193        172.26.32.0          00-21-5a-96-d1-b2    MFP60872. Both                                    

172.26.32.109        172.26.32.0          14-58-d0-39-1b-0d    MFP60892. Dhcp                                     

172.26.32.113        172.26.32.0          64-51-06-27-70-be    MFP60857. Dhcp                                    

PS C:\Windows\system32> Get-DhcpServerv4Reservation -ScopeId 172.26.32.0 -ComputerName dc03

IPAddress            ScopeId              ClientId             Name                 Type                 Description        

---------            -------              --------             ----                 ----                 -----------         

172.26.32.182        172.26.32.0          78-e3-b5-fa-4f-e2    mfp60901. Dhcp                                    

172.26.32.5          172.26.32.0          00-27-0e-38-98-75    PC61045.  Dhcp                 Mike Waldron's PC  

172.26.32.177        172.26.32.0          dc-9c-52-16-f5-47    SWEP5.    Dhcp                                    

172.26.32.156        172.26.32.0          08-00-27-7f-79-ac    PC60197VM.york.go... Dhcp                 Steve Fentons VM   

172.26.32.178        172.26.32.0          00-50-b6-62-5d-34    LT63347.  Dhcp                 D Andrew Laptop    

172.26.32.166        172.26.32.0          00-50-b6-60-9e-80    LT63346.  Dhcp                 S Binns Laptop     

172.26.32.160        172.26.32.0          54-ee-75-0f-18-b3    PC64792.  Dhcp                 Reddy Rakasi - To...

PS C:\Windows\system32> Get-DhcpServerv4Reservation -ScopeId 172.26.32.0 -ComputerName dhcp01

IPAddress            ScopeId              ClientId             Name                 Type                 Description        

---------            -------              --------             ----                 ----                 -----------        

172.26.32.160        172.26.32.0          54-ee-75-0f-18-b3    PC64792.  Dhcp                 Reddy Rakasi - To...

172.26.32.5          172.26.32.0          00-27-0e-38-98-75    PC61045.  Dhcp                 Mike Waldron's PC  

172.26.32.156        172.26.32.0          08-00-27-7f-79-ac    PC60197VM.york.go... Dhcp                 Steve Fentons VM   

172.26.32.166        172.26.32.0          00-50-b6-60-9e-80    LT63346.  Dhcp                 S Binns Laptop     

172.26.32.177        172.26.32.0          dc-9c-52-16-f5-47    SWEP5.    Dhcp                                    

172.26.32.178        172.26.32.0          00-50-b6-62-5d-34    LT63347.  Dhcp                 D Andrew Laptop    

172.26.32.182        172.26.32.0          78-e3-b5-fa-4f-e2    mfp60901. Dhcp    

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles