Compartilhar via


Elevation PowerToys for the Windows PowerShell Integrated Scripting Environment (ISE)

Windows PowerShell 2.0 includes an Integrated Scripting Environment (ISE).  This application enables you to write, run, and test scripts and modules in a graphical environment.  It has features such as syntax-coloring, tab completion, visual debugging, Unicode-compliance, context-sensitive Help, and a tabbed/multi-pane user interface.

Windows PowerShell 2.0 adds an Edit command to the context menu options for Powershell script, module, and data file types (.ps1, .psm1, and .psd1 extensions).  However, if you need to edit/test a script as an Administrator you would need to right click on the start menu icon for the ISE, run it as administrator, open the script in the editor, and navigate the Command Pane to the script’s folder to run it.  So I created an Edit as Administrator PowerToy for these file types to shortcut this process.  Install PowerShellEditAsAdmin.inf to use it.

The other two PowerToys add context menu options (PowerShell ISE Here and PowerShell ISE Here as Administrator) to folders and drives to open the PowerShell ISE with the selected folder or drive as the ISE current directory.  Install PowerShellISEHere.inf and PowerShellISEHereAsAdmin.inf to use these.

When you use the “as Administrator” versions of these PowerToys, you will see the elevation prompt will be for Windows Command Processor (cmd.exe).  This happens because I am using the Start command that is built into cmd.exe to launch the ISE and set the working directory.  I initially attempted to do this with the new Start-Process PowerShell cmdlet.  However, I hit two issues that prevented me from using it.  Start-Process allows you to use the “runas” verb with the –Verb switch to start a process elevated.  Unfortunately, if you use the “runas” verb then the –WorkingDirectory switch does not work.  So then I tried elevating powershell.exe first and then using Start-Process.  Unfortunately, passing in the Start-Process cmdlet with the –Command switch kept stripping out the double quotes causing the –WorkingDirectory path to error when it contained a space in the path.  If anyone out there can figure this out, please post the solution back as a comment.

 

Important Note: For these PowerToys to work, the Elevate Command PowerToy from here must also be installed.

 

- Michael Murgolo, Senior Consultant, Microsoft Services, U.S. East Region.

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .

PowerShellISEPowertoys.zip

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed