troubleshooting Question

Need Help Modifying a Powershell Script

Avatar of Mike
MikeFlag for United States of America asked on
Scripting LanguagesPowershell
1 Comment1 Solution54 ViewsLast Modified:
Greeting Experts,

Can somebody help me modify the following script to export the data to a .csv file as it pings/Nslookup for each device in the input folder... any help would be approached... Please find the script below...

$InputFile = 'D:\workstationsList.txt'
$addresses = get-content $InputFile
$reader = New-Object IO.StreamReader $InputFile
    while($reader.ReadLine() -ne $null){ $TotalIPs++ }
write-host    ""    
write-Host "Performing nslookup on each address..."    
        foreach($address in $addresses) {
            ## Progress bar
            $i++
            $percentdone = (($i / $TotalIPs) * 100)
            $percentdonerounded = "{0:N0}" -f $percentdone
            Write-Progress -Activity "Performing nslookups" -CurrentOperation "Working on IP: $address (IP $i of $TotalIPs)" -Status "$percentdonerounded% complete" -PercentComplete $percentdone
            ## End progress bar
            try {
                [system.net.dns]::resolve($address) | Select HostName,AddressList
                }
                catch {
                    Write-host "$address was not found. $_" -ForegroundColor Green
                }
            }
write-host    ""            
write-Host "Pinging each address..."
        foreach($address in $addresses) {
            ## Progress bar
            $j++
            $percentdone2 = (($j / $TotalIPs) * 100)
            $percentdonerounded2 = "{0:N0}" -f $percentdone2
            Write-Progress -Activity "Performing pings" -CurrentOperation "Pinging IP: $address (IP $j of $TotalIPs)" -Status "$percentdonerounded2% complete" -PercentComplete $percentdone2
            ## End progress bar
                if (test-Connection -ComputerName $address -Count 2 -Quiet ) {  
                    write-Host "$address responded" -ForegroundColor Green 
                    } else 
                    { Write-Warning "$address does not respond to pings"              
                    }  
        }


write-host    ""        
write-host "Done!"
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros