Archive for May, 2012

Powershell

Powershell is awesome.

Here a collection of some snippets:

Check who is accessing a file on a server:
net file | where {$_ –match “$filename”}

More:
Get-Service | Sort-Object -Descending Status | ForEach{if($_.Status
-eq “Running”){Write-Host $_.Name -ForegroundColor green} else {Write-Host $_.Na
me -ForegroundColor red}}

Get-Service | ConvertTo-Html -Property Name, Status | ForEach {if($_
-like “*<td>Running</td>*”) {$_ -replace “<tr>”, “<tr bgcolor=green>”} else {$_
-replace “<tr>”, “<tr bgcolor=red>”}} > .\get-service.html

Get-PSDrive | Sort-Object Used -Descendind

New-PSDrive -name FK -psprovider FileSystem -root C:\Temp\Powershell\Files

Set-Location FK:
Get-ChildItem * -Exclude *.tmp, *.temp | Select-Object name, length | Sort-Object Length, Name -Descending

Get-Alias | Sort-Object

Get-Service | Group-Object Status
Get-Service | Get-Member
Get-Service | where{$_.status -eq “stopped”}

Get-ChildItem | Group-Object Extension | Sort-Object Count -Descending
Get-ChildItem | Measure-Object length -average -sum -maximum -minimum
Get-ChildItem | where-object{$_.length -gt 2MB}
Get-ChildItem | where {$_.PSIsContainer}

$a=Get-ChildItem | Select-Object Extension | Sort-Object Extension -unique
$a | ForEach {“.\Neu”+$_.Extension} | ForEach {NewItem $_ -type directory}

$a=Get-ChildItem | where {$_.PsIsContainer -eq -0}
$a | foreach{Copy-Item $_.FullName (“.\Neu” + $_.Extension + “\” + $_.Name)}

Get-ChildItem | foreach{$_.IsReadOnly = -1}

Get-ADUser -Filter *
Get-Command *user*

No Comments »

admin on May 16th 2012 in PowerShell




Check out new movies online website. Download and buy movies now.
1