Scripting >> Powershell >> 2.0 >> Examples

 

Download a web page

> $web = Net.WebClient

if get an error, try the following instead

> $web = [System.Net.WebClient]

> $web.DownloadString("http://www.example.com") 

 

To obtain the top 5 process by CPU percent utilization in decending order 

$CPUPercent = @{   
Name = 'CPUPercent'
Expression = {
$TotalSec = (New-TimeSpan -Start $_.StartTime).TotalSeconds
[Math]::Round( ($_.CPU * 100 / $TotalSec), 2) }
}

Get-Process | Select-Object -Property Name, CPU, $CPUPercent, Description |
Sort-Object -Property CPUPercent -Descending |
Select-Object -First 5