Loading ...

Some Power Shell Notes

Hello everybody,

today I want to share few words about powershell usage. 

So, recently I've got some tasks which is related to usage of powershell scripts in order to automate some execution.

One of discoveries in PowerShell for me was pipelining with usage of Where-Object. Consider following example:

Get-ChildItem | Where-Object {$_.Name.Length -gt 10 }

It has two parts: Get-ChildItem and Where-Object.

Get-ChildItem will get all items in directory, and pipeline them into WhereObject, which in turn will produce as output those, which has Name longer then 10 characters. 

Another interesting part of pipelines is that you can pipeline objects from one to another. Consider code below:

Get-ChildItem | Select-Object Name, Length | Sort-Object Name

The code will take files and folders at some location and pass them to Select-Object. Select-Object will take properties from it Name and Length and pass them into Sort-Object, and Sort-Object by itself will do sorting by Name

Another useful feature of PowerShell is Out-GridView object.  There is a saying, that one picture is better then thousands of words. Here is output from following powershell command:

Get-ChildItem | Select-Object Name, Length | Sort-Object Name | Out-GridView

powerShellPicture.png

 

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5