PowerTip: Test Active Directory Script with Pester

Summary: Use Pester to safely test script changes to Active Directory.

Hey, Scripting Guy! Question How can I test my Active Directory script without having it make changes to my live domain?

Hey, Scripting Guy! Answer Use Pester’s mocking feature to test your code without using the actual Active Directory cmdlets.

Comments (4)

  1. Tim Bolton says:

    Huh? How do you test what the cmdlet will do without the cmdlet..?

  2. Hoyt says:

    Talk about an article that’s light on details. Not even a github link let alone a demo!


  3. David Wyatt says:

    The PowerTip posts are always short; they’re paired with the longer blog post that gets published earlier the same day. This particular one is associated with this article:


    To answer your question, Tim, you aren’t testing what the cmdlet would do. Rather, you’re testing the logic in your own code in such a way that you don’t need to set up an AD environment first, which would take more time (and money for compute time on VMs,
    etc.) If your code passes this unit test first, then you move on to the more expensive and more thorough tests.

  4. Chris says:


    This "association" is not a good idea. How is anyone supposed to discover this association without training?

Skip to main content