PowerShell - a new console power

Many time ago, i wrote my first batch file. Some script to do some stuff for me. I'm laizy, i admit. But i hate it, to write it in VBScript or in other script languages. Then Microsoft announced a new console application (better shell), named Monad, who will be (is) .NET powered. Since i work pretty much in C#, i was anxious to try to write my own script in a language of my choice . So, after presentation yesterday, i find out, there is much more in Monad (PowerShell), that just scripting. PowerShell will achieve the same results as VBScript, but with fewer commands. First great thing is alias. Alias is the name of your choice for some command.

Example:

dir is an alias for get-childitem

Basicly is the same, if you write dir or use get-childitem command. So, i wrote some aliases and shutdown PowerShell. After opening PowerShell again, my aliases were gone. So, after googling around, i found out this article, how to save them for future usage.

Nice about Power Shell is object-oriented approach. Now you can use in command line command like this:

$selector = New-Object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root

SearchRoot is a property. So, you can use C# to create a class, then expose some property to public and after installing the cmdlets, you can use that property to your own satisfaction Wink Pretty cool...

My main concerne was to write some functionality in C#  to support my laizyness Stick out tongue  Miha has shown, how to create a cmdlets (dll, that execute some command for you). So, after reading about functionality, google gives me a link to templates for building PowerShell apps. Usefull for those, who dont know which reference and which class they should inherit or override it.


There are many articles about creating Cmdlets. I recommend to read links, listed below:

I will create an video about creating an cmdlet. If time and boss will permitt me ...

 

Avtor: bojanv, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.