Scripts

Using -Assist in an Assisted Module – CommandAssist

This is the the meat of CommandAssist module, providing a contextual assistant to supplying the right parameters to a command.

Getting to the Meat of It

In the last post, we created a proxy module for ActiveDirectory module, so what does that really get for us?

Starting off in a new shell, I’ve imported the AssistedAD module and I’m going to try out the -Assist parameter for Get-ADUser

Import-Module ADAssist
Get-ADUser -Assist

Initially, I was prompted for a Filter parameter, as that parameter is marked mandatory in the default parameter set. I supplied a "*" and moved on. You’ll notice that I did not have to load the ActiveDirectory module, the CommandAssist module or the ShowUI module, as the proxy module handles all that in the background for you.

What I then got was:

 

image

You’ll notice that there are three tabs, Filter, LdapFilter, and Identity.  Each tab represents a parameter set and shows the associated parameters for that set. 

You will only be able to pass parameters for one parameter set, which can alleviate the common error of

Parameter set cannot be resolved using the specified named parameters

This is a key benefit of CommandAssist versus other tab completion options.

As you add parameters, the command line at the top will change to reflect your changes to the parameters.

image

Parameters that take a specified enumeration (like AuthType in this case) will have a dropdown box with the available options.

If I change parameter sets, the command line changes to reflect my new parameter selections.

image

However, your previous selections on an alternate tab have not changed, so you can return to that tab and continue editing if you determine that is the appropriate parameter set to use.

 

What other information would you like to see here?

Please post a comment on the blog or a message on Twitter if any additional information or features you think might be useful for this!  I’d love to hear how you think this might provide value in your usage or your environment.

Creating an Assisted Module with CommandAssist

The CommandAssist module allows you to easily create proxies functions for every command in a module (or snapin).  

There is a handy command to generate these proxy modules included with the CommandAssist module. 

image

Building an Assisted Module

The easiest way to explain what happens is to walk through the usage of New-AssistedModule.  To that end, we’ll create a proxy of a module that I’ve been use regularly – the ActiveDirectory module.

NOTE: You will need to have ShowUI available in your module path (you can check with Get-Module ShowUI).  You do not need to have it loaded into your session, CommandAssist will take care of that.

First we’ll load the CommandAssist module:

Import-Module CommandAssist

Second we will load the module we want to create a proxy for:

Import-Module ActiveDirectory

NOTE: This only has to be done the first time to create the proxy.  Afterward, the proxy module will load the real module in the background.

Third we will use New-AssistedModule to create our proxy module.

$NewModulePath = c:\users\smurawski\Documents\WindowsPowerShell\Modules\AssistedAD
Get-Module ActiveDirectory |
	New-AssistedModule -ModulePath $NewModulePath

image

As noted in the screenshots, the module created has proxies for each command that add the -assist parameter.  There also is a module file that will load all of the proxies, as well as the source module (in this example, AssistedAD.psm1).

The next post will review how the -Assist parameter works.

NOTE: The proxy module will load the real module in the background (so if you distribute it, the end user will need the source module or snapin as well).

Setting Application Compatibility Flags

There was a post on the PowerShell Facebook group today asking how to set the “Run As Administrator” checkbox on the Compatibility tab of the properties for an application.

The compatibility settings are just registry entries, either under the user’s account or under the local machine.

(You can find them under HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers or

HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers)

Compatibility settings reference the path of the executable as the value and store the app compat flags in the data for the registry key.

I’ve written a quick PowerShell script to automate the setting of these compatibility flags and posted it on PoshCode.

Lake County .NET Users Group–Slide Deck and Samples

Scott Seely and Tim Stall invited me to give an introduction to PowerShell talk for the Lake County .NET Users Group yesterday evening.

We had a great turnout and a number of good questions.  Thank you to everyone who gave up part of their evening to come and learn a bit about the .NET command shell goodness that is PowerShell. 

I’ve uploaded the slide deck, sample scripts, and sample Visual Studio solution here.