I wrote a script which works, but the output is long enough that it would take a large console buffer to capture it all and paste it into a file to save.
I would like to be able to send the result strings both to the screen and to a file.
In the script I used "write-host" liberally, AND these are the strings I want to write to a file. I do not want to use simple redirection so no output goes to the monitor.
I suspect that I need a different approach instead of "write-host", but I have not been able to cobble together anything that works.
Following is a little chunk of the script so you can see basically how I am trying to accomplish the goal of the script. Thank you.
param($FName)
$tgt = Import-Csv $FName
$tgt | ForEach-Object ($_.IPAddr) {
Write-Host Checking IP Address ($_.IPAddr)
Resolve-DnsName -Name $_.IPAddr 2\>$null | Out-Null
$ResolvResult = $?
if ($ResolvResult -eq $TRUE) {
$RevHstName = Resolve-DnsName -name $_.IPAddr | Select-Object -Property NameHost -First 1
$RevHstName = $RevHstName -replace ".*=" -replace "}"
$TestRoot = ($RevHstName -split ".",3) #\[1\]
if (($TestRoot -like '*-servers\*') -or ($TestRoot -like '*awsdns*'))
{
write-host $_.IPAddr "looks up as a ROOT or AWS SERVER"
}
else
{
write-host "Successful Lookup for" $_.IPAddr "is" $RevHstName
}
.....
I have tried various combinations piping into or out of "Tee-Object", "Write-Output", "Out-File". But I haven't been able to get any of them to work.