kennysarmy Posted February 12, 2020 Posted February 12, 2020 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?
djm968 Posted February 12, 2020 Posted February 12, 2020 (edited) Have a look at the Out-file command. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7 And Set-content https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-7 There is also some very good info here. https://stackoverflow.com/questions/28812239/powershell-write-host-append-to-text-file-computer-name-and-time-stamp Edited February 12, 2020 by djm968 1
djm968 Posted February 12, 2020 Posted February 12, 2020 (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 February 12, 2020 by djm968 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now