Here's a portion of a Powershell script I use for a daily disk space report
that will get you going.  I have all my servers nested in a Servers OU so
this will work.  It won't work as is if your AD structure is different.
There are probably tons of optimizations that could be made, but this works
well for what I need it to do.

----
#Create Variables
$OutputDirectory = "C:\Whatever\"
$SourceDirectory = "C:\Whatever\"

# This portion of the script creates the source file which the next portion
will ping for availability.

function GetServerList
{
$Root = New-Object
directoryservices.directoryentry("LDAP://OU=Servers,DC=DOMAIN,DC=LOCAL")
$searcher = new-object System.DirectoryServices.DirectorySearcher($Root)
$searcher.filter="(&(objectCategory=computer))"

# In the line below, piping the output to out-null prevents a '0' from
being returned in the output
$searcher.PropertiesToLoad.Add("cn") | Out-Null
$searcher.sort.PropertyName="cn"
$servers = $searcher.findAll()
# The line below prints the names of the servers
foreach ($server in $servers) {$server.properties.cn}
}

GetServerList | Out-File $OutputDirectory\serverlist.txt


# This portion of the script reads the list of servers created above and
creates an output file of those which respond to ping.


function PingServers
{
$readfile = get-content $SourceDirectory\serverlist.txt
foreach($server in $readfile)
{

$Alive = get-wmiobject win32_pingstatus -Filter "Address='$server'" |
Select-Object statuscode
if($Alive.statuscode -eq 0)
{ $Server}
else
{ }
}
}

PingServers | Out-File $OutputDirectory\alive.txt
----

On Thu, Nov 6, 2014 at 11:13 AM, David McSpadden <[email protected]> wrote:

>  I want to run a windows batch the just does a ping.
>
> If the ping returns good data do nothing but if the ping fails set an
> error code I can look for and address it outside the batch.
>
> Anyone have or can point me to a . b a t script that does this already??
>
> Thanks
>
>
>
> This e-mail and any files transmitted with it are property of Indiana
> Members Credit Union, are confidential, and are intended solely for the use
> of the individual or entity to whom this e-mail is addressed. If you are
> not one of the named recipient(s) or otherwise have reason to believe that
> you have received this message in error, please notify the sender and
> delete this message immediately from your computer. Any other use,
> retention, dissemination, forwarding, printing, or copying of this email is
> strictly prohibited.
>
> Please consider the environment before printing this email.
>

Reply via email to