Losing my mind :)

Hi there
im trying to do something really simple and i guess after few hours working on the computer i am losing it:)

trying to do this:


  displayName= "GraphUser$($_)"  
  mailNickname= "GraphUser$($_)"
  userPrincipalName= "GraphUser$($_)@domain.onmicrosoft.com"
  passwordProfile= @{
    forceChangePasswordNextSignIn= "true"
    password= "xWwvsdfsaw+bWH-d"}

but i dont see it executing 500-1000
when i check $user i see it as 1000

its something obvios im missing here cause this was working yesterday(or some typo that wasnt there made it work)
Thanks in advancePreformatted text


please go back and edit your post to fix the code formatting as it misses some characters at the moment.

To post code or sample data or console output please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance

I don’t know if it is because of the missing code formatting but if you want to define a range it is


and not


Thanks and apologize for confusion.
it does have only two

… looks better now. :+1:t4: :wink: But I don’t get what your problem is. When you run your code it executes 501 times and assigns some values with a hastable to a variable. And when you check it after it ran you see the last assigned values.

What did you expect? Or what do you actually want to do?

1 Like

Apologize again
what i meant to do is capture all these values into variable like $data (i edit the original post to show that)
but when i check the $data its empty
when i check the last $user it has the last value which is normal but the data for all users isn’t in $data

I see …

You have to remove the variable assignment inside the loop:

$data =
500..1000 |
ForEach-Object {

        accountEnabled    = "false"
        displayName       = "GraphUser$($_)"  
        mailNickname      = "GraphUser$($_)"
        userPrincipalName = "GraphUser$($_)@domain.onmicrosoft.com"
        passwordProfile   = @{
            forceChangePasswordNextSignIn = "true"
            password                      = "xWwvsdfsaw+bWH-d"

Now you can access it with its index like this:


or this

1 Like