I forgot about $args. :) The main issue/concern I had with the way I was doing it was that I had to mostly duplicate the Process{} in the If..Else and I was hoping there was a "cleaner" way to do it.
Although.. I tested the function you provided, and if I do "Start-elevated -executable notepad test.txt" it tells me that A positional parameter cannot be found that accepts argument 'test.txt' DAMIEN SOLODOW Systems Engineer 317.447.6033 (office) 317.447.6014 (fax) HARRISON COLLEGE From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Michael B. Smith Sent: Thursday, October 9, 2014 11:24 AM To: powershell@lists.myitforum.com Subject: [powershell] RE: Better way to accomplish this? There is already a built-in $args variable that accomplishes the same thing. To use the same function, formatted the way I prefer is below. But the question really is (since formatting is a religious argument, not a capability argument) - what problems/concerns do you have with the script/link you posted? What challenge do you need to overcome? Function Start-Elevated { [CmdletBinding()] Param( [parameter(Mandatory = $true,ValueFromPipeline=$true,Position=0)][String]$Executable ) If( !$args -or $args.Count -eq 0 ) { Start-Process -Verb RunAs -FilePath $Executable } Else { Start-Process -Verb RunAs -FilePath $Executable -ArgumentList $args } } From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Damien Solodow Sent: Thursday, October 9, 2014 11:00 AM To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: [powershell] Better way to accomplish this? I'm creating a function to invoke a specified executable in an elevated session. The main obstacle right now is around passing parameters (arguments) to the process I'm launching. I have a way that works, but I'm wondering if there is a better way to accomplish it: https://gist.github.com/dsolodow/6dfcfb3e413ae2fec5a2#file-sudo-function DAMIEN SOLODOW Systems Engineer 317.447.6033 (office) 317.447.6014 (fax) HARRISON COLLEGE 500 North Meridian St Suite 500 Indianapolis, IN 46204-1213 www.harrison.edu<http://www.harrison.edu/> ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1