Archive for PowerShell

PowerShell

PowerShell is an amazing framework designed to streamline tasks. The main benefits of PowerShell is that it built and integrated to the .NET framework and provides core functionaly to COM and WMI.

If you have done any siginificant work with Linux then most likely you are experienced with Bash Scripts and in DOS batch files, of course there are also PowerShell scripts.

In addition, in PowerShell, there are small programs called cmdlets. The programs are then compiled into a DLL which then can be loaded as part of another script. It is a way of reusing and pipelining processes (think pipes and filters pattern) with objects instead of text input!

If you are used to Bash/MS-DOS it will make you happy to know most of the typical commands have aliases and you can use them right away!

  • List all files = ls/dir
  • Current Dir = pwd/cd
  • Read file = cat/type
  • Clear screen = clear/cls
  • Copy = cp/copy
  • Move = mv/move
  • Delete =rm/rmdir/del
  • Rename = mv/ren/rename
  • Write = echo
  • List processes = ps/tlist/tasklisk

PowerShell is great because if you have some experience with .NET and scripting you are a pro right away.  To conclude, here my favorite script for parsing long log files courtesy of PowerShell.com:

foreach($line in (Get-Content $env:windirwindowsupdate.log `
-ReadCount 0 -Encoding UTF8)) `
{ if ($line -like '*successfully installed*') `
{ ($line -split ': ')[-1]}}