Tag Archives: ISE

Friday Fun: Send PowerShell ISE Content to Word

geekYesterday on Facebook, Ed Wilson was lamenting about confusion of keyboard shortcuts between PowerShell and Microsoft Word. I’ve run into the same issue. Muscle memory is strong. Then the discussion turned to getting content from the PowerShell ISE into a Word document. I humorously suggested we had a plugin and it had a Ctrl+C keyboard shortcut. Then I thought, why not make this even easier!

So I put together a quick function for the PowerShell ISE.

This function will paste any selected text from the ISE into a Word document. The first time you run the function, PowerShell will create a Word document and format it for fixed width text. It will then insert your text and a new paragraph marker. The next time you run the function, it should detect that you have a document open and re-use the existing variables. The Word document will be visible so you can edit it further and save it. If you move the cursor around in the document, any new content you insert will go there.

To make this easy to use, insert this function into your PowerShell ISE profile script and add a menu item with a keyboard shortcut.

Send-ToWord

Now, I can select code from the ISE script pane and send it to Word with a quick key combination. Have fun and enjoy your weekend.

Update: I posted another version that includes an option to copy and paste as colored code.

Friday Fun: Updated ISE Scripting Geek Module

geek A few years ago I published a module with a number of functions and enhancements for the PowerShell ISE. This ISEScriptingGeek module has remained popular over the last few years. But I wrote it for PowerShell v2. I have also come up with a number of new additions to the ISE that I use to make scripting easier. So I have gone ahead and updated the module.

The new module includes most of the original features, many of which are added to a custom add-ons menu.

scriptinggeek-addon-menu

To use the module, import it in the ISE or in your ISE profile script. Once imported you can view all of the commands.

Most of the commands will have help. I’m not going to go into detail about every command and menu option. I incorporated my scripting help module as well to provide documentation on some of the validation attributes. I think you should load up some test files and try things out.

The final thing I have done is to include some ISE theme files. To import them, go to Tools – Options and click on Manage Themes. Click on Import and navigate to the Themes folder in the module directory (…\documents\WindowsPowerShell\Modules\ISEScriptingGeek\Themes). You should see 3 files. Import one or more, select it and click OK.

grayscaletheme

monoyellow-theme

vim-theme
This version requires PowerShell 4.0 or later. DownloadISEScriptingGeek-v3.1 and extract to your modules directory.

If you have questions or run into a problem, feel free to post a comment. I especially would love to hear about your favorite features from the module.

Enjoy and happy scripting.

DSC Resource Snippets

talkbubbleA few days ago I posted a PowerShell script that would generate a DSC configuration template. The idea was to generate all the code you might need and let you whittle it down to just what you need. On my primary system, I don’t have any community or experimental DSC resources so my configuration template script only gets the default resources. Towards the end of the article I mentioned that another option would be to create snippets you could use in the PowerShell ISE. So I did.

In PowerShell 4 Microsoft already includes a simple  DSC configuration snippet. In the ISE,  hit Ctrl+J and start typing DSC and you should see a snippet title DSC Configuration (simple).  I ran my configuration template script and then converted each resource into its own snippet just for you.

Download DSC-Resource-Snippets.zip and extract the .ps1xml files to your Snippets directory, C:\Users\\Documents\WindowsPowerShell\Snippets. That folder may not exist if you have not created of your own snippets. When you start the ISE and press Ctrl+J and start typing DSC you should see a snippet for each resource.

dsc-snippets

Find the one you want and press Enter. Use these snippets in conjunction with the DSC configuration snippet and you are practically finished with just a few key strokes. Edit and enjoy.