Reputation: 629
I'm trying to run an IP check from a loooong list of.. well, IPs.. with [System.Net.DNS] This works great, however I want to put a simple progress bar on it. Be it seconds or Percentage... Don't really care. I just want a nice progress bar to show up and tell me how long I need to wait.
$colComputers = get-content $File
foreach ($strComputer in $colComputers)
{
$IP = try {$dnsresult = [System.Net.DNS]::GetHostEntry($strComputer)} `
catch {$dnsresult = "Fail"}
$IP
for ($IP=100; $IP -gt 1; $IP--) {
Write-Progress -Activity "Working..." `
-SecondsRemaining $IP `
-Status "Please wait."
}
Script runs great, just getting stuck on this progress bar. I was thinking it would be nice if at all possible to determine how many IPs the list contains and just let it count down from last to first.
Upvotes: 0
Views: 552
Reputation: 54981
I'm having trouble understanding your script.
$IP = try { }
?$IP
(which I though would always be null), why?.$dnsresult
..Is this what you were trying to do?
$colComputers = @(get-content $File)
$count = $colComputers.Count
$i = 1
foreach ($strComputer in $colComputers)
{
#Write-Progress needs -percentagecomplete to make the progressbar move
Write-Progress -Activity "Working... ($i/$count)" -PercentComplete ($i/$colComputers.Count*100) -Status "Please wait."
#What is IP = try { } :S
try {
$dnsresult = [System.Net.DNS]::GetHostEntry($strComputer)
}
catch {
$dnsresult = "Fail"
}
#Do something with $dnsresults...
#Increase counter i
$i++
}
Upvotes: 2