Tag Archives: Sapien

Much TODO with Sapien PowerShell Studio 2016 and Pester

I’ve been working a lot with Peter lately, and as I’ve blogged about before I use Sapien’s PowerShell Studio tool. The new 2016 version has an interesting new capability that while it may seem small, works extremely well when developing Pester tests.

When I create a Pester test, for example for a function, I outline all the things I need to test. Once I’ve created the list, I then go into my test script, and create It statements for each test.

Pester has a switch you can pass to It called –Pending. This will cause Pester to skip over the test. This allows you to stub out needed tests without them interfering with your code. Pester itself will even display pending tests in its output.

    It ‘is a test yet to be implemented’ –Pending {

    }

Knowing you have a test to implement, and being able to quickly find where that code is, are two different things. Tests can get rather long rather quickly. I also admit I don’t always develop the tests linearly. For example, I may develop part of a unit test, then copy that code lower in the script and adapt it for the acceptance test. Then go back up to the next It assertion I need to work on.

That’s where a nifty little feature in the new 2016 version of PowerShell Studio comes in handy. When you add a #TODO: statement (pound sign TODO followed by a colon), it will appear in the navigation drop down in the PowerShell Studio editor.

Here’s a little example. In the screen capture below, you see I have the first test, which has been implemented. Following are two more tests using the –Pending switch.

image

 

Here’s a slightly closer view. You can see the various #TODO: comments. When I click in the navigation drop down, these TODOs show up, allowing me to jump to them easily.

image

This has been surprisingly useful when working with Pester. While the example shown above seems trivial, some of my tests are hundreds of lines long. Being able to quickly navigate to tests I still need to implement keeps my workflow going ahead at a good pace, and keeps me from getting frustrated trying to find the next test I want to implement.

I also have to say the new dark color theme leaves me all warm and fuzzy inside. Smile

SAPIEN PowerShell Studio 2014–Customization Redux

Earlier in the week (post) I started this series on SAPIEN PowerShell Studio 2014 discussing customization. How appropriate to wrap up returning to that same topic.

The original version I downloaded was 4.1.47. Late last night I found out a new version has already been released, 4.1.49. I downloaded it and to my pleasure found two more options for color themes, Visual Studio 2013 Dark and Visual Studio 2013 Light.

image

If you read my earlier post you’ll already know what I picked, the new VS dark theme is much darker and richer than the Office 2013 black theme. Take a look:

image

Note that the colors of the editor are not set with this selection, only the backgrounds for things like the menus, title bar, borders, etc. If you want the nifty dark settings in the editor you’ll still need to set them yourself, or use the XML data I listed at the bottom of the already mentioned first post in the series.

You may be wondering how I found out about the update with these new features. Well, SAPIEN has a particularly nice set of forums, located at http://sapien.com/forums/. As you might expect there are forums for all of their products, but you will also find forums for the various scripting languages. In here you can ask generic questions not directly related to any of their products.

After my initial download I had placed a post asking some questions, specifically this post: http://sapien.com/forums/viewtopic.php?f=12&t=7435

Within an hour a support person named David had answered my questions, one of which as you’ll see was on the color themes.

Now, what particularly impressed me was four days later David remembered my forum post, and placed a follow up post letting me know about the update with the new dark color theme. Now that is some outstanding customer service, big kudos to David (whoever you are) for the follow up.

SAPIEN PowerShell Studio 2014–Tools

As I’ve been working with the SAPIEN PowerShell Studio (website), there are a few things in the Tools menu I have found useful. I wanted to call these out, as some may overlook what could be a set of very beneficial items.

If you navigate to the tools menu, over to the left you’ll see these tools:

image

Find in Files is pretty obvious, but don’t over look it. How many times have you been working on something and thought “OK, I wrote something like this once, but just which file was it in?” This will allow you to search for a string you enter. You can specify the folder, and can add a list of file types to look through. By default it will limit the search to PowerShell oriented files, but you could change this easily if, for example, you wanted to search through a CSV file. Especially nice is the ability to use regular expressions or wild cards.

image

Compare Files does just what it says. You select two files, and it will compare them and produce a report of the differences.

Custom Tool is interesting, essentially it becomes a menu you can customize and use to launch executables, parameterized as you want it. Rather than repeating what is already published, I’ll point you to a blog post on the SAPIEN website which explains how to customize this for your needs.

http://www.sapien.com/blog/2013/01/08/powershell-studio-2012-with-git-subversion-and-mercurial-oh-my/

Check Syntax is great, it will quickly look through the current script and identify any syntax errors. I’ve gotten to the point where I always use this after making major edits to a script. Much nicer to find out this way rather than after you start running the script.

Verify Script is similar, but instead of syntax it checks to see if all the required “pieces parts” are present. For example, it looks at any Import-Module statements and validates that those modules are indeed available, and that the functions you reference are there.

Sign Script I haven’t needed to use yet, but if you are in an environment where this is required than this will be a great little shortcut for you.

Restore Points are the last item on the list. When you create a restore point, you can then go make changes to your code, then if you don’t like them you can Rewind to the previous restore point, or use the Restore button to revert back to the point at which you created the original restore point. Once you are happy with your code you can then Delete the restore point.

This is ideal for those situations where you think “hmm, I wonder if this would work…” and want to try out something. But, if it doesn’t you want to be able to roll back to the point prior to your editing. Previously you would have needed to make a copy of the PS1 (or whatever you are editing) file, make changes, then either copy the file back or copy parts of it back into your code. Yuck. Restore Points make this much easier. Even better, the persist between sessions. You can close the entire PowerShell Studio, and when you return and reopen the file those restore points are still active.

I am amazed how little many developers know about the tools at their disposal. Often people look no further than the main tab and never explore the rest of their environment.

Even though individually these tools may seem like small things, together they provide quite a toolbox to solve a lot of common, everyday issues developers face. I hope it encourages you to more fully explore the SAPIEN PowerShell Studio 2014.

SAPIEN PowerShell Studio 2014–Navigation

Continuing my series on SAPIEN PowerShell Studio (website), the next feature I want to focus on is Navigation, both of your files and inside the code.

From a file perspective, PowerShell Studio allows you to organize into projects. Right now I am working on two modules plus one set of scripts which accomplish a common task. Each module I have organized into a project. Here is the project window for one of the modules I’m developing:

image

This allows me to quickly navigate between the various files I have in the project. I can easily open and close these files as I work on them without having to go through the laborious “File, Open…” mechanism in the PowerShell ISE. My other project is the collection of files which consume these modules. Each file performs a specific task, but ultimately get us to a completed solution. Using the Project feature in PowerShell Studio allows me to organize these into one solution, quickly jumping back and forth between them.

Even better, I can have these three items open in separate PowerShell Studio windows at the same time. Note that I did need to go into the Options window, and check on “Allow multiple instances” option.

image

This is a far, far easier way to work than inside the PowerShell IDE included with the native Microsoft PowerShell installation. Speaking of easy, let’s look at code navigation.

One of the first features is the functions window. This simply lists all the functions in the currently open code editor window. Simply double click on one to jump to that function.

image

This is awesome in an large script with many functions.

Next is the ability to easily expand / contract code.

image

You can quickly expand and collapse sections of code to make scrolling through it easier, allowing you to look at only the sections you need to see. I have one script of nearly 1,500 lines, and have placed regions throughout. This feature allows me to focus only on the code I want, and neatly hide what I am not currently working on.

The next thing I’d like to show is the split code window. This allows me to take a single code window, and look at two different parts at the same time. While many editors do have this feature, it is especially great for PowerShell.

image

The final feature I want to mention is Bookmarks. We’ve all had big scripts where we are working on a section of code, need to go look at something elsewhere in the code, then need to jump back to the previous line we were working on. It is useful, then, to drop a bookmark, scroll down to the code you want to look at, then quickly jump back.

image

Using the Bookmark menu you can place a marker in your code. Over to the left of the editor you’ll see the marker.

image

Now you can scroll down and find the other piece of code you want to look at. If it is something you’ll want to come back to continually, you can place a second bookmark. Then using the Next/Previous bookmark buttons you can easily jump back and forth between the two locations in your code.

image

While these are features that come with some editors, such as Visual Studio, they are certainly lacking in the PowerShell ISE. These are basic but critical features that make you much more productive when developing your own PowerShell scripts.

SAPIEN PowerShell Studio 2014–Customization

SAPIEN Technologies (website) released their PowerShell tool, PowerShell Studio 2014 this month. They give a 45 day trial, so I’ve downloaded it and am truly impressed. In the first day it already helped my productivity. I thought I’d spend a few blog posts looking at some of the features.

The focus for this first post is customization. Out of the box, here is the look and feel (click on image for bigger view):

image

And here is what my environment looks like:

image

Yes, I am one of those oddballs who likes dark color themes. And it was pretty easy to set this up. First, in the upper right there’s a drop down. From it you can pick from one of the standard “Office” themes.

image

As you can see, I selected Office 2012 Black. This gives the darker colors that surround the environment. Next to tackle the colors within the editor. In the Home toolbar there is an Options button…

image

which brings up an Options window.

image

Through the Font Style button you can set the values for each

image

Once you have everything set the way you wish, you can save your settings and move them from machine to machine. Just go back to the General tab.

image

Through it you can Save All Settings, which saves everything, from the colors to the layout of all the panels on the screen. Alternately, you can save just the editor settings by clicking the Save Editor Settings. To make it easy should you like this theme I’ve pasted the XML for the dark editor at the end of this blog. All you’ll have to do is copy it to notepad, save it as an XML file, then use the “Load Settings” feature to load it.

PowerShell Studio also makes it easy to alter the layout of the various panels that surround the editor. At the bottom left is a “Layouts” button. Clicking it shows the layouts optimized for the task you are doing.

image

Once you get a layout you like, you can save your custom layout for later. You’ll note my customized layout that I previously saved has been added to the list (ArcaneCode Layout). Now you can quickly jump back and forth between layouts to work on a specific task.

I love the fact that PowerShell Studio 2014 allows me to customize the environment to work the way I want to. You too can customize to your favorite settings.

Finally, as promised, here is the XML for my editor settings.

 

<registry name="SOFTWARE\SAPIEN Technologies, Inc.\PowerShell Studio 2014">
  <k name="Editor">
    <v name="ShowLineNumbers" value="1" kind="DWord" />
    <v name="EnableOutlining" value="1" kind="DWord" />
    <v name="EnableCurrentLineHighlighting" value="0" kind="DWord" />
    <v name="EnableAutoComplete" value="1" kind="DWord" />
    <v name="EnableObjectDescriptions" value="1" kind="DWord" />
    <v name="ShowColumnGuide" value="0" kind="DWord" />
    <v name="ColumnGuide" value="80" kind="DWord" />
    <v name="EnableTrackChanges" value="1" kind="DWord" />
    <v name="EnableAutomaticSyntaxCheck" value="1" kind="DWord" />
    <v name="EnableAliasTabExpansion" value="1" kind="DWord" />
    <v name="EnableCmdletAutoSelect" value="1" kind="DWord" />
    <v name="ConvertTabsIntoSpaces" value="1" kind="DWord" />
    <v name="TabSize" value="2" kind="DWord" />
    <v name="ShowModuleCmdlets" value="1" kind="DWord" />
    <v name="AutoCompleteRequiresExactMatch" value="0" kind="DWord" />
    <v name="AutoInsertModules" value="1" kind="DWord" />
    <v name="ShowExternalTools" value="1" kind="DWord" />
    <v name="EnableDotSourcePrimalSense" value="1" kind="DWord" />
    <k name="Code Formatting">
      <v name="EnableSmartIndent" value="1" kind="DWord" />
      <v name="AutomaticallyFormatOnNewLine" value="1" kind="DWord" />
      <v name="AutomaticallyFormatOnOpenBraces" value="1" kind="DWord" />
      <v name="AutomaticallyFormatOnSemicolon" value="1" kind="DWord" />
      <v name="CurlyBracketsNewLine" value="1" kind="DWord" />
      <v name="IndentParamBlock" value="1" kind="DWord" />
      <v name="IndentAttributeParameters" value="2" kind="DWord" />
      <v name="AlignParameters" value="1" kind="DWord" />
      <v name="AlignAttributeParameters" value="1" kind="DWord" />
    </k>
    <k name="Default Assemblies">
      <v name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" value="" kind="String" />
      <v name="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" value="" kind="String" />
      <v name="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" value="" kind="String" />
      <v name="System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" value="" kind="String" />
    </k>
    <k name="Style">
      <v name="FontName" value="Consolas" kind="String" />
      <v name="FontSize" value="11" kind="String" />
      <v name="BackColor" value="-16777216" kind="DWord" />
      <k name="Alias">
        <v name="Bold" value="True" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-1" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Cmdlet">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-160" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Code Snippet Field">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-16711681" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Command As Parameter">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="True" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-256" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Comment">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-5329234" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="External Tool">
        <v name="Bold" value="True" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-65536" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Function">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-256" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Highlighted Reference">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-65281" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Number">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-6750690" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Operator">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-1" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Parameter">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-256" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Parameter Attribute">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-16722899" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Reserved Word">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-256" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="String">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-16722899" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Text">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-1" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Type">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-9144343" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Unknown Command">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-1" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
      <k name="Variable">
        <v name="Bold" value="False" kind="String" />
        <v name="Italic" value="False" kind="String" />
        <v name="Underline" value="False" kind="String" />
        <v name="ForeColor" value="-16722899" kind="DWord" />
        <v name="BackColor" value="-16777216" kind="DWord" />
      </k>
    </k>
  </k>
</registry>

SAPIEN PowerShell Studio 2012

Over the next few blog posts I thought I’d present some of the various PowerShell IDE’s on the market. Yes, that’s right, there’s more out there then just the IDE that ships with PowerShell. I thought I’d kick things off with the “Cadillac” of tools, SAPIEN PowerShell Studio 2012.

This by far is the most comprehensive tool of any on the market. It’s key selling point is the ability to quickly and easily create Windows Forms that can be called from, and raise events in, your PowerShell scripts.

OK, I can already hear you. “Hey Robert this is supposed to be scripts, what do we need Windows Forms for?” That’s a great question.

A very common task to do in scripting is the creation of virtual machines. You can imagine though all of the things you would need to enter in order to create the machine. What’s the name? What’s the activation key? What do you want installed? SQL Server? SharePoint?

You could, of course, have the script prompt you one question at a time. Or have a vast array of command line switches and parameters you need to enter just right in order to run the script. You could reduce complexity by having multiple scripts, but then you increase the workload. Then there’s the issue of who is going to run the script.

It would be far preferable to have a simple, single windows dialog pop up and ask all these questions at once. The person running the script could enter the information in any order, and when they were done just click an big OK button to launch the script.

This also expands the sphere of people who can run the script. Now you will be able to let an experienced PowerShell developer create the complex script, then give it to someone who may not even know PowerShell. They just run a single command, enter in some information into an easy to understand Windows Form, and they are off and running.

But Windows Forms are just the tip of the iceberg. For example, PowerShell Studio makes it easy to package your scripts into executables. Yep, you can take all your proprietary code and keep it safe from prying eyes by compiling it into an easy to distribute EXE file. 

It also has the ability to run your scripts in either 32 or 64 bit mode, all within the same editor. Very nice if you are having to support older systems as well as more modern ones.

From a development standpoint, it has the nice feature of organizing your scripts into projects. This makes management of them much easier.

It has an outstanding editor, with a great help system, and a snippet library loaded up with snippet goodness. The object browser is one of my favorite features. Using it you can drill down into not only PowerShell objects, but .Net, WMI, the file system, and even databases. I find this incredibly useful, I can quickly lookup info without having to leave my IDE.

I will admit that at $349 (as I write this), it’s not the cheapest of the PowerShell IDE’s on the market. However I’m a firm believer in “you get what you pay for”. This price is low enough that it should be a no brainer for any sized company, from a huge multinational corporation to a single person consultant. By taking advantage of the features in SAPIEN’s PowerShell Studio 2012 you’ll recap that back in a very short time.

Without a doubt this is the most feature rich PowerShell IDE I’ve seen. It seems to have everything but the kitchen sink. And I wouldn’t be surprised if that’s in there too and I just haven’t found it yet.

iPowerShell

As a consultant I travel a lot, and am usually on my small laptop with it’s 13 inch screen. A great size for travel, but a bit small on occasion. Doing PowerShell I often want to look things up, but it’s a pain having to jump back and forth between my editor and the help.

I have e-books on PowerShell which I can read on my various e-book devices, but as you might expect with a book they are not highly interactive. So the other day I ran across a solution for, of all things, my iPad.

It’s called iPowerShell, from the folks at Sapien. It was less than five dollars (US), and they have both iPad and iPhone / iPod Touch versions. It provides interactive access to the PowerShell help system, allowing you to quickly drill down into Cmdlets, Aliases, Providers, and more.

image

 

What I love most about iPowerShell is it’s extensibility. It uses the standard PowerShell help file format. That means you can write your own custom help files and use them not just in regular PowerShell but iPowerShell and other products that incorporate standard help.

This brings up some great possibilities. Many companies have generated their own set of custom modules and cmdlets. Often they have already created help files to go with them. Now those same help files can be used by simply importing them into iPowerShell.

If I had any wishes for iPowerShell, there’s be two. First, it’d be nice to have the basic syntax included. For example, there’s two ways to do the foreach command, it’d be nice to have those documented for easy lookup in iPowerShell. Second, right now the cmdlets are sorted alphabetically by the verbs. It’d be nice if there was a way to have them sorted by the nouns. There is a search feature though, which greatly alleviates that need.

Incidentally I found out about the tool because of my post on PowerShell Training. Over on the BIDN version of the post, a reader had posted a link to Windows PowerShell 2.0 TFM by Don Jones and Jeffery Hicks. This is an extremely comprehensive book, one that I immediately bought and have been reading ever since (hence explaining why I was up until 2 am this morning). You can get it in PDF format directly from Sapien at the link above, or in print format from Amazon. Highly recommended.

Sapien has some other cool, free community tools I plan to blog about in the near future, so stay tuned. In the meantime if you are both a PowerShell coder and iPod / iPhone / iPod Touch owner I think you’ll enjoy this inexpensive app.