During Foreach read another foreach in powershell -



During Foreach read another foreach in powershell -

hi powershell gurus out there. have foreach opens url urllistl.txt , doing measure-command on them. result measure-command writes event-log. in text file have country list, like: usa canada brazil , on.... want in write eventlogs message read text file , write measure-command result in message part of eventlog. below script works fine creates 2 entries each url.

{ $urllistfile = "c:\yourname\urllist.txt" $urllist = get-content $urllistfile -erroraction silentlycontinue foreach ($uri in $urllist) { $time = measure-command { c:\yourname\mainscript.ps1} $time.totalseconds $countrycode = (get-content c:\yourname\urllistcountry.txt) foreach ($sitecode in $countrycode) { $logfileexist = get-eventlog -list | where-object { $_.logdisplayname -eq "scriptcheck" } if (! $logfileexist) { new-eventlog -logname "scriptcheck" -source "scripts" } if ($time.totalseconds -lt 25) { write-eventlog -logname "scriptcheck" -source "scripts" -entrytype info -eventid 100 -message " $sitecode `ntotal time: $time" } elseif ($time.totalseconds -gt 25) { write-eventlog -logname "scriptcheck" -source "scripts" -entrytype warning -eventid 101 -message " $sitecode `ntotal time: $time" } } }

}

if (get-process -name iexplore -erroraction silentlycontinue) { stop-process -name iexplore } measure-site

powershell foreach

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -