• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Ignore dead server

A

atorres

#1
I am trying to create a script that reads the registry to a list of servers
using a text file; but some of the server on the file are dead; I would like
to know how can I create a file that reports the dead servers, and then
continue with the next server on the list.

NOTE: My scripts errors out once it gets to a dead server

Here is my sample:
$Servers = Get-Content C:\Prod\AdminScripts\PS\Trend\Trend_list.txt
$File = "C:\Prod\AdminScripts\PS\Trend\Trend-Server.log"
ForEach ($Serv in $Servers) {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',
$Serv)
$regKey =
$reg.OpenSubKey("SOFTWARE\\TrendMicro\\ServerProtect\\CurrentVersion")
$regKey.GetValueNames()
$Path = $regKey.GetValue('HomeDirectory')
$Output = "\\$Serv\$Path"
$Output | Out-File $File -Append
}
 

My Computer

N
#2
you could use ping...do something like:

$servers | %{$test = ping -Quiet $_.name
if (!$test) {$_.name >> C:\notresolved.txt}
elseif ($test.received -eq 0) {$_.name >> c:\unpingable.txt}
elseif ($test.received -ne 0) {$_.name >> c:\alive.txt}}

"atorres" wrote:

> I am trying to create a script that reads the registry to a list of servers
> using a text file; but some of the server on the file are dead; I would like
> to know how can I create a file that reports the dead servers, and then
> continue with the next server on the list.
>
> NOTE: My scripts errors out once it gets to a dead server
>
> Here is my sample:
> $Servers = Get-Content C:\Prod\AdminScripts\PS\Trend\Trend_list.txt
> $File = "C:\Prod\AdminScripts\PS\Trend\Trend-Server.log"
> ForEach ($Serv in $Servers) {
> $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',
> $Serv)
> $regKey =
> $reg.OpenSubKey("SOFTWARE\\TrendMicro\\ServerProtect\\CurrentVersion")
> $regKey.GetValueNames()
> $Path = $regKey.GetValue('HomeDirectory')
> $Output = "\\$Serv\$Path"
> $Output | Out-File $File -Append
> }
 

My Computer

O

OldDog

#3
On Nov 24, 12:13 pm, Niro <N...@xxxxxx> wrote:

> you could use ping...do something like:
>
> $servers | %{$test = ping -Quiet $_.name
> if (!$test) {$_.name >> C:\notresolved.txt}
> elseif ($test.received -eq 0) {$_.name >> c:\unpingable.txt}
> elseif ($test.received -ne 0) {$_.name >> c:\alive.txt}}
>
>
>
> "atorres" wrote:

> > I am trying to create a script that reads the registry to a list of servers
> > using a text file; but some of the server on the file are dead; I wouldlike
> > to know how can I create a file that reports the dead servers, and then
> > continue with the next server on the list.
>

> > NOTE: My scripts errors out once it gets to a dead server
>

> > Here is my sample:
> > $Servers = Get-Content C:\Prod\AdminScripts\PS\Trend\Trend_list.txt
> > $File = "C:\Prod\AdminScripts\PS\Trend\Trend-Server.log"
> > ForEach ($Serv in $Servers) {
> >    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',
> > $Serv)
> >    $regKey =
> > $reg.OpenSubKey("SOFTWARE\\TrendMicro\\ServerProtect\\CurrentVersion")
> >    $regKey.GetValueNames()
> >    $Path = $regKey.GetValue('HomeDirectory')
> >    $Output = "\\$Serv\$Path"
> >    $Output | Out-File $File -Append
> > }- Hide quoted text -
>
> - Show quoted text -
What if they are not dead? What if they are Linux???

Give this a try..
#<---------------- Begin
----------------------------------------------->
$ping = New-Object System.Net.NetworkInformation.Ping
$computerlist = Get-Content 'c:\scripts\Servers.txt'
foreach ($srv in $computerlist)
{
$reply = $ping.Send($srv)
if ($reply.status -eq "Success")
{
if ($reply.Options.ttl -le 64)
{
Write-Host $srv " probably is a Unix host"
}
Else
{ if ($reply.Options.ttl -ge 65)
{
Write-Host $srv " probably is a Windows host"
}
}
}
Else { Write-Host $srv " Does Not Ping"
}
}

#<----------------------- End Script
-------------------------------------­----->
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)