none
Boolean User Properties always returns TRUE RRS feed

  • Question

  • Hi, I am trying to get some propeties from the user on the AD and I found out with the following issue, all the boolean attributes always return TRUE as value. The Code that I am using to extract them is the following

    foreach ($objUser in $objUsers)
    {
     $bolPasswordNeverExpires = [boolean] $objUser.Properties['PasswordNeverExpires'];
     $bolEnabled = [boolean] $objUser.Properties['Enabled'];
     $bolAccountExpired = [boolean] $objUser.Properties['AccountExpired'];
    }

    Could you please guide me into the proper direction to solve it. I looked up in most of powershell related topic and did not find a way to solve it. I even attempt using UserAccountControl Attribute to check Enabled status do not matter agains which value I check it, it always returns TRUE.

    Friday, September 12, 2014 7:58 PM

All replies

  • There's no property 'AccountExpired', perhaps you mean 'accountExpires'

    I'm getting a mix of True and False from this code for example:

    Get-ADUser -Filter * -Properties * | % {
        $objUsers.PasswordNeverExpires
        $objUsers.Enabled
        [bool]$objUsers.accountExpires
    }


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    Friday, September 12, 2014 8:37 PM
  • Thank´s for the tip. Unluckily when I attempt it, if I left only

    $objUsers.PasswordNeverExpires or $objUsers.Enabled, it only return whites spaces and no comparison from True or False is feasible.

    If I change it to [boolean] $objUsers.PasswordNeverExpires or $objUsers.Enabled instead of using the Properties option, it returns False for all values.

    I attempt to use the UserAccountControl field for look up the property Ex: (objUser.UserAccountControl AND 2) for Enabled and it also returns True for all situation

    I look up for the properties on the ISE interface and the only ones displayed are the following ones:

    distinguishedname
    displayname
    whencreated
    samaccountname
    sn
    accountexpires
    pwdlastset
    samaccounttype
    adspath
    useraccountcontrol
    whenchanged
    cn
    userprincipalname
    lastlogontimestamp
    msds-user-account-control-computed

    May it be an issue with the filter that does not load the specified properties?

    Monday, September 15, 2014 1:33 PM
  • Yes, as shown in the script I posted above, you must use the -Properties parameter to get extended properties including PasswordNeverExpires.

    Have you tried the code I posted above?


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    Monday, September 15, 2014 2:36 PM
  • Hi Sam:

    Yes, I attempt using the code that you posted and in this case for all the instances it return me FALSE.

    Monday, September 15, 2014 8:05 PM
  • Can you post screen shots of the code and result?

    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    Monday, September 15, 2014 8:16 PM