Hello fellow PowerShell users,

Last meeting (5th) of The Dutch PowerShell UserGroup I saw ISESteroids in action. And from that moment I knew it, “that is what I need”.
But the question was how does it work? (http://www.powertheshell.com/isesteroids/)

ISES

So I downloaded the 2.0 preview and did some testing. One of the best features in my opinion called refactoring ButtonRefactor.
What does it do?
Refactoring will make you code readable. Some people are bad script writes (including myself :-)). So let’s fix the bad code!

When you have started you steroids in your ISE you will click on #refactor button#. This will start an extra tab on the right side of your screen called Refactor. In this tab you have two options:
– Basic
– Advanced
ISESAdvanced
The Basic Tab
Hit the button “fix Script Now”. And your script will be readable four everyone.
My code after executing the basic refactor:

Function SetACL 
{
    param($FolderPath,$OldSID,$NewSID) 
    $ACL = Get-ChildItem $FolderPath -Recurse | Get-Acl 
    # # Now get the SDDL string: 
    foreach ($file in $ACL) 
    { 
        # $file.Path 
        $sddl = $file.Sddl 
        $sddl2 = $sddl -replace $OldSID, $NewSID 
        $file.SetSecurityDescriptorSddlForm($sddl2) 
        Set-Acl -AclObject $file -Path $file.Path 
    } 
}
#Example #
SetACL -FolderPath c:\temp -OldSID S-1-5-21-529984894-3124434191-3335185898-2239 -NewSID S-1-5-21-529984894-3124434191-3335185898-1525

Note: Every option you will change in the advacenced tab will be active in Basic tab!

The Advanced Tab

Character operations
Fix whitespace Following Backtick
Input:

	write "Following `     
	Backtick" #after the backtick I added 5 spaces

Outcome:

	write "Following `
	Backtick" #the spaces are gone

– Convert Illegal characters
Input:

	Write-host “Convert Illegal characters”

Outcome:

	Write-host "Convert Illegal characters"

As you can see the “” is replace by “”

Normalize Line Endings
I was not able to find a good example.

Reformat Structure
– Replace Semicolons with Line Breaks
 Input:

$a = "Replace" 
$b = "Semicolons"
Write-Host $a; write-host $b

 Outcome:

$a = "Replace" 
$b = "Semicolons"
Write-Host $a 
write-host $b

Code Quality Improvement
– Replace Double Quotes
Input:

$a = "Replace" 
$b = "Double" 
$c = "Quotes"

Outcome:

$a = 'Replace' 
$b = 'Double' 
$c = 'Quotes'

 

Script Block
– Remove emty Lines at start/end
Input:

Get-Process | where {

$_.name -like "*tweetdeck*"

}

Outcome:

Get-Process | where {$_.name -like "*tweetdeck*"}

 

– Align Braces (including one-liner)
Input:

if (Get-Process | where {$_.name -like "*tweetdeck*" -eq "true"} ){"OK, tweetdeck is started"}

Outcome:

if (Get-Process | where {
        $_.name -like "*tweetdeck*" -eq "true"
    }
 )
{
    "OK, tweetdeck is started"
}

 

– Align Braces (Except One-liner)
This one is the same as above but will not change anything if code is written in one line.

The options Align Braces. There you have to make a choice, “include one-liners” of “Except one-liners” you cannot run both.

Command
– Add cmdlet “Get” Verbservice
This wil translate unknown command into known get commands. If there are any matching get commands
Input:

Service
Process

Outcome:

Get-Service 
Get-Process

 

– Turns aliases into commands
Input:

$a = Get-Service | Where {$_.Name -like "*win*"} 
$a | % {$_.Status}

Outcome:

$a = Get-Service | Where-Object {$_.Name -like "*win*"} 
$a | ForEach-Object {$_.Status}

note: the question mark will not be refactored (question mark is an alias for where-object)

– Case-correct command names
Refactors command lets with casing like get-process will be Get-Process

– Case-correct command parameter names
Input:

Get-Process –nam

Outcome:

Get-Process -Name

 

– Convert Positional Parameters
Input:

Get-Process powerhsell_ise

Outcome:

Get-Process -Name powerhsell_ise

 

Pipeline
– Linebreak After Pipe
Input:

Get-Process | where {$_.name -like "*powershell*"} | select Processname

Outcome:

Get-Process | 
where {$_.name -like "*powershell*"} | 
select Processname

 

– Remove Out-null
Input:

Get-Process | out-null

Outcome:

$null = Get-Process

 

According to the ISESteroid developers is the out-null 40x slower then $null. How can you test this?

measure-command {$null = Get-Process}
measure-command {Get-Process | out-null}

 

Spaces
– Adjust Opertators
Input:

$a="test"

 Outcome:

$a = "test"

 

– Adjust Arrays
Input:

 $array = ("server1","server2","server3")

 Outcome:

$array = ("server1", "server2", "server3")

 

Variables
– Case-correct Variable Names
Input:

$TestVariable = "Test" 
$testvariable 
$tesTvAriable

 Outcome:

$TestVariable = "Test" 
$TestVariable 
$TestVariable