Difference between revisions of "Powershell"

From Richard's Wiki
Jump to: navigation, search
Line 2: Line 2:
 
  get-childitem . -include *scc,bin,obj -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
 
  get-childitem . -include *scc,bin,obj -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
  
* Poll a website and log response times:
+
* Periodically poll a website and log response times:
 
  $url="http://xml.weather.yahoo.com/forecastrss?p=10036"
 
  $url="http://xml.weather.yahoo.com/forecastrss?p=10036"
 
  $web = new-object system.net.webclient
 
  $web = new-object system.net.webclient

Revision as of 17:19, 6 July 2009

  • Recursive delete of files:
get-childitem . -include *scc,bin,obj -recurse | foreach ($_) {remove-item -recurse -force $_.fullname}
  • Periodically poll a website and log response times:
$url="http://xml.weather.yahoo.com/forecastrss?p=10036"
$web = new-object system.net.webclient
$datetime = new-object system.datetime
$log = "log.txt"
while (1) {
 $start = [DateTime]::Now
 $zz = $web.DownloadString($url)
 $end = [DateTime]::Now
 $duration = $end - $start
 "" + [DateTime]::Now + ": Duration " + $duration  >> $log
 sleep 60
}