by Wojciech Sura

Powershell philosophy

One way to think about Powershell is that it is a shell version of IEnumerable Linq extensions.

For instance, let’s imagine, that we want to¬†know the size of the biggest .wav file in the folder. If we was in C#, the code would probably look like the following:

[csharp]int size = Files.Where(f => f.Name.Contains(".wav")).OrderBy(file => file.Size).Last().Select(f => f.Size);[/csharp]

PowerShell version differs only by the syntax, philosophy is the same:

[shell]PS D:\Temporary> Get-ChildItem | Where-Object {$_.Name -like "*.wav"} | Sort-Object -Property Length | Select-Object -last 1 | Select-Object Length[/shell]

They’re very similar, aren’t they?