Jump to content

Powershell Script to create txt file of pingable hosts?


Recommended Posts

Posted

I have a text file of student computers.

 

I've found some powershell that let's me see which are on and which are off.

 

The code is :

 

GC D:\scripts\remotesoftware\PupilComputers.txt | %{
If (Test-Connection $_ -Quiet -Count 2){
Write-Host "$_ is UP" -b Green
}
Else{
Write-Host "$_ is Down" -b Red
}
}

 

 

Can anyone help me adapt this so that the hosts which are ping-able are added to a new TXT file?

Posted (edited)

This should work.

 

GC D:\scripts\remotesoftware\PupilComputers.txt | %{

If (Test-Connection $_ -Quiet -Count 2){

Write-Output "$_ is UP" -b Green >> C:\scripts\testlog.txt

}

Else{

Write-Output "$_ is Down" -b Red >> C:\scripts\testlog.txt

}

}

Edited by djm968
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...