locked
Get-ADUser Filter by Manager disabled RRS feed

  • Question

  • Hello All, 

    I am trying to work on the Script to get the manager disabled for a specific set of accounts and i am using the following conditions to get the disabled manager information. 

    Get-ADUser -Filter {(sAMAccountName -like "xx" -or sAMAccountName -like "yy")} -properties Manager|

    Select Name,@{label="Manager Status";expression={(Get-ADUser $_.Manager -Properties SAMAccountName).SamAccountName}} |

    Where-Object {($_.Manager).Enabled -eq $false} |Export-CSV C:\temp\managerdisable.csv


    When i try to run this script i am getting a blank CSV file. 

    Thursday, July 25, 2019 3:54 PM

All replies

  • In your Where-Object clause, the expression $_.Manager is the user manager, and it does not have an Enabled property. In your Select clause you should could add another Get-ADUser to retrieve the Enabled property of the manager.

    Or don't pipe, but code a ForEach after the first Get-ADUser where in one additional Get-ADUser you retrieve both the sAMAccountName and the Enabled property of the manager.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, July 25, 2019 5:04 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, July 26, 2019 3:15 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, July 31, 2019 6:28 AM