News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • PowerShell ISE — Did you know you can customize it?

    Posted on RetiredGeek Comment on the AskWoody Lounge

    Home Forums Developers, developers, developers DevOps Lounge PowerShell ISE — Did you know you can customize it?

    Viewing 0 reply threads
    • Author
      Posts
      • #2274079 Reply
        RetiredGeek
        AskWoody MVP

        Hey Y’all,

        As most of you here know I love to write PS code. Well, one of the things that has always driven me half crazy, that would be the half that’s not already crazy, is version control. Yes, I know there are version control tools out there but most of them are either costly, overly complicated or online only. All things I wish to avoid.

        The way I was doing it was to have a Scripts directory where I do all my development, a directory where I keep version history, and a Production directory for the currently tested and mostly debugged code that I use on a regular basis.

        The problem was every time I was ready to implement a new version it meant copying it to two directories and renaming them at the same time. Oh yeah, and making sure I was consistent and didn’t make typing errors in the process. I have pondered a way to automate this but couldn’t come up with a workable solution until I ran across a reference on StackOverflow (sorry Woody) and then an article on the Scripting Guy’s site (sorry again Woody).

        The reference on StackOverflow pointed me to the $PSISE variable in the PowerShell ISE which gives you access to the current ISE parameters. Most of interest to me was the ability to pull the Current Tab name:

        PS> $psise.CurrentFile.DisplayName
        Dev-PSVersionControl-v-1-2.ps1
        

        and the FullPath:

        PS> $psise.currentfile.fullpath
        G:BEKDocsScriptsDev-PSVersionControl-v-1-2.ps1
        

        This gives me the information I needed to automatically process the file displayed in the current ISE tab and do the copying. So all I had to do was write a script to accomplish that task.

        As you can see from the snippets above I use a standard naming convention for my scripts in development: Dev-[script name][version information].ps1. The version information is always separated as shown above so that I have a pattern I can search for in my version control script.

        The next problem was how to execute the version control script from within the PowerShell ISE. Of course I could type: .productionpsversioncontrol.ps1 into the console window but who want’s to constantly do that? There had to be a better way, especially as my aging fingers find it harder and harder to type like I used to!

        Here is where the Scripting Guys script came in. I was googling for ways to modify the ISE environment when I came across it. It shows how to add items to the Add-Ons menu on the ISE menu bar.

        Now I had all the pieces I needed, or at least I thought, to get this project under way. I ran into a couple of problems while writing the code. First was with the FileBrowser that would not pop up on top of the ISE. This got solved, googling again, with a Function by Kaffee Krampus @StackOverflow.com. The next problem, again with FileBrowser is that it wouldn’t let me get the default directory to show up at the top of the browser window. It only allows one of the Windows special folders (Desktop,MyDocuments, etc.) to be the Root directory. Although you can set the $FolderBrowser.SelectedPath parameter and it will highlight that directory but you have to scroll down to it. Still working on solving this one, Ideas anyone?

        The last problem is again with getting an InputBox to show up on top of the ISE. I prompt the user (ME) to see if I want the current version to become the Production version. Unfortunately, it doesn’t show above the ISE window. Luckily, unlike the FileBrowser window it does show an indication on the task bar that there is another open window in the ISE so I can click there and select it. With the FileBrowser there was no indication that there was a window behind, thus seeming like the code had finished! I think I have a solution for this from my code library and it may even solve the problem with the FileBrowser but I haven’t tested it yet. (Edit: All the window problems have been solver and the special function to show the file browser has been removed simplifying the code.)

        So to recap I now have a menu selection on my ISE toolbar that will run the program. The program will prompt me to select the File History Directory and copy the program there removing the “Dev-” from the name. It will then prompt to see if I want to update the Production directory with the file. If Yes it will copy the file removing the version information in the process so it doesn’t mess up my scheduled tasks and taskbar toolbar for calling the program by having a different name.

        Obviously, if you’ve read this far you’re interested in the code so here’s a .zip file with both programs: PSVersionControl-1
        .zip MD5 Hash: D3C0817063E9C422B807692A224D6163
        Note: you’ll need to change some path variables in the code (both scripts) based on your setup.

        HTH :cheers:

         

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

        • This topic was modified 2 weeks, 4 days ago by RetiredGeek.
        • This topic was modified 2 weeks, 4 days ago by RetiredGeek. Reason: Updated .zip file
        • This topic was modified 2 weeks, 4 days ago by RetiredGeek.
        Attachments:
        2 users thanked author for this post.
    Viewing 0 reply threads

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: PowerShell ISE — Did you know you can customize it?

    You can use BBCodes to format your content.
    Your account can't use Advanced BBCodes, they will be stripped before saving.