Run PS Script on Specified OU

This topic contains 3 replies, has 3 voices, and was last updated by  Flynn Bundy 3 years ago.

  • Author
  • #27092



    Im wondering if anyone could help me running this PS script on a specified OU?

    Can i pipe it some how?


  • #27095

    Richard Siddaway

    You should be able to use the -searchBase parameter on Get-AdObject to define the OU you want to use – it needs the distinguished name of the OU

  • #27180


    Thanks Richard. I haven't much powershell experience. Would you be able to show an example of how it should be constructed please?

  • #27182

    Flynn Bundy

    Hi Rackstar,

    What Richard is saying is that you can select whichever machines you wish by specifying the distinguished name of the OU. As an example

    $computers = Get-ADComputer -SearchBase "OU=DSC,DC=Overlord,DC=Corp,DC=Com" -Filter * | select -ExpandProperty Name 

    This would go to my DSC OU and gather all of the names of the machines in that OU and store them away in my computers variable. From here you have a collection of computers stored in a variable and you can do whatever you like to do. for example:

    Foreach ($Item in $computers){
    Write-Information "Hello There"

You must be logged in to reply to this topic.