I have a non working PowerShell script for searching an OU in an 2008 level Active directory, but it is obviously incomplete. I was able to retrieve part of the script from another forum (cant remember which one, or I would kindly give them the credit they deserve), but I was hoping to include a variable to in the "SearchBase" option below and make it dynamic, where I can change the OU to ping from a top level and have it also work under a child OU if I need to.
Outcome: Ping OU and child OU and have the option to ping either selection. Of course I would manually enter in my Search base parameters when prompted from the shell. I just want to have any easy way of ping all computers from an OU level without having to paste the lower part of the script to my PowerShell script pane and changing the OU from there. If I can get the correct parameters working, then it would be easy to load this function to my PS profile. Thank you, and help is appreciated. Hoping someone can let me know what I am missing to get this functional.
functionget-DCping
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName
=$true,
Position
=0)]
[string]$Search)
$rtn=$null
Get-ADComputer-Filter*-SearchBase'OU=$Search,DC=domain,DC=domain' |
%
{$rtn=Test-Connection-CN$_.name-Count1-BufferSize16-Quiet
IF
($rtn-match'True') {write-host-ForegroundColorgreen$_.name}
ELSE
{ Write-host-ForegroundColorred$_.name }}
}