none
Compare User Attribute to a value RRS feed

  • Question

  • Hello,

           I have a powershell script that I've been using to move users from one OU to another OU based on a CSV export from a HR information system. The script had been checking if their home directory existed on the appropriate file server with Test-Path command, $HomeCheck = Test-Path $HOMEDIR.

          Now I need to check based on OU and DisplayName. I've tried to get the value of the current display name with $CurrentDisplayName =  Get-ADUser -identity user123 -property DisplayName | Select -property DisplayName. But $CurrentDisplayName contains @{displayname=

    If anyone has any ideas how to accomplish this or a better method, it would be greatly appreciated.

    Thanks,

    Pete


    • Moved by jrv Tuesday, August 8, 2017 8:17 PM Best forum
    • Edited by Pedro Rodriguez 4 Tuesday, August 8, 2017 9:11 PM Added detail because it got moved
    Tuesday, August 8, 2017 8:04 PM

Answers

  • After the pipe in the Select cmdlet use -expandproperty Displayname. So your command would look like this $CurrentDisplayName =  Get-ADUser -identity user123 -property DisplayName | Select -expandproperty DisplayName. This forces the output to a string instead of an object. 

    Thanks

    J

    Wednesday, August 9, 2017 2:31 PM

All replies

  • The displayName attribute is not mandatory, so it may not have a value. Are you saying the value is missing, because that is certainly possible? You can check in ADUC on the General tab.

    As far as the OU is concerned, there is no attribute for this except the distinguishedName (DN). You would need to parse the DN for either the distinguishedName of the OU or the Relative Distinguished Name (RDN or Name, recognizing that this may not uniquely identify it).


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, August 9, 2017 1:21 AM
  • After the pipe in the Select cmdlet use -expandproperty Displayname. So your command would look like this $CurrentDisplayName =  Get-ADUser -identity user123 -property DisplayName | Select -expandproperty DisplayName. This forces the output to a string instead of an object. 

    Thanks

    J

    Wednesday, August 9, 2017 2:31 PM
  • Thanks. That worked perfectly.

    Regards,

    Pete

    Wednesday, August 9, 2017 6:08 PM