Wednesday, May 11, 2011

Powershell Useful Scripts

List of Useful Powershell Scripts and resources


1. The powershell command that will delete all *.tmp or *.temp) file in c:\
Ref: Deleting All temp File


get-childitem c:\ -include *.tmp, *.temp -recurse | foreach ($_) {Remove-Item $_.fullname -whatif}



2. List all files recursively and output to CSV
Ref: Powershell listing of all files and owner to CSV
$arr = @()
gci C:\Projects -recurse | ? {$_.PSIsContainer -eq $False} | % {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Directory $_.DirectoryName
$obj | Add-Member NoteProperty Name $_.Name
$obj | Add-Member NoteProperty Length $_.Length
$obj | Add-Member NoteProperty Owner ((Get-ACL $_.FullName).Owner)
$arr += $obj
}
$arr | Export-CSV -notypeinformation "report.csv"</b>


3. Blog with many powershell scripts
<a target="_blank" href="http://tasteofpowershell.blogspot.com/">http://tasteofpowershell.blogspot.com</a>

No comments: