ZTree.com  | ZEN  | About...  

 Index   Back

[Help!] Running elevated Powershell from F9 ?   [Help!]

By: Laurent Duchastel     Montréal, Québec  
Date: Oct 14,2019 at 18:18
In Response to: [Help!] Running elevated Powershell from F9 ? (Ben Kent)

> > This leads to a question : what would be the best way to run with F9
> a
> > PS script that span many lines ?
>
> 1. separate your powershell commands with ; and put them in one line.
> Difficult to read and it can be hard to get some commands to work that
> way.
>
> 2. Call an powershell script from the F9 entry
> i.e. Create the .ps1 script before, and call it from the F9 menu item.
> It will work, but not what you asked for.
>
> 3. Generate a temporary PS1 script, but need to watch out for
> characters that need escaping.
>
> echo Get-AppxPackage *officehub* ^| Remove-AppxPackage
> >%#ZTTemp%\~Temp.ps1
> echo Write-Output "Done." >>%#ZTTemp%\~Temp.ps1
> "%#ZTTOOLS%\elevate\elevate64" -c -w powershell -file
> %#ZTTemp%\~Temp.ps1
>
> You could use this syntax, with that you have to escape brackets, as
> shon
> (
> echo line^(1^)
> echo line^(2^)
> )>%#ZTTemp%\~Temp.ps1
>
>
> 4. Hybrid script
> Taking inspiration from
> https://stackoverflow.com/questions/1947...ch-file-one-command-in-multiple-lines
> powershell block comments can be used to create a hybrid CMD PS1 script
>
>
> ----------------
> @echo off
> REM The Powershell section needs two trailing empty lines
> "%#ZTTOOLS%\elevate\elevate64" -c -w powershell -command - < %0
> exit /b
> ----- Begin PS1 script -- #>
> Get-AppxPackage *officehub* | Remove-AppxPackage
>
>
> ----------------


Thank you very much for this exhaustive response.
Worth keeping around.


Laurent Duchastel

181 views      
 

Messages in this Thread

 
94,802 Postings in 11,953 Threads, 348 registered users, 5 users online (0 registered, 5 guests)
Index | Admin contact |   Forum Time: Apr 5, 2020 - 7:21 pm EDT  |  Hits:30,542,548  (4,329 Today )
RSS Feed