Run PS Script on Specified OU

Hi

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

https://gallery.technet.microsoft.com/office/Sync-Primary-Email-Address-a1d989cb#content

Can i pipe it some how?

Thanks

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

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

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"

}