Tag Archives: ISE

Send from PowerShell ISE to Microsoft Word Revisited

Many of you seemed to like my little PowerShell ISE add-on to send text from the script pane to a Word document. I should have known someone would ask about a way to make it colorized. You can manually select lines in a script and when you paste them into Word they automatically inherit the colorized tokens. Unfortunately, coming up with a PowerShell equivalent is much more complicated.

If you search around you’ll find plenty of tools and scripts for generating HTML and colorized output from the ISE. I tried incorporating some of them into my script but they were much more complicated than I wanted to deal with. All I really needed was a simple Ctrl+C command. So I cheated. I decided to use the SendKeys() method from VBScript.

I added a new switch parameter to the function called Colorized. This meant I also needed an additional menu shortcut.

You’ll notice that there is no keyboard shortcut. At least for me, I got inconsistent results using a keyboard shortcut, and often nothing. But if I selected the menu item, it always seemed to work.

Here is the complete updated function.

I can’t guarantee the color copy and paste will work 100% of the time. Otherwise, you can always use traditional keyboard shortcuts: Ctrl+C,Alt+Tab (to Word), Ctrl+V.

Enjoy.

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.