Tommy_Cooper
asked on
Powershell get computers list and ping
Morning everyone,
Please can someone give a bit of instruction....
I want to get a list of servers from Active Directory (using Quest addins) and then for each server returned I want to ping it
So I have this:
========================== ========== ========== ==
$ProdServer=Get-QADCompute r -Searchroot 'mydomain.com/servers' |Select-Object name
forEach ($Server in $ProdServer)
{
$Alive=Get-WMIObject win32_pingstatus -Filter "Address-'$Server'" |Select-Object statuscode if ($Alive.statuscode -eq 0)
{
Write-Host $Server is Reachable
}
Else
{
Write-Host $Server is NOT reachable
}
}
========================== ========== ========
The problem is that the result I get is this:
@{Name=servername} is NOT reachable
How do I change what I'm inputting to the ping piece so that it doesn't contain the column heading (property name) of 'Name'?
Many thanks :)
Please can someone give a bit of instruction....
I want to get a list of servers from Active Directory (using Quest addins) and then for each server returned I want to ping it
So I have this:
==========================
$ProdServer=Get-QADCompute
forEach ($Server in $ProdServer)
{
$Alive=Get-WMIObject win32_pingstatus -Filter "Address-'$Server'" |Select-Object statuscode if ($Alive.statuscode -eq 0)
{
Write-Host $Server is Reachable
}
Else
{
Write-Host $Server is NOT reachable
}
}
==========================
The problem is that the result I get is this:
@{Name=servername} is NOT reachable
How do I change what I'm inputting to the ping piece so that it doesn't contain the column heading (property name) of 'Name'?
Many thanks :)
also u have a mistake in your script:
instead of:
$Alive=Get-WMIObject win32_pingstatus -Filter "Address-'$Server'" |Select-Object
should be:
Alive=Get-WMIObject win32_pingstatus -Filter "Address='$Server'" |Select-Object
here's your script updated:
instead of:
$Alive=Get-WMIObject win32_pingstatus -Filter "Address-'$Server'" |Select-Object
should be:
Alive=Get-WMIObject win32_pingstatus -Filter "Address='$Server'" |Select-Object
here's your script updated:
$ProdServer=Get-QADComputer -Searchroot 'mydomain.com/servers' |Select-Object name
forEach ($Server in $ProdServer)
{
$Alive = Get-WMIObject win32_pingstatus -Filter "Address='$Server'" |Select-Object statuscode
if ($Alive.statuscode -eq 0)
{
Write-Host $Server.Name is Reachable
}
Else
{
Write-Host $Server.Name is NOT reachable
}
}
ASKER
Hi Sedgwick,
I'm learning Powershell and wasn't aware of test-connection. This looks good. Kind of the same really. But I'll investigate that more: )
Sadly, running your script with test-connection gives me this result:
========================== ========== =====
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S tring) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi crosoft.Po werShell.C ommands.Te stConnecti onCommand
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S tring) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi crosoft.Po werShell.C ommands.Te stConnecti onCommand
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S tring) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi crosoft.Po werShell.C ommands.Te stConnecti onCommand
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S tring) [Test-Connection], PingException
+ FullyQualifiedErrorId : TestConnectionException,Mi crosoft.Po werShell.C ommands.Te stConnecti onCommand
ServerName is NOT reachable
========================== ========== =======
ALL instances of 'ServerName' are referring to the same server. Notice the very last entry also. This is bizarre because 'servername' is reachable.
Can you explain what's going on and what causes these multiple entries?
Many tanks
I'm learning Powershell and wasn't aware of test-connection. This looks good. Kind of the same really. But I'll investigate that more: )
Sadly, running your script with test-connection gives me this result:
==========================
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S
+ FullyQualifiedErrorId : TestConnectionException,Mi
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S
+ FullyQualifiedErrorId : TestConnectionException,Mi
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S
+ FullyQualifiedErrorId : TestConnectionException,Mi
Test-Connection : Testing connection to computer 'DOMAINNAME\'ServerName$' failed: The requested name is valid, but no data of the requested type was found
At line:2 char:20
+ If (Test-Connection <<<< $_){
+ CategoryInfo : ResourceUnavailable: (DOMAINNAME\'ServerName$:S
+ FullyQualifiedErrorId : TestConnectionException,Mi
ServerName is NOT reachable
==========================
ALL instances of 'ServerName' are referring to the same server. Notice the very last entry also. This is bizarre because 'servername' is reachable.
Can you explain what's going on and what causes these multiple entries?
Many tanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if u still get errors when using test-connection, use your script instead with the changes i've made.
ASKER
Sedgwick,
This is brilliant many thanks. Your script is working fine. I see that it works because we're doing 'Test-Connection' against only the property named 'name'.
Thanks awfully for your help.
Tommy
This is brilliant many thanks. Your script is working fine. I see that it works because we're doing 'Test-Connection' against only the property named 'name'.
Thanks awfully for your help.
Tommy
u welcome.
cheers
cheers
Open in new window