Home > database >  match and check if 2 values are equal or not
match and check if 2 values are equal or not

Time:11-25

I have 2 variables were I am getting value like below

[DBG]: PS C:\Windows\system32>> $todhome.tod_disk_type
STANDARD
STANDARD
STANDARD
[DBG]: PS C:\Windows\system32>> $todhome.actual_disk_type
STANDARD
STANDARD
STANDARD

Please let me know how to match and check they are same or not

tried below but not working

if ($todhome.tod_disk_type -match $todhome.actual_disk_type)

output for compare-object

PS C:\Windows\system32> $a
STANDARD
STANDARD
STANDARD

PS C:\Windows\system32> $b
STANDARD
STANDARD
STANDARD

PS C:\Windows\system32> Compare-Object $a $b

PS C:\Windows\system32> 

CodePudding user response:

You can use Compare-Object to compare two sequences:

# define two string arrays with the same values
$a = -split 'STANDARD STANDARD STANDARD'
$b = -split 'STANDARD STANDARD STANDARD'

# Use Compare-Object to find any differences
$diff = Compare-Object $a $b

if($diff){
  # differences were found 
}
  • Related