Jump to content

powershell for loop an array and compare values

AlexGoesHigh
Go to solution Solved by AlexGoesHigh,

Well i guess my googling skills got better, i fixed my problems with this since powershell is diferent from what i know. My code turned out to be useless in the end.

 

I used this instead to compare the arrays

$arrayOfItemsToCompare | ForEach-Object {
	if ($array -contains $_) {
    	Write-Host $_
    }
}

 

i don't have much expirience with powershell and my programming skill are very basic but i'm having issues doing something very basic. Looping through the items of an array and comparing each item

 

for ($i = 0, $i -le ($array.length - 1), $i++) {
    if ($array[$i] -eq $arrayOfItemsToCompare[$i]){
        Write-host $servicesArray
    }
}

Both arrays only contains strings, no numbers, booleans or objects, i just want to compare all the strings that i have in $array with all the strings in $arrayOfItemsToCompare which is an array that i created at the beggining of the script, my problem right now is that i get an error saying that $array.length is an object that contains "44 0" which i have no clue how it gets there because if i do a write-host ($array.length - 1) i get "44"

 

i'm open to any suggestions, what i want i just to compare each item in the two arrays and say that $array has all the items in $arrayOfItemsToCompare otherwise say there's missing items

this is one of the greatest thing that has happened to me recently, and it happened on this forum, those involved have my eternal gratitude http://linustechtips.com/main/topic/198850-update-alex-got-his-moto-g2-lets-get-a-moto-g-for-alexgoeshigh-unofficial/ :')

i use to have the second best link in the world here, but it died ;_; its a 404 now but it will always be here

 

Link to comment
Share on other sites

Link to post
Share on other sites

Well i guess my googling skills got better, i fixed my problems with this since powershell is diferent from what i know. My code turned out to be useless in the end.

 

I used this instead to compare the arrays

$arrayOfItemsToCompare | ForEach-Object {
	if ($array -contains $_) {
    	Write-Host $_
    }
}

 

this is one of the greatest thing that has happened to me recently, and it happened on this forum, those involved have my eternal gratitude http://linustechtips.com/main/topic/198850-update-alex-got-his-moto-g2-lets-get-a-moto-g-for-alexgoeshigh-unofficial/ :')

i use to have the second best link in the world here, but it died ;_; its a 404 now but it will always be here

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×