Posts tagged ‘powershell’

Copy files using PowerShell and Robocopy

This script collects all log files three levels deep into your Windows folder and copies them to some other folder.

robocopy $env:windir\ c:\logfiles\ *.log /R:0 /LEV:3 /S /XD *winsxs*  | 
Where-Object { $_} | 
Foreach-Object { 
Write-Progress "Robocopy is looking for LOG-files in:" $_.Split([char]9)[-1] 
}
$files = dir c:\logfiles *.log -Recurse
$files | Move-Item -Destination c:\logfiles\ -Force
dir c:\logfiles | Where-Object { $_.psiscontainer } | del -Recurse -Force

Credit to http://www.powershell.com

  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • LinkedIn
  • RSS
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • email
  • MySpace
  • PDF
  • Print
  • Reddit
  • Tumblr

How to run a PowerShell script as a Scheduled Task

schtasks /CREATE /TN CheckHealthScript /TR "powershell.exe `
  -noprofile -executionpolicy Unrestricted `
  -file %public%\checkhealth.ps1" /IT /RL HIGHEST /SC DAILY

And to delete the task

schtasks /DELETE /TN CheckHealthScript
  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • LinkedIn
  • RSS
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • email
  • MySpace
  • PDF
  • Print
  • Reddit
  • Tumblr

PowerShell webscraper tool

A little snippet for scraping a site for matches using regular expressions.

$regex = [RegEx]'(.*LPE.*)'
 
$url = 'http://mute.nu/'
$wc = New-Object System.Net.WebClient
$content = $wc.DownloadString($url)
 
#echo $content
 
$regex.Matches($content) | Foreach-Object { $_.Groups[1].Value }

This will match everything before and after the string LPE on this site.

  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • LinkedIn
  • RSS
  • StumbleUpon
  • Google Bookmarks
  • Yahoo! Buzz
  • email
  • MySpace
  • PDF
  • Print
  • Reddit
  • Tumblr