Mittwoch, 20. September 2017

Scripting On Steroids

Hi guys, this is Lewis Kaylen and welcome to my first blog post ever. Today I want to tell you something about my personal experience of ISE Steroids. Since there already are a lot of introductions to ISE Steroids, I think it is time for a more personal view about it.

But first things first. I am from Germany and still training to become a system integrator. Since my training started more than two years ago, I often felt like, “Man, I am doing this awful work for the 100th time, isn’t there any way to automate it, so I do not have to do it a trillion times?” Yeah, there is. It is called PowerShell. And it is indeed very powerful. Thing is, if you have no experience working with command line based shells, you are literally … (You know what I mean). PowerShell has so many features, cmdlets and integrated stuff that you will lose yourself in it nearly instantly. Yep, that’s what happened to me. But I took the challenge, fell in love with Ed Wilson, Boe Prox, Chris Webb and all the other blog writers and became very addicted to PowerShell and its capabilities. But still, my first scripts where really messed up, simply due to lack of experience. After thousands and thousands of lines of code you will obtain that experience and even then, there is still so much to learn about PowerShell and its underlying features. Today, for example, I use a lot of .Net code because it executes faster than using the provided cmdlets. However, default ISE lacks a lot features that are essential for writing scripts with hundreds of lines. It is enough to write little scripts and I even managed more than 2000 lines in one single script with it, but you will become crazy over time. So ISE is a fine tool for some minor daily scripting, but it is far away from being a full IDE. So I started investigating if there are some advanced tools which enhance my scripting experience. And yes, there are. A lot. For example, PowerShell Studio. That will cost you a ton of money. But I would assume that it is totally worth it. Then there is PowerShell Plus which is free of charge. And then, we have ISE Steroids and today I will tell you how it enhanced my scripting experience.




{Curly Brackets}:

You ever messed up your code like in the first picture?





This is just one small but very important feature of ISE Steroids. However there are a lot of auto-format and auto-correct functions in Steroids. Just to name a few:

-   Replacing Illegal Characters (For all of you who like to copy-paste code)
-   Right use of single and double quotes
-   Replacing aliases with complete cmdlet names

This list could be much longer and I really appreciate all the re-formatting help of Steroids.


PSSharper

PSSharper is one of those features you cannot live without when you became accustomed to it. It does not only show errors, which is something very important, because error handling in ISE sucks. It goes even further for you. Ever asked yourself what is the difference between single and double quotes? Where you should use it and where not? Or that there might be some performance related things to it? No? Then hit ‘Why is PSSharper suggesting this?’ and you will know. You forgot to write a useful synopsis again? PSSharper will tell you and will create a default command line based help where you can explain and describe your work and how to use it. So basically PSSharper makes sure you use a lot of best practices and believe me, if you are no decent developer, there might be some best practices you do not know of yet. This means, you can rewrite a lot of your old code to match those best practices. That might be a hell of a work if you have a great self-written script repository. But believe me, it is totally worth it.


Turning Code into Exe
Right. You read correctly. Tired of setting execution policies around your clients’? Or using batch files to invoke PowerShell scripts? Then you want to use this feature. I personally tested it with my self-written deployment framework, which is about 2000 lines of code and it works perfectly. Even, and that is really wonderful, every environmental related variable works! $PSScriptRoot is one of those environmental variables, which are mandatory for my script.




You might wonder if spending at least 100 bucks for a license is worth it. If you ask me. Totally! Especially if you are new to PowerShell scripting, PSSharper will save you a lot of time and you will not get lost in your own code too easily. If you already got used to ISE, prepare to use it on a whole new level. One more thing that is very important to me. You can automate its installation process:

function Install-Steroids{

$PSProfileDir = ([IO.FileInfo]::new($profile)).Directory

If (([IO.Directory]::Exists($PSProfileDir)) -eq $false){
                   
$null=[ IO.Directory]::CreateDirectory($PSProfileDir)
                   
}

If (([IO.File]::Exists("$PSProfileDir\Microsoft.PowerShellISE_profile.ps1")) -eq $false){
                   
$null=[IO.File]::Create("$PSProfileDir\Microsoft.PowerShellISE_profile.ps1")
}

Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Install-Module -Name ISESteroids -Scope CurrentUser -Force -SkipPublisherCheck #Risky

If (((Get-Content -Path "$PSProfileDir\Microsoft.PowerShellISE_profile.ps1") -notcontains "Start-Steroids") -eq $true){
               
Add-Content -Path "$PSProfileDir\Microsoft.PowerShellISE_profile.ps1" –Value "`n`nStart-Steroids" -Force
               
}
}



This was my very personal view of ISE Steroids. You might check it for your own. It is definitely worth your time.


Thank you.