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.
- Michael Murgolo, Senior Consultant, Microsoft Services, U.S. East Region.
I think i know your solution to your quotes stipping issue: If you use %~s1 to pipe the path to Powershell you wont need quotes.
Substitution of batch parameters (%n) has been enhanced. You can
now use the following optional syntax:
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
%~$PATH:1 - searches the directories listed in the PATH
environment variable and expands %1 to the fully
qualified name of the first one found. If the
environment variable name is not defined or the
file is not found by the search, then this
modifier expands to the empty string
The modifiers can be combined to get compound results:
%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
%~dp$PATH:1 - searches the directories listed in the PATH
environment variable for %1 and expands to the
drive letter and path of the first one found.
Hope that helps.
P.S. I would love your help with something - ivan.dretvich.com/2011/06/how-to-run-domain-admin-tasks-without-being-logged-in-as-an-administrator/
I use Elevation PowerToy (which i have modded) and am having issues with the quotes myself. Basically the util adds a Run as %username% context menu which then in turn runs RUNAS.exe elevate.bat %* %1 etc... however if my variables have quotes in them, the RUNAS flips and links dont work (Powershell so far is the only culprit for this) - any help appreciated.