Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:57:45+00:00 2026-06-18T07:57:45+00:00

trying to work this one out and not having much luck really. The if

  • 0

trying to work this one out and not having much luck really. The if statement from the following block of code is never true, which I don’t understand:

$array1 = "red", "blue", "green", "yellow"
$array2 = "rose", "sky", "grass", "sand"
$both_arrays = $array1, $array2

for ($c=0; $c -lt 4; $c++) {

$object = $both_arrays[0][$c]
$colour = $both_arrays[1][$c]

Write-Host $c "-" $object
Write-Host $c "-" $colour

if ( ($colour.contains("green") ) ) { Write-Host "HELL YEAH! Green is my favourite colour!" }

}

Output as follows:

0 - red
0 - rose
1 - blue
1 - sky
2 - green
2 - grass
3 - yellow
3 - sand

It works fine if we’re just dealing with one array though:

$array1 = "red", "blue", "green", "yellow"

for ($c=0; $c -lt 4; $c++) {

$colour = $array1[$c]

Write-Host $c "-" $colour

if ( ($colour.contains("green") ) ) { Write-Host "HELL YEAH! Green is my favourite colour!" }

}

Output comes out as expected:

0 - red
1 - blue
2 - green
HELL YEAH! Green is my favourite colour!
3 - yellow

What the smeg is going on? Help appreciated!

Still getting an error with an example of the above code when I attempt to apply the concept to another script I’m writing:

for ($c=0; $c -lt 3; $c++) { #$arrCheckpoint, 

$ckname = $arrCheckpointNameAndStatus[0][$c]
$ckstatus = $arrCheckpointNameAndStatus[1][$c]

Write-Host $ckname

if ( ($ckname.contains("Standard Checkpoint") ) ) { Write-Host "Hit." }

}

Write-Host "End of Script"

It throws the following error:

Method invocation failed because [System.Object[]] doesn't contain a method named 'contains'.
At C:\script.ps1:225 char:27
+     if ( ($ckname.contains <<<< ("Standard Checkpoint") ) ) { Write-Host "Hit." }
+ CategoryInfo          : InvalidOperation: (contains:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Really starting to bug me now!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:57:46+00:00Added an answer on June 18, 2026 at 7:57 am

    You appear to have the array indexing of your object and color arrays reversed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to work out the best way of doing this but not
Not having much luck getting help from any of you Spring gurus on here.
I'm having trouble figuring this one out. I'm trying to direct mobile traffic to
Okay I been trying to work this out but unable too. I have a
i am trying to work this out is the simplest way, i am a
I'm trying for a while to work this out with no success so far
I ask this because I am currently trying to work out my own technique,
I'm trying to work out what regular expression I would need to change this
I've been trying to figure this one out by reading the git-svn man-page but
Probably a really simple answer to this one. I am having trouble getting write-progress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.