I am using below script to reboot remote servers which are in CSV file.
============
Import-CSV "D:\script\serverlist.csv" | ForEach-Object -Begin {
"Computer $_ initiated reboot at $(Get-Date)" | Add-Content -Path Rebootlogs.txt
} -Process {
Restart-Computer $_.servername -Force
} -End {
Import-CSV "D:\script\serverlist.csv" | ForEach-Object -Begin {
Start-Sleep -Seconds 60
} -Process {
if (Test-Connection $_ -quiet) {"Computer $_ verified to be responding to ping at $(Get-Date)" | Add-Content -Path Rebootlogs.txt }
else {"Computer $_ unresponsive to ping at $(Get-Date)" | Add-Content -Path Rebootlogs.txt}
} -End {}
}
==========================
Result:
======================
Computer initiated reboot at 01/30/2015 05:20:24
Computer @{servername=server12; schedule=ONCE; RebootTime=22:30:00; RebootDate=01/26/2015} unresponsive to ping at 01/30/2015 05:21:28
========================
But when I am using below script wiht "get-content" from TXT file..
==================
Import-Csv "D:\script\serverlist.txt" |
ForEach-Object -Begin {
"Computer $_ initiated reboot at $(Get-Date)" | Add-Content -Path RebootLog.txt
} -Process {
Restart-Computer -Force -ComputerName $_
} -End {
Get-Content -Path "D:\gops\serverlist.txt" | ForEach-Object -Begin {
Start-Sleep -Seconds 60
} -Process {
if (Test-Connection $_ -quiet) {"Computer $_ verified to be responding to ping at $(Get-Date)" | Add-Content -Path RebootLog.txt} else {"Computer $_ unresponsive to ping at $(Get-Date)" | Add-Content -Path RebootLog.txt}
} -End {
}
}
=========================
Result:
==============
Computer initiated reboot at 01/30/2015 05:26:02
Computer server12 verified to be responding to ping at 01/30/2015 05:27:05
=============================
I am not able to catch, why so difference showing from "import-csv" input file.
I need the output same like "get-content" result script:
Please help or guide me on this..
I want to use CSV input file..
- Edited by Mr. Raj Thursday, February 05, 2015 7:46 PM