none
Set User Must change password at next logon only for certain locations RRS feed

  • Question

  • Hi Experts,

    I am trying to set "User Must change password at next logon" Attribute only for certain locations. But for some reason  the below script does not work. Not sure if i am doing something wrong.

    Kindly assist.

    $Office = 'London'
    $Location = "London,New York,Delhi"
    $LocationArray = $Location.Split(',')

    if ($Office -eq $LocationArray)
    {

    Set-ADUser -Identity '200000' -ChangePasswordAtLogon $false

    }
    Else
    {

    Set-ADUser -Identity '200000' -ChangePasswordAtLogon $true

    }


    Justin

    Monday, February 26, 2018 8:32 AM

Answers

  • -eq does a comparison for equality. You will need something like this:
    If($Office -in $LocationArray) ....
    or this: 
    if($LocationArray -contains $Office) .... 

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by JS2206 Monday, February 26, 2018 9:46 AM
    Monday, February 26, 2018 9:09 AM

All replies

  • -eq does a comparison for equality. You will need something like this:
    If($Office -in $LocationArray) ....
    or this: 
    if($LocationArray -contains $Office) .... 

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by JS2206 Monday, February 26, 2018 9:46 AM
    Monday, February 26, 2018 9:09 AM
  • Thank you so much for your help. It worked for me.

    Justin

    Monday, February 26, 2018 9:46 AM