Archive for the ‘PowerShell’ category

David Cumps writes: Using PowerShell, Writing and Debugging Cmdlets

August 20, 2007

Post by David Cumps:

The prompt is dead, long live the prompt! That’s the feeling PowerShell should give you, the new command line shell from Microsoft. Today, I’ll try to determine exactly what the Power part in PowerShell stands for.

PowerShell - Layout - Cmdlet

Read more at http://blog.cumps.be/using-powershell-writing-and-debugging-cmdlets/

Using PowerShell, Writing and Debugging Cmdlets

Advertisements

Touched By PowerShell

July 25, 2007

 

Today I was asked how to “touch” all files in a folder in Windows to set the Modified timestamp to now. If I was asked about the Created timestamp I would have suggested to copy the files to a new folder and use the copies which will have a new Created timestamp. Unfortunately Windows doesn’t seem to have an easy way to edit the Modified timestamp.

Thankfully, everyone who has Windows also has PowerShell, or should have, or should upgrade their OS. With PowerShell, touching files is easy:

Get-ChildItem * | % { $_.LastWriteTime = [DateTime]::Now }

Touched By PowerShell

PowerCleaning

June 29, 2007

 

I’ve often wanted to easily delete all old files below a folder that haven’t been modified for a while. I’ve written a very small PowerShell function to do just that. By default it emulates the Disk Cleanup tool in Windows and deletes all files older than one week from the environment temp folder.

function Remove-TemporaryItems ([string] $path = ($env:TEMP), [TimeSpan] $age = (New-Object System.TimeSpan 7, 0, 0, 0) ) {
    $files = Get-ChildItem $env:TEMP -recurse | `
        Where-Object { ! $_.PSIsContainer -and $_.LastWriteTime.Add($age) -le [DateTime]::Now };
    $files | Remove-Item;
    $files;
}

PowerCleaning