AD Powershell

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Yeta Yeta 4 weeks, 1 day ago.

  • Author
    Posts
  • #73867
    Profile photo of Yeta
    Yeta
    Participant

    Greetings,
    How can one query the AD database using powershell to only get you user objects with the ProtectedFromAccidentalDeletion property set to $True?

    I tried using this one liner code with no success:
    get-aduser -Filter * | where-object {$_.ProtectedFromAccidentalDeletion -eq $True}

    Regards,

    Yeta

  • #73870
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Could you please format your code as code? Thanks.

    get-aduser -Filter * -Properties ProtectedFromAccidentalDeletion | where-object {$_.ProtectedFromAccidentalDeletion}
    • #73877
      Profile photo of Yeta
      Yeta
      Participant

      Thanks Olaf,
      Could you please assist with the interpretation of the syntax? Why the protectedfromaccidentaldeletion before and after the pipeline? Also why shouldn't we indicate within the code whether the property should have a value of true or false?

      Thanks again...

  • #73880
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Get-ADUser does not return the ProtectedFromAccidentalDeletion property by default. Olaf added the -properties parameter to instruct Get-ADUser to return the ProtectedFromAccidentalDeletion property. Since the ProtectedFromAccidentalDeletion is now included in the Get-ADUser output, Where-Object can now be used to filter on its value.

  • #73885
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Curtis is absolutely right. And to explain the thing with the where-object: Where-Object evaluates whatever is between the curly braces. If the property is boolian anyway you can omit the comparison.

    • #73915
      Profile photo of Yeta
      Yeta
      Participant

      Curtis and Olaf, thanks for the interpretation of the where-object cmdlet. It's now making sense

You must be logged in to reply to this topic.