bryan oakley-wiggins
asked on
powershell write-output
Hi
*** Envirnment***
PoSH v 1.0
Windows 2003
I have a daily check script I am working on and part of this will be to ping a bunch of servers from an input file (I will later on hook this into AD with a custom attribute for critical servers) but for now I take input from a file and display on screen...
What I am trying to do, is for each server that doesn't respond to ping, I want to write-host but also output the failures to a .log file...
I usually wrtie-host "something";write-output "something" | out-file ".\test.log" but I am getting the empty pipeline error....
Here is the current script -I would appreciate any guidance on how to write out the failures..!
### Script start ###
$readfile=Get-Content "w:\pingtest.txt"
foreach($readf in $readfile)
{
$ALive=get-wmiobject win32_pingstatus -Filter "Address='$readf'" | Select-Object statuscode
if($ALive.statuscode -eq 0)
{Write-Host $readf is REACHABLE -background "GREEN" -foreground "BLACk"}
else
{Write-Host $readf is NOT reachable -background "RED" -foreground "BLACk"}
}
### Script End ###
Cheers
Bry
*** Envirnment***
PoSH v 1.0
Windows 2003
I have a daily check script I am working on and part of this will be to ping a bunch of servers from an input file (I will later on hook this into AD with a custom attribute for critical servers) but for now I take input from a file and display on screen...
What I am trying to do, is for each server that doesn't respond to ping, I want to write-host but also output the failures to a .log file...
I usually wrtie-host "something";write-output "something" | out-file ".\test.log" but I am getting the empty pipeline error....
Here is the current script -I would appreciate any guidance on how to write out the failures..!
### Script start ###
$readfile=Get-Content "w:\pingtest.txt"
foreach($readf in $readfile)
{
$ALive=get-wmiobject win32_pingstatus -Filter "Address='$readf'" | Select-Object statuscode
if($ALive.statuscode -eq 0)
{Write-Host $readf is REACHABLE -background "GREEN" -foreground "BLACk"}
else
{Write-Host $readf is NOT reachable -background "RED" -foreground "BLACk"}
}
### Script End ###
Cheers
Bry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Marvellous..!
I swear I tried that but mustn't have ;-)
To note - I just added -append to the out-file to collect all failures...
Once again, massive thanks and very much appreciated..!
Cheers
Bry