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

74 views      
 

Messages in this Thread

 
94,580 Postings in 11,930 Threads, 348 registered users, 13 users online (0 registered, 13 guests)
Index | Admin contact |   Forum Time: Nov 17, 2019 - 5:33 am EST  |  Hits:29,145,875  (5,836 Today )
RSS Feed