I am creating a script that pulls all of the date and time information from our servers. The script gets the servers from a text file. I am having is getting the output of a script to be written to a text file.
I tried using a pipe with Out-File like so:
$servers = gc "C:\Users\Public\Shell_NTP\TestList.txt"
foreach ($server in $servers){
$dt = gwmi win32_operatingsystem -computer $server
$dt_str = $dt.converttodatetime($dt.localdatetime)
write-host "$($server) current local time is $($dt_str)" | Out-File
"C:\Users\Public\Shell_NTP\TestListOutput.txt"
Then I tried the simple carrot output like so:
$servers = gc "C:\Users\Public\Shell_NTP\TestList.txt"
foreach ($server in $servers){
$dt = gwmi win32_operatingsystem -computer $server
$dt_str = $dt.converttodatetime($dt.localdatetime)
write-host "$($server) current local time is $($dt_str)" >
C:\Users\Public\Shell_NTP\TestListOutput.txt
And that did not work either. So any help or advice would be excellent.
TL;DR Trying to get the powershell output into a text file or some other more usable file format.