mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-23 14:31:30 -06:00
355 lines
90 KiB
HTML
355 lines
90 KiB
HTML
|
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=../../../../assets/favicon.png><meta name=generator content="mkdocs-1.6.0, mkdocs-material-9.5.31"><title>Change Windows Terminal default: PowerShell 5 -> PowerShell 7 - WinUtil Documentation</title><link rel=stylesheet href=../../../../assets/stylesheets/main.3cba04c6.min.css><link rel=stylesheet href=../../../../assets/stylesheets/palette.06af60db.min.css><link rel=preconnect href=https://fonts.gstatic.com crossorigin><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"><style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style><script>__md_scope=new URL("../../../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script></head> <body dir=ltr data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#change-windows-terminal-default-powershell-5-powershell-7 class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header__inner md-grid" aria-label=Header> <a href=../../../.. title="WinUtil Documentation" class="md-header__button md-logo" aria-label="WinUtil Documentation" data-md-component=logo> <img src=../../../../assets/favicon.png alt=logo> </a> <label class="md-header__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg> </label> <div class=md-header__title data-md-component=header-title> <div class=md-header__ellipsis> <div class=md-header__topic> <span class=md-ellipsis> WinUtil Documentation </span> </div> <div class=md-header__topic data-md-component=header-topic> <span class=md-ellipsis> Change Windows Terminal default: PowerShell 5 -> PowerShell 7 </span> </div> </div> </div> <form class=md-header__option data-md-component=palette> <input class=md-option data-md-color-media=(prefers-color-scheme) data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=indigo aria-label="Switch to light mode" type=radio name=__palette id=__palette_0> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_1 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="m14.3 16-.7-2h-3.2l-.7 2H7.8L11 7h2l3.2 9h-1.9M20 8.69V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69m-9.15 3.96h2.3L12 9l-1.15 3.65Z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme=default data-md-color-primary=indigo data-md-color-accent=blue aria-label="Switch to dark mode" type=radio name=__palette id=__palette_1> <label class="md-header__button md-icon" title="Switch to dark mode" for=__palette_2 hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg> </label> <input class=md-option data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme=slate data-md-color-primary=black data-md-color-accent=blue aria-label="Switch to light mode" type=radio name=__palette id=__palette_2> <label class="md-header__button md-icon" title="Switch to light mode" for=__palette_0 hidden> <svg xmlns
|
||
|
</span><span id=__span-0-2><a id=__codelineno-0-2 name=__codelineno-0-2 href=#__codelineno-0-2></a><span class=w> </span><span class=nt>"Content"</span><span class=p>:</span><span class=w> </span><span class=s2>"Change Windows Terminal default: PowerShell 5 -> PowerShell 7"</span><span class=p>,</span>
|
||
|
</span><span id=__span-0-3><a id=__codelineno-0-3 name=__codelineno-0-3 href=#__codelineno-0-3></a><span class=w> </span><span class=nt>"Description"</span><span class=p>:</span><span class=w> </span><span class=s2>"This will edit the config file of the Windows Terminal replacing PowerShell 5 with PowerShell 7 and installing PS7 if necessary"</span><span class=p>,</span>
|
||
|
</span><span id=__span-0-4><a id=__codelineno-0-4 name=__codelineno-0-4 href=#__codelineno-0-4></a><span class=w> </span><span class=nt>"category"</span><span class=p>:</span><span class=w> </span><span class=s2>"Essential Tweaks"</span><span class=p>,</span>
|
||
|
</span><span id=__span-0-5><a id=__codelineno-0-5 name=__codelineno-0-5 href=#__codelineno-0-5></a><span class=w> </span><span class=nt>"panel"</span><span class=p>:</span><span class=w> </span><span class=s2>"1"</span><span class=p>,</span>
|
||
|
</span><span id=__span-0-6><a id=__codelineno-0-6 name=__codelineno-0-6 href=#__codelineno-0-6></a><span class=w> </span><span class=nt>"Order"</span><span class=p>:</span><span class=w> </span><span class=s2>"a009_"</span><span class=p>,</span>
|
||
|
</span><span id=__span-0-7><a id=__codelineno-0-7 name=__codelineno-0-7 href=#__codelineno-0-7></a><span class=w> </span><span class=nt>"InvokeScript"</span><span class=p>:</span><span class=w> </span><span class=p>[</span>
|
||
|
</span><span id=__span-0-8><a id=__codelineno-0-8 name=__codelineno-0-8 href=#__codelineno-0-8></a><span class=w> </span><span class=s2>"Invoke-WPFTweakPS7 -action \"PS7\""</span>
|
||
|
</span><span id=__span-0-9><a id=__codelineno-0-9 name=__codelineno-0-9 href=#__codelineno-0-9></a><span class=w> </span><span class=p>],</span>
|
||
|
</span><span id=__span-0-10><a id=__codelineno-0-10 name=__codelineno-0-10 href=#__codelineno-0-10></a><span class=w> </span><span class=nt>"UndoScript"</span><span class=p>:</span><span class=w> </span><span class=p>[</span>
|
||
|
</span><span id=__span-0-11><a id=__codelineno-0-11 name=__codelineno-0-11 href=#__codelineno-0-11></a><span class=w> </span><span class=s2>"Invoke-WPFTweakPS7 -action \"PS5\""</span>
|
||
|
</span><span id=__span-0-12><a id=__codelineno-0-12 name=__codelineno-0-12 href=#__codelineno-0-12></a><span class=w> </span><span class=p>],</span>
|
||
|
</span><span id=__span-0-13><a id=__codelineno-0-13 name=__codelineno-0-13 href=#__codelineno-0-13></a><span class=w> </span><span class=nt>"link"</span><span class=p>:</span><span class=w> </span><span class=s2>"https://christitustech.github.io/winutil/dev/tweaks/Essential-Tweaks/Powershell7"</span>
|
||
|
</span><span id=__span-0-14><a id=__codelineno-0-14 name=__codelineno-0-14 href=#__codelineno-0-14></a><span class=p>}</span>
|
||
|
</span></code></pre></div> </details> <h2 id=invoke-script>Invoke Script<a class=headerlink href=#invoke-script title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-1-1><a id=__codelineno-1-1 name=__codelineno-1-1 href=#__codelineno-1-1></a><span class=nb>Invoke-WPFTweakPS7</span> <span class=n>-action</span> <span class=s2>"PS7"</span>
|
||
|
</span></code></pre></div> <h2 id=undo-script>Undo Script<a class=headerlink href=#undo-script title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-2-1><a id=__codelineno-2-1 name=__codelineno-2-1 href=#__codelineno-2-1></a><span class=nb>Invoke-WPFTweakPS7</span> <span class=n>-action</span> <span class=s2>"PS5"</span>
|
||
|
</span></code></pre></div> <h2 id=function-invoke-wpftweakps7>Function: Invoke-WPFTweakPS7<a class=headerlink href=#function-invoke-wpftweakps7 title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-3-1><a id=__codelineno-3-1 name=__codelineno-3-1 href=#__codelineno-3-1></a><span class=k>function</span> <span class=nb>Invoke-WPFTweakPS7</span><span class=p>{</span>
|
||
|
</span><span id=__span-3-2><a id=__codelineno-3-2 name=__codelineno-3-2 href=#__codelineno-3-2></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-3-3><a id=__codelineno-3-3 name=__codelineno-3-3 href=#__codelineno-3-3></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-3-4><a id=__codelineno-3-4 name=__codelineno-3-4 href=#__codelineno-3-4></a><span class=cm> This will edit the config file of the Windows Terminal Replacing the Powershell 5 to Powershell 7 and install Powershell 7 if necessary</span>
|
||
|
</span><span id=__span-3-5><a id=__codelineno-3-5 name=__codelineno-3-5 href=#__codelineno-3-5></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> action</span>
|
||
|
</span><span id=__span-3-6><a id=__codelineno-3-6 name=__codelineno-3-6 href=#__codelineno-3-6></a><span class=cm> PS7: Configures Powershell 7 to be the default Terminal</span>
|
||
|
</span><span id=__span-3-7><a id=__codelineno-3-7 name=__codelineno-3-7 href=#__codelineno-3-7></a><span class=cm> PS5: Configures Powershell 5 to be the default Terminal</span>
|
||
|
</span><span id=__span-3-8><a id=__codelineno-3-8 name=__codelineno-3-8 href=#__codelineno-3-8></a><span class=cm> #></span>
|
||
|
</span><span id=__span-3-9><a id=__codelineno-3-9 name=__codelineno-3-9 href=#__codelineno-3-9></a> <span class=k>param</span> <span class=p>(</span>
|
||
|
</span><span id=__span-3-10><a id=__codelineno-3-10 name=__codelineno-3-10 href=#__codelineno-3-10></a> <span class=p>[</span><span class=k>ValidateSet</span><span class=p>(</span><span class=s2>"PS7"</span><span class=p>,</span> <span class=s2>"PS5"</span><span class=p>)]</span>
|
||
|
</span><span id=__span-3-11><a id=__codelineno-3-11 name=__codelineno-3-11 href=#__codelineno-3-11></a> <span class=no>[string]</span><span class=nv>$action</span>
|
||
|
</span><span id=__span-3-12><a id=__codelineno-3-12 name=__codelineno-3-12 href=#__codelineno-3-12></a> <span class=p>)</span>
|
||
|
</span><span id=__span-3-13><a id=__codelineno-3-13 name=__codelineno-3-13 href=#__codelineno-3-13></a>
|
||
|
</span><span id=__span-3-14><a id=__codelineno-3-14 name=__codelineno-3-14 href=#__codelineno-3-14></a> <span class=k>switch</span> <span class=p>(</span><span class=nv>$action</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-15><a id=__codelineno-3-15 name=__codelineno-3-15 href=#__codelineno-3-15></a> <span class=s2>"PS7"</span><span class=p>{</span>
|
||
|
</span><span id=__span-3-16><a id=__codelineno-3-16 name=__codelineno-3-16 href=#__codelineno-3-16></a> <span class=k>if</span> <span class=p>(</span><span class=nb>Test-Path</span> <span class=n>-Path</span> <span class=s2>"$env:ProgramFiles\PowerShell\7"</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-17><a id=__codelineno-3-17 name=__codelineno-3-17 href=#__codelineno-3-17></a> <span class=nb>Write-Host</span> <span class=s2>"Powershell 7 is already installed."</span>
|
||
|
</span><span id=__span-3-18><a id=__codelineno-3-18 name=__codelineno-3-18 href=#__codelineno-3-18></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-19><a id=__codelineno-3-19 name=__codelineno-3-19 href=#__codelineno-3-19></a> <span class=nb>Write-Host</span> <span class=s2>"Installing Powershell 7..."</span>
|
||
|
</span><span id=__span-3-20><a id=__codelineno-3-20 name=__codelineno-3-20 href=#__codelineno-3-20></a> <span class=nb>Invoke-WinUtilWingetProgram</span> <span class=n>-Action</span> <span class=n>Install</span> <span class=n>-Programs</span> <span class=p>@(</span><span class=s2>"Microsoft.PowerShell"</span><span class=p>)</span>
|
||
|
</span><span id=__span-3-21><a id=__codelineno-3-21 name=__codelineno-3-21 href=#__codelineno-3-21></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-22><a id=__codelineno-3-22 name=__codelineno-3-22 href=#__codelineno-3-22></a> <span class=nv>$targetTerminalName</span> <span class=p>=</span> <span class=s2>"PowerShell"</span>
|
||
|
</span><span id=__span-3-23><a id=__codelineno-3-23 name=__codelineno-3-23 href=#__codelineno-3-23></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-24><a id=__codelineno-3-24 name=__codelineno-3-24 href=#__codelineno-3-24></a> <span class=s2>"PS5"</span><span class=p>{</span>
|
||
|
</span><span id=__span-3-25><a id=__codelineno-3-25 name=__codelineno-3-25 href=#__codelineno-3-25></a> <span class=nv>$targetTerminalName</span> <span class=p>=</span> <span class=s2>"Windows PowerShell"</span>
|
||
|
</span><span id=__span-3-26><a id=__codelineno-3-26 name=__codelineno-3-26 href=#__codelineno-3-26></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-27><a id=__codelineno-3-27 name=__codelineno-3-27 href=#__codelineno-3-27></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-28><a id=__codelineno-3-28 name=__codelineno-3-28 href=#__codelineno-3-28></a> <span class=c># Check if the Windows Terminal is installed and return if not (Prerequisite for the following code)</span>
|
||
|
</span><span id=__span-3-29><a id=__codelineno-3-29 name=__codelineno-3-29 href=#__codelineno-3-29></a> <span class=k>if</span> <span class=p>(</span><span class=o>-not</span> <span class=p>(</span><span class=nb>Get-Command</span> <span class=s2>"wt"</span> <span class=n>-ErrorAction</span> <span class=n>SilentlyContinue</span><span class=p>))</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-30><a id=__codelineno-3-30 name=__codelineno-3-30 href=#__codelineno-3-30></a> <span class=nb>Write-Host</span> <span class=s2>"Windows Terminal not installed. Skipping Terminal preference"</span>
|
||
|
</span><span id=__span-3-31><a id=__codelineno-3-31 name=__codelineno-3-31 href=#__codelineno-3-31></a> <span class=k>return</span>
|
||
|
</span><span id=__span-3-32><a id=__codelineno-3-32 name=__codelineno-3-32 href=#__codelineno-3-32></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-33><a id=__codelineno-3-33 name=__codelineno-3-33 href=#__codelineno-3-33></a> <span class=c># Check if the Windows Terminal settings.json file exists and return if not (Prereqisite for the following code)</span>
|
||
|
</span><span id=__span-3-34><a id=__codelineno-3-34 name=__codelineno-3-34 href=#__codelineno-3-34></a> <span class=nv>$settingsPath</span> <span class=p>=</span> <span class=s2>"$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"</span>
|
||
|
</span><span id=__span-3-35><a id=__codelineno-3-35 name=__codelineno-3-35 href=#__codelineno-3-35></a> <span class=k>if</span> <span class=p>(</span><span class=o>-not</span> <span class=p>(</span><span class=nb>Test-Path</span> <span class=n>-Path</span> <span class=nv>$settingsPath</span><span class=p>))</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-36><a id=__codelineno-3-36 name=__codelineno-3-36 href=#__codelineno-3-36></a> <span class=nb>Write-Host</span> <span class=s2>"Windows Terminal Settings file not found at $settingsPath"</span>
|
||
|
</span><span id=__span-3-37><a id=__codelineno-3-37 name=__codelineno-3-37 href=#__codelineno-3-37></a> <span class=k>return</span>
|
||
|
</span><span id=__span-3-38><a id=__codelineno-3-38 name=__codelineno-3-38 href=#__codelineno-3-38></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-39><a id=__codelineno-3-39 name=__codelineno-3-39 href=#__codelineno-3-39></a>
|
||
|
</span><span id=__span-3-40><a id=__codelineno-3-40 name=__codelineno-3-40 href=#__codelineno-3-40></a> <span class=nb>Write-Host</span> <span class=s2>"Settings file found."</span>
|
||
|
</span><span id=__span-3-41><a id=__codelineno-3-41 name=__codelineno-3-41 href=#__codelineno-3-41></a> <span class=nv>$settingsContent</span> <span class=p>=</span> <span class=nb>Get-Content</span> <span class=n>-Path</span> <span class=nv>$settingsPath</span> <span class=p>|</span> <span class=nb>ConvertFrom-Json</span>
|
||
|
</span><span id=__span-3-42><a id=__codelineno-3-42 name=__codelineno-3-42 href=#__codelineno-3-42></a> <span class=nv>$ps7Profile</span> <span class=p>=</span> <span class=nv>$settingsContent</span><span class=p>.</span><span class=n>profiles</span><span class=p>.</span><span class=n>list</span> <span class=p>|</span> <span class=nb>Where-Object</span> <span class=p>{</span> <span class=nv>$_</span><span class=p>.</span><span class=n>name</span> <span class=o>-eq</span> <span class=nv>$targetTerminalName</span> <span class=p>}</span>
|
||
|
</span><span id=__span-3-43><a id=__codelineno-3-43 name=__codelineno-3-43 href=#__codelineno-3-43></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$ps7Profile</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-44><a id=__codelineno-3-44 name=__codelineno-3-44 href=#__codelineno-3-44></a> <span class=nv>$settingsContent</span><span class=p>.</span><span class=n>defaultProfile</span> <span class=p>=</span> <span class=nv>$ps7Profile</span><span class=p>.</span><span class=n>guid</span>
|
||
|
</span><span id=__span-3-45><a id=__codelineno-3-45 name=__codelineno-3-45 href=#__codelineno-3-45></a> <span class=nv>$updatedSettings</span> <span class=p>=</span> <span class=nv>$settingsContent</span> <span class=p>|</span> <span class=nb>ConvertTo-Json</span> <span class=n>-Depth</span> <span class=n>100</span>
|
||
|
</span><span id=__span-3-46><a id=__codelineno-3-46 name=__codelineno-3-46 href=#__codelineno-3-46></a> <span class=nb>Set-Content</span> <span class=n>-Path</span> <span class=nv>$settingsPath</span> <span class=n>-Value</span> <span class=nv>$updatedSettings</span>
|
||
|
</span><span id=__span-3-47><a id=__codelineno-3-47 name=__codelineno-3-47 href=#__codelineno-3-47></a> <span class=nb>Write-Host</span> <span class=s2>"Default profile updated to "</span> <span class=n>-NoNewline</span>
|
||
|
</span><span id=__span-3-48><a id=__codelineno-3-48 name=__codelineno-3-48 href=#__codelineno-3-48></a> <span class=nb>Write-Host</span> <span class=s2>"$targetTerminalName "</span> <span class=n>-ForegroundColor</span> <span class=n>White</span> <span class=n>-NoNewline</span>
|
||
|
</span><span id=__span-3-49><a id=__codelineno-3-49 name=__codelineno-3-49 href=#__codelineno-3-49></a> <span class=nb>Write-Host</span> <span class=s2>"using the name attribute."</span>
|
||
|
</span><span id=__span-3-50><a id=__codelineno-3-50 name=__codelineno-3-50 href=#__codelineno-3-50></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-3-51><a id=__codelineno-3-51 name=__codelineno-3-51 href=#__codelineno-3-51></a> <span class=nb>Write-Host</span> <span class=s2>"No PowerShell 7 profile found in Windows Terminal settings using the name attribute."</span>
|
||
|
</span><span id=__span-3-52><a id=__codelineno-3-52 name=__codelineno-3-52 href=#__codelineno-3-52></a> <span class=p>}</span>
|
||
|
</span><span id=__span-3-53><a id=__codelineno-3-53 name=__codelineno-3-53 href=#__codelineno-3-53></a><span class=p>}</span>
|
||
|
</span></code></pre></div> <h2 id=function-invoke-winutilwingetprogram>Function: Invoke-WinUtilWingetProgram<a class=headerlink href=#function-invoke-winutilwingetprogram title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-4-1><a id=__codelineno-4-1 name=__codelineno-4-1 href=#__codelineno-4-1></a><span class=k>Function</span> <span class=nb>Invoke-WinUtilWingetProgram</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-2><a id=__codelineno-4-2 name=__codelineno-4-2 href=#__codelineno-4-2></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-4-3><a id=__codelineno-4-3 name=__codelineno-4-3 href=#__codelineno-4-3></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-4-4><a id=__codelineno-4-4 name=__codelineno-4-4 href=#__codelineno-4-4></a><span class=cm> Runs the designated action on the provided programs using Winget</span>
|
||
|
</span><span id=__span-4-5><a id=__codelineno-4-5 name=__codelineno-4-5 href=#__codelineno-4-5></a>
|
||
|
</span><span id=__span-4-6><a id=__codelineno-4-6 name=__codelineno-4-6 href=#__codelineno-4-6></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> Programs</span>
|
||
|
</span><span id=__span-4-7><a id=__codelineno-4-7 name=__codelineno-4-7 href=#__codelineno-4-7></a><span class=cm> A list of programs to process</span>
|
||
|
</span><span id=__span-4-8><a id=__codelineno-4-8 name=__codelineno-4-8 href=#__codelineno-4-8></a>
|
||
|
</span><span id=__span-4-9><a id=__codelineno-4-9 name=__codelineno-4-9 href=#__codelineno-4-9></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> action</span>
|
||
|
</span><span id=__span-4-10><a id=__codelineno-4-10 name=__codelineno-4-10 href=#__codelineno-4-10></a><span class=cm> The action to perform on the programs, can be either 'Install' or 'Uninstall'</span>
|
||
|
</span><span id=__span-4-11><a id=__codelineno-4-11 name=__codelineno-4-11 href=#__codelineno-4-11></a>
|
||
|
</span><span id=__span-4-12><a id=__codelineno-4-12 name=__codelineno-4-12 href=#__codelineno-4-12></a><span class=cm> </span><span class=sd>.NOTES</span>
|
||
|
</span><span id=__span-4-13><a id=__codelineno-4-13 name=__codelineno-4-13 href=#__codelineno-4-13></a><span class=cm> The triple quotes are required any time you need a " in a normal script block.</span>
|
||
|
</span><span id=__span-4-14><a id=__codelineno-4-14 name=__codelineno-4-14 href=#__codelineno-4-14></a><span class=cm> The winget Return codes are documented here: https://github.com/microsoft/winget-cli/blob/master/doc/windows/package-actionr/winget/returnCodes.md</span>
|
||
|
</span><span id=__span-4-15><a id=__codelineno-4-15 name=__codelineno-4-15 href=#__codelineno-4-15></a><span class=cm> #></span>
|
||
|
</span><span id=__span-4-16><a id=__codelineno-4-16 name=__codelineno-4-16 href=#__codelineno-4-16></a>
|
||
|
</span><span id=__span-4-17><a id=__codelineno-4-17 name=__codelineno-4-17 href=#__codelineno-4-17></a> <span class=k>param</span><span class=p>(</span>
|
||
|
</span><span id=__span-4-18><a id=__codelineno-4-18 name=__codelineno-4-18 href=#__codelineno-4-18></a> <span class=p>[</span><span class=k>Parameter</span><span class=p>(</span><span class=k>Mandatory</span><span class=p>,</span> <span class=k>Position</span><span class=p>=</span><span class=n>0</span><span class=p>)]</span><span class=nv>$Programs</span><span class=p>,</span>
|
||
|
</span><span id=__span-4-19><a id=__codelineno-4-19 name=__codelineno-4-19 href=#__codelineno-4-19></a>
|
||
|
</span><span id=__span-4-20><a id=__codelineno-4-20 name=__codelineno-4-20 href=#__codelineno-4-20></a> <span class=p>[</span><span class=k>Parameter</span><span class=p>(</span><span class=k>Mandatory</span><span class=p>,</span> <span class=k>Position</span><span class=p>=</span><span class=n>1</span><span class=p>)]</span>
|
||
|
</span><span id=__span-4-21><a id=__codelineno-4-21 name=__codelineno-4-21 href=#__codelineno-4-21></a> <span class=p>[</span><span class=k>ValidateSet</span><span class=p>(</span><span class=s2>"Install"</span><span class=p>,</span> <span class=s2>"Uninstall"</span><span class=p>)]</span>
|
||
|
</span><span id=__span-4-22><a id=__codelineno-4-22 name=__codelineno-4-22 href=#__codelineno-4-22></a> <span class=no>[String]</span><span class=nv>$Action</span>
|
||
|
</span><span id=__span-4-23><a id=__codelineno-4-23 name=__codelineno-4-23 href=#__codelineno-4-23></a> <span class=p>)</span>
|
||
|
</span><span id=__span-4-24><a id=__codelineno-4-24 name=__codelineno-4-24 href=#__codelineno-4-24></a>
|
||
|
</span><span id=__span-4-25><a id=__codelineno-4-25 name=__codelineno-4-25 href=#__codelineno-4-25></a> <span class=k>Function</span> <span class=nb>Invoke-Winget</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-26><a id=__codelineno-4-26 name=__codelineno-4-26 href=#__codelineno-4-26></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-4-27><a id=__codelineno-4-27 name=__codelineno-4-27 href=#__codelineno-4-27></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-4-28><a id=__codelineno-4-28 name=__codelineno-4-28 href=#__codelineno-4-28></a><span class=cm> Invokes the winget.exe with the provided arguments and return the exit code</span>
|
||
|
</span><span id=__span-4-29><a id=__codelineno-4-29 name=__codelineno-4-29 href=#__codelineno-4-29></a>
|
||
|
</span><span id=__span-4-30><a id=__codelineno-4-30 name=__codelineno-4-30 href=#__codelineno-4-30></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> wingetId</span>
|
||
|
</span><span id=__span-4-31><a id=__codelineno-4-31 name=__codelineno-4-31 href=#__codelineno-4-31></a><span class=cm> The Id of the Program that Winget should Install/Uninstall</span>
|
||
|
</span><span id=__span-4-32><a id=__codelineno-4-32 name=__codelineno-4-32 href=#__codelineno-4-32></a>
|
||
|
</span><span id=__span-4-33><a id=__codelineno-4-33 name=__codelineno-4-33 href=#__codelineno-4-33></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> scope</span>
|
||
|
</span><span id=__span-4-34><a id=__codelineno-4-34 name=__codelineno-4-34 href=#__codelineno-4-34></a><span class=cm> Determines the installation mode. Can be "user" or "machine" (For more info look at the winget documentation)</span>
|
||
|
</span><span id=__span-4-35><a id=__codelineno-4-35 name=__codelineno-4-35 href=#__codelineno-4-35></a>
|
||
|
</span><span id=__span-4-36><a id=__codelineno-4-36 name=__codelineno-4-36 href=#__codelineno-4-36></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> credential</span>
|
||
|
</span><span id=__span-4-37><a id=__codelineno-4-37 name=__codelineno-4-37 href=#__codelineno-4-37></a><span class=cm> The PSCredential Object of the user that should be used to run winget</span>
|
||
|
</span><span id=__span-4-38><a id=__codelineno-4-38 name=__codelineno-4-38 href=#__codelineno-4-38></a>
|
||
|
</span><span id=__span-4-39><a id=__codelineno-4-39 name=__codelineno-4-39 href=#__codelineno-4-39></a><span class=cm> </span><span class=sd>.NOTES</span>
|
||
|
</span><span id=__span-4-40><a id=__codelineno-4-40 name=__codelineno-4-40 href=#__codelineno-4-40></a><span class=cm> Invoke Winget uses the public variable $Action defined outside the function to determine if a Program should be installed or removed</span>
|
||
|
</span><span id=__span-4-41><a id=__codelineno-4-41 name=__codelineno-4-41 href=#__codelineno-4-41></a><span class=cm> #></span>
|
||
|
</span><span id=__span-4-42><a id=__codelineno-4-42 name=__codelineno-4-42 href=#__codelineno-4-42></a> <span class=k>param</span> <span class=p>(</span>
|
||
|
</span><span id=__span-4-43><a id=__codelineno-4-43 name=__codelineno-4-43 href=#__codelineno-4-43></a> <span class=no>[string]</span><span class=nv>$wingetId</span><span class=p>,</span>
|
||
|
</span><span id=__span-4-44><a id=__codelineno-4-44 name=__codelineno-4-44 href=#__codelineno-4-44></a> <span class=no>[string]</span><span class=nv>$scope</span> <span class=p>=</span> <span class=s2>""</span><span class=p>,</span>
|
||
|
</span><span id=__span-4-45><a id=__codelineno-4-45 name=__codelineno-4-45 href=#__codelineno-4-45></a> <span class=no>[PScredential]</span><span class=nv>$credential</span> <span class=p>=</span> <span class=nv>$null</span>
|
||
|
</span><span id=__span-4-46><a id=__codelineno-4-46 name=__codelineno-4-46 href=#__codelineno-4-46></a> <span class=p>)</span>
|
||
|
</span><span id=__span-4-47><a id=__codelineno-4-47 name=__codelineno-4-47 href=#__codelineno-4-47></a>
|
||
|
</span><span id=__span-4-48><a id=__codelineno-4-48 name=__codelineno-4-48 href=#__codelineno-4-48></a> <span class=nv>$commonArguments</span> <span class=p>=</span> <span class=s2>"--id $wingetId --silent"</span>
|
||
|
</span><span id=__span-4-49><a id=__codelineno-4-49 name=__codelineno-4-49 href=#__codelineno-4-49></a> <span class=nv>$arguments</span> <span class=p>=</span> <span class=k>if</span> <span class=p>(</span><span class=nv>$Action</span> <span class=o>-eq</span> <span class=s2>"Install"</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-50><a id=__codelineno-4-50 name=__codelineno-4-50 href=#__codelineno-4-50></a> <span class=s2>"install $commonArguments --accept-source-agreements --accept-package-agreements </span><span class=p>$(</span><span class=k>if</span> <span class=p>(</span><span class=nv>$scope</span><span class=p>)</span> <span class=p>{</span><span class=s2>" --scope $scope"</span><span class=p>})</span><span class=s2>"</span>
|
||
|
</span><span id=__span-4-51><a id=__codelineno-4-51 name=__codelineno-4-51 href=#__codelineno-4-51></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-52><a id=__codelineno-4-52 name=__codelineno-4-52 href=#__codelineno-4-52></a> <span class=s2>"uninstall $commonArguments"</span>
|
||
|
</span><span id=__span-4-53><a id=__codelineno-4-53 name=__codelineno-4-53 href=#__codelineno-4-53></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-54><a id=__codelineno-4-54 name=__codelineno-4-54 href=#__codelineno-4-54></a>
|
||
|
</span><span id=__span-4-55><a id=__codelineno-4-55 name=__codelineno-4-55 href=#__codelineno-4-55></a> <span class=nv>$processParams</span> <span class=p>=</span> <span class=p>@{</span>
|
||
|
</span><span id=__span-4-56><a id=__codelineno-4-56 name=__codelineno-4-56 href=#__codelineno-4-56></a> <span class=n>FilePath</span> <span class=p>=</span> <span class=s2>"winget"</span>
|
||
|
</span><span id=__span-4-57><a id=__codelineno-4-57 name=__codelineno-4-57 href=#__codelineno-4-57></a> <span class=n>ArgumentList</span> <span class=p>=</span> <span class=nv>$arguments</span>
|
||
|
</span><span id=__span-4-58><a id=__codelineno-4-58 name=__codelineno-4-58 href=#__codelineno-4-58></a> <span class=n>Wait</span> <span class=p>=</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-59><a id=__codelineno-4-59 name=__codelineno-4-59 href=#__codelineno-4-59></a> <span class=n>PassThru</span> <span class=p>=</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-60><a id=__codelineno-4-60 name=__codelineno-4-60 href=#__codelineno-4-60></a> <span class=n>NoNewWindow</span> <span class=p>=</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-61><a id=__codelineno-4-61 name=__codelineno-4-61 href=#__codelineno-4-61></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-62><a id=__codelineno-4-62 name=__codelineno-4-62 href=#__codelineno-4-62></a>
|
||
|
</span><span id=__span-4-63><a id=__codelineno-4-63 name=__codelineno-4-63 href=#__codelineno-4-63></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$credential</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-64><a id=__codelineno-4-64 name=__codelineno-4-64 href=#__codelineno-4-64></a> <span class=nv>$processParams</span><span class=p>.</span><span class=n>credential</span> <span class=p>=</span> <span class=nv>$credential</span>
|
||
|
</span><span id=__span-4-65><a id=__codelineno-4-65 name=__codelineno-4-65 href=#__codelineno-4-65></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-66><a id=__codelineno-4-66 name=__codelineno-4-66 href=#__codelineno-4-66></a>
|
||
|
</span><span id=__span-4-67><a id=__codelineno-4-67 name=__codelineno-4-67 href=#__codelineno-4-67></a> <span class=k>return</span> <span class=p>(</span><span class=nb>Start-Process</span> <span class=nv>@processParams</span><span class=p>).</span><span class=n>ExitCode</span>
|
||
|
</span><span id=__span-4-68><a id=__codelineno-4-68 name=__codelineno-4-68 href=#__codelineno-4-68></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-69><a id=__codelineno-4-69 name=__codelineno-4-69 href=#__codelineno-4-69></a>
|
||
|
</span><span id=__span-4-70><a id=__codelineno-4-70 name=__codelineno-4-70 href=#__codelineno-4-70></a> <span class=k>Function</span> <span class=nb>Invoke-Install</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-71><a id=__codelineno-4-71 name=__codelineno-4-71 href=#__codelineno-4-71></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-4-72><a id=__codelineno-4-72 name=__codelineno-4-72 href=#__codelineno-4-72></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-4-73><a id=__codelineno-4-73 name=__codelineno-4-73 href=#__codelineno-4-73></a><span class=cm> Contains the Install Logic and return code handling from winget</span>
|
||
|
</span><span id=__span-4-74><a id=__codelineno-4-74 name=__codelineno-4-74 href=#__codelineno-4-74></a>
|
||
|
</span><span id=__span-4-75><a id=__codelineno-4-75 name=__codelineno-4-75 href=#__codelineno-4-75></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> Program</span>
|
||
|
</span><span id=__span-4-76><a id=__codelineno-4-76 name=__codelineno-4-76 href=#__codelineno-4-76></a><span class=cm> The Winget ID of the Program that should be installed</span>
|
||
|
</span><span id=__span-4-77><a id=__codelineno-4-77 name=__codelineno-4-77 href=#__codelineno-4-77></a><span class=cm> #></span>
|
||
|
</span><span id=__span-4-78><a id=__codelineno-4-78 name=__codelineno-4-78 href=#__codelineno-4-78></a> <span class=k>param</span> <span class=p>(</span>
|
||
|
</span><span id=__span-4-79><a id=__codelineno-4-79 name=__codelineno-4-79 href=#__codelineno-4-79></a> <span class=no>[string]</span><span class=nv>$Program</span>
|
||
|
</span><span id=__span-4-80><a id=__codelineno-4-80 name=__codelineno-4-80 href=#__codelineno-4-80></a> <span class=p>)</span>
|
||
|
</span><span id=__span-4-81><a id=__codelineno-4-81 name=__codelineno-4-81 href=#__codelineno-4-81></a> <span class=nv>$status</span> <span class=p>=</span> <span class=nb>Invoke-Winget</span> <span class=n>-wingetId</span> <span class=nv>$Program</span>
|
||
|
</span><span id=__span-4-82><a id=__codelineno-4-82 name=__codelineno-4-82 href=#__codelineno-4-82></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=n>0</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-83><a id=__codelineno-4-83 name=__codelineno-4-83 href=#__codelineno-4-83></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> installed successfully."</span>
|
||
|
</span><span id=__span-4-84><a id=__codelineno-4-84 name=__codelineno-4-84 href=#__codelineno-4-84></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-85><a id=__codelineno-4-85 name=__codelineno-4-85 href=#__codelineno-4-85></a> <span class=p>}</span> <span class=k>elseif</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=p>-</span><span class=n>1978335189</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-86><a id=__codelineno-4-86 name=__codelineno-4-86 href=#__codelineno-4-86></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> No applicable update found"</span>
|
||
|
</span><span id=__span-4-87><a id=__codelineno-4-87 name=__codelineno-4-87 href=#__codelineno-4-87></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-88><a id=__codelineno-4-88 name=__codelineno-4-88 href=#__codelineno-4-88></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-89><a id=__codelineno-4-89 name=__codelineno-4-89 href=#__codelineno-4-89></a>
|
||
|
</span><span id=__span-4-90><a id=__codelineno-4-90 name=__codelineno-4-90 href=#__codelineno-4-90></a> <span class=nb>Write-Host</span> <span class=s2>"Attempt installation of </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> with User scope"</span>
|
||
|
</span><span id=__span-4-91><a id=__codelineno-4-91 name=__codelineno-4-91 href=#__codelineno-4-91></a> <span class=nv>$status</span> <span class=p>=</span> <span class=nb>Invoke-Winget</span> <span class=n>-wingetId</span> <span class=nv>$Program</span> <span class=n>-scope</span> <span class=s2>"user"</span>
|
||
|
</span><span id=__span-4-92><a id=__codelineno-4-92 name=__codelineno-4-92 href=#__codelineno-4-92></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=n>0</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-93><a id=__codelineno-4-93 name=__codelineno-4-93 href=#__codelineno-4-93></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> installed successfully with User scope."</span>
|
||
|
</span><span id=__span-4-94><a id=__codelineno-4-94 name=__codelineno-4-94 href=#__codelineno-4-94></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-95><a id=__codelineno-4-95 name=__codelineno-4-95 href=#__codelineno-4-95></a> <span class=p>}</span> <span class=k>elseif</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=p>-</span><span class=n>1978335189</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-96><a id=__codelineno-4-96 name=__codelineno-4-96 href=#__codelineno-4-96></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> No applicable update found"</span>
|
||
|
</span><span id=__span-4-97><a id=__codelineno-4-97 name=__codelineno-4-97 href=#__codelineno-4-97></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-98><a id=__codelineno-4-98 name=__codelineno-4-98 href=#__codelineno-4-98></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-99><a id=__codelineno-4-99 name=__codelineno-4-99 href=#__codelineno-4-99></a>
|
||
|
</span><span id=__span-4-100><a id=__codelineno-4-100 name=__codelineno-4-100 href=#__codelineno-4-100></a> <span class=nv>$userChoice</span> <span class=p>=</span> <span class=no>[System.Windows.MessageBox]</span><span class=p>::</span><span class=n>Show</span><span class=p>(</span><span class=s2>"Do you want to attempt </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip."</span><span class=p>,</span> <span class=s2>"User credential Prompt"</span><span class=p>,</span> <span class=no>[System.Windows.MessageBoxButton]</span><span class=p>::</span><span class=n>YesNo</span><span class=p>)</span>
|
||
|
</span><span id=__span-4-101><a id=__codelineno-4-101 name=__codelineno-4-101 href=#__codelineno-4-101></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$userChoice</span> <span class=o>-eq</span> <span class=s1>'Yes'</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-102><a id=__codelineno-4-102 name=__codelineno-4-102 href=#__codelineno-4-102></a> <span class=nv>$getcreds</span> <span class=p>=</span> <span class=nb>Get-Credential</span>
|
||
|
</span><span id=__span-4-103><a id=__codelineno-4-103 name=__codelineno-4-103 href=#__codelineno-4-103></a> <span class=nv>$status</span> <span class=p>=</span> <span class=nb>Invoke-Winget</span> <span class=n>-wingetId</span> <span class=nv>$Program</span> <span class=n>-credential</span> <span class=nv>$getcreds</span>
|
||
|
</span><span id=__span-4-104><a id=__codelineno-4-104 name=__codelineno-4-104 href=#__codelineno-4-104></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=n>0</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-105><a id=__codelineno-4-105 name=__codelineno-4-105 href=#__codelineno-4-105></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> installed successfully with User prompt."</span>
|
||
|
</span><span id=__span-4-106><a id=__codelineno-4-106 name=__codelineno-4-106 href=#__codelineno-4-106></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-107><a id=__codelineno-4-107 name=__codelineno-4-107 href=#__codelineno-4-107></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-108><a id=__codelineno-4-108 name=__codelineno-4-108 href=#__codelineno-4-108></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-109><a id=__codelineno-4-109 name=__codelineno-4-109 href=#__codelineno-4-109></a> <span class=nb>Write-Host</span> <span class=s2>"Skipping installation with specific user credentials."</span>
|
||
|
</span><span id=__span-4-110><a id=__codelineno-4-110 name=__codelineno-4-110 href=#__codelineno-4-110></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-111><a id=__codelineno-4-111 name=__codelineno-4-111 href=#__codelineno-4-111></a>
|
||
|
</span><span id=__span-4-112><a id=__codelineno-4-112 name=__codelineno-4-112 href=#__codelineno-4-112></a> <span class=nb>Write-Host</span> <span class=s2>"Failed to install </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2>."</span>
|
||
|
</span><span id=__span-4-113><a id=__codelineno-4-113 name=__codelineno-4-113 href=#__codelineno-4-113></a> <span class=k>return</span> <span class=nv>$false</span>
|
||
|
</span><span id=__span-4-114><a id=__codelineno-4-114 name=__codelineno-4-114 href=#__codelineno-4-114></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-115><a id=__codelineno-4-115 name=__codelineno-4-115 href=#__codelineno-4-115></a>
|
||
|
</span><span id=__span-4-116><a id=__codelineno-4-116 name=__codelineno-4-116 href=#__codelineno-4-116></a> <span class=k>Function</span> <span class=nb>Invoke-Uninstall</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-117><a id=__codelineno-4-117 name=__codelineno-4-117 href=#__codelineno-4-117></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-4-118><a id=__codelineno-4-118 name=__codelineno-4-118 href=#__codelineno-4-118></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-4-119><a id=__codelineno-4-119 name=__codelineno-4-119 href=#__codelineno-4-119></a><span class=cm> Contains the Uninstall Logic and return code handling from winget</span>
|
||
|
</span><span id=__span-4-120><a id=__codelineno-4-120 name=__codelineno-4-120 href=#__codelineno-4-120></a>
|
||
|
</span><span id=__span-4-121><a id=__codelineno-4-121 name=__codelineno-4-121 href=#__codelineno-4-121></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> Program</span>
|
||
|
</span><span id=__span-4-122><a id=__codelineno-4-122 name=__codelineno-4-122 href=#__codelineno-4-122></a><span class=cm> The Winget ID of the Program that should be uninstalled</span>
|
||
|
</span><span id=__span-4-123><a id=__codelineno-4-123 name=__codelineno-4-123 href=#__codelineno-4-123></a><span class=cm> #></span>
|
||
|
</span><span id=__span-4-124><a id=__codelineno-4-124 name=__codelineno-4-124 href=#__codelineno-4-124></a> <span class=k>param</span> <span class=p>(</span>
|
||
|
</span><span id=__span-4-125><a id=__codelineno-4-125 name=__codelineno-4-125 href=#__codelineno-4-125></a> <span class=no>[psobject]</span><span class=nv>$Program</span>
|
||
|
</span><span id=__span-4-126><a id=__codelineno-4-126 name=__codelineno-4-126 href=#__codelineno-4-126></a> <span class=p>)</span>
|
||
|
</span><span id=__span-4-127><a id=__codelineno-4-127 name=__codelineno-4-127 href=#__codelineno-4-127></a>
|
||
|
</span><span id=__span-4-128><a id=__codelineno-4-128 name=__codelineno-4-128 href=#__codelineno-4-128></a> <span class=k>try</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-129><a id=__codelineno-4-129 name=__codelineno-4-129 href=#__codelineno-4-129></a> <span class=nv>$status</span> <span class=p>=</span> <span class=nb>Invoke-Winget</span> <span class=n>-wingetId</span> <span class=nv>$Program</span>
|
||
|
</span><span id=__span-4-130><a id=__codelineno-4-130 name=__codelineno-4-130 href=#__codelineno-4-130></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$status</span> <span class=o>-eq</span> <span class=n>0</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-131><a id=__codelineno-4-131 name=__codelineno-4-131 href=#__codelineno-4-131></a> <span class=nb>Write-Host</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> uninstalled successfully."</span>
|
||
|
</span><span id=__span-4-132><a id=__codelineno-4-132 name=__codelineno-4-132 href=#__codelineno-4-132></a> <span class=k>return</span> <span class=nv>$true</span>
|
||
|
</span><span id=__span-4-133><a id=__codelineno-4-133 name=__codelineno-4-133 href=#__codelineno-4-133></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-134><a id=__codelineno-4-134 name=__codelineno-4-134 href=#__codelineno-4-134></a> <span class=nb>Write-Host</span> <span class=s2>"Failed to uninstall </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2>."</span>
|
||
|
</span><span id=__span-4-135><a id=__codelineno-4-135 name=__codelineno-4-135 href=#__codelineno-4-135></a> <span class=k>return</span> <span class=nv>$false</span>
|
||
|
</span><span id=__span-4-136><a id=__codelineno-4-136 name=__codelineno-4-136 href=#__codelineno-4-136></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-137><a id=__codelineno-4-137 name=__codelineno-4-137 href=#__codelineno-4-137></a> <span class=p>}</span> <span class=k>catch</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-138><a id=__codelineno-4-138 name=__codelineno-4-138 href=#__codelineno-4-138></a> <span class=nb>Write-Host</span> <span class=s2>"Failed to uninstall </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2> due to an error: $_"</span>
|
||
|
</span><span id=__span-4-139><a id=__codelineno-4-139 name=__codelineno-4-139 href=#__codelineno-4-139></a> <span class=k>return</span> <span class=nv>$false</span>
|
||
|
</span><span id=__span-4-140><a id=__codelineno-4-140 name=__codelineno-4-140 href=#__codelineno-4-140></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-141><a id=__codelineno-4-141 name=__codelineno-4-141 href=#__codelineno-4-141></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-142><a id=__codelineno-4-142 name=__codelineno-4-142 href=#__codelineno-4-142></a>
|
||
|
</span><span id=__span-4-143><a id=__codelineno-4-143 name=__codelineno-4-143 href=#__codelineno-4-143></a> <span class=nv>$count</span> <span class=p>=</span> <span class=nv>$Programs</span><span class=p>.</span><span class=n>Count</span>
|
||
|
</span><span id=__span-4-144><a id=__codelineno-4-144 name=__codelineno-4-144 href=#__codelineno-4-144></a> <span class=nv>$failedPackages</span> <span class=p>=</span> <span class=p>@()</span>
|
||
|
</span><span id=__span-4-145><a id=__codelineno-4-145 name=__codelineno-4-145 href=#__codelineno-4-145></a>
|
||
|
</span><span id=__span-4-146><a id=__codelineno-4-146 name=__codelineno-4-146 href=#__codelineno-4-146></a> <span class=nb>Write-Host</span> <span class=s2>"==========================================="</span>
|
||
|
</span><span id=__span-4-147><a id=__codelineno-4-147 name=__codelineno-4-147 href=#__codelineno-4-147></a> <span class=nb>Write-Host</span> <span class=s2>"-- Configuring winget packages ---"</span>
|
||
|
</span><span id=__span-4-148><a id=__codelineno-4-148 name=__codelineno-4-148 href=#__codelineno-4-148></a> <span class=nb>Write-Host</span> <span class=s2>"==========================================="</span>
|
||
|
</span><span id=__span-4-149><a id=__codelineno-4-149 name=__codelineno-4-149 href=#__codelineno-4-149></a>
|
||
|
</span><span id=__span-4-150><a id=__codelineno-4-150 name=__codelineno-4-150 href=#__codelineno-4-150></a> <span class=k>for</span> <span class=p>(</span><span class=nv>$i</span> <span class=p>=</span> <span class=n>0</span><span class=p>;</span> <span class=nv>$i</span> <span class=o>-lt</span> <span class=nv>$count</span><span class=p>;</span> <span class=nv>$i</span><span class=p>++)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-151><a id=__codelineno-4-151 name=__codelineno-4-151 href=#__codelineno-4-151></a> <span class=nv>$Program</span> <span class=p>=</span> <span class=nv>$Programs</span><span class=p>[</span><span class=nv>$i</span><span class=p>]</span>
|
||
|
</span><span id=__span-4-152><a id=__codelineno-4-152 name=__codelineno-4-152 href=#__codelineno-4-152></a> <span class=nv>$result</span> <span class=p>=</span> <span class=nv>$false</span>
|
||
|
</span><span id=__span-4-153><a id=__codelineno-4-153 name=__codelineno-4-153 href=#__codelineno-4-153></a> <span class=nb>Set-WinUtilProgressBar</span> <span class=n>-label</span> <span class=s2>"$Action </span><span class=p>$(</span><span class=nv>$Program</span><span class=p>)</span><span class=s2>"</span> <span class=n>-percent</span> <span class=p>(</span><span class=nv>$i</span> <span class=p>/</span> <span class=nv>$count</span> <span class=p>*</span> <span class=n>100</span><span class=p>)</span>
|
||
|
</span><span id=__span-4-154><a id=__codelineno-4-154 name=__codelineno-4-154 href=#__codelineno-4-154></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span> <span class=nb>Set-WinUtilTaskbaritem</span> <span class=n>-value</span> <span class=p>(</span><span class=nv>$i</span> <span class=p>/</span> <span class=nv>$count</span><span class=p>)})</span>
|
||
|
</span><span id=__span-4-155><a id=__codelineno-4-155 name=__codelineno-4-155 href=#__codelineno-4-155></a>
|
||
|
</span><span id=__span-4-156><a id=__codelineno-4-156 name=__codelineno-4-156 href=#__codelineno-4-156></a> <span class=nv>$result</span> <span class=p>=</span> <span class=k>switch</span> <span class=p>(</span><span class=nv>$Action</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-157><a id=__codelineno-4-157 name=__codelineno-4-157 href=#__codelineno-4-157></a> <span class=s2>"Install"</span> <span class=p>{</span><span class=nb>Invoke-Install</span> <span class=n>-Program</span> <span class=nv>$Program</span><span class=p>}</span>
|
||
|
</span><span id=__span-4-158><a id=__codelineno-4-158 name=__codelineno-4-158 href=#__codelineno-4-158></a> <span class=s2>"Uninstall"</span> <span class=p>{</span><span class=nb>Invoke-Uninstall</span> <span class=n>-Program</span> <span class=nv>$Program</span><span class=p>}</span>
|
||
|
</span><span id=__span-4-159><a id=__codelineno-4-159 name=__codelineno-4-159 href=#__codelineno-4-159></a> <span class=k>default</span> <span class=p>{</span><span class=k>throw</span> <span class=s2>"[Install-WinUtilProgramWinget] Invalid action: $Action"</span><span class=p>}</span>
|
||
|
</span><span id=__span-4-160><a id=__codelineno-4-160 name=__codelineno-4-160 href=#__codelineno-4-160></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-161><a id=__codelineno-4-161 name=__codelineno-4-161 href=#__codelineno-4-161></a>
|
||
|
</span><span id=__span-4-162><a id=__codelineno-4-162 name=__codelineno-4-162 href=#__codelineno-4-162></a> <span class=k>if</span> <span class=p>(</span><span class=o>-not</span> <span class=nv>$result</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-4-163><a id=__codelineno-4-163 name=__codelineno-4-163 href=#__codelineno-4-163></a> <span class=nv>$failedPackages</span> <span class=p>+=</span> <span class=nv>$Program</span>
|
||
|
</span><span id=__span-4-164><a id=__codelineno-4-164 name=__codelineno-4-164 href=#__codelineno-4-164></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-165><a id=__codelineno-4-165 name=__codelineno-4-165 href=#__codelineno-4-165></a> <span class=p>}</span>
|
||
|
</span><span id=__span-4-166><a id=__codelineno-4-166 name=__codelineno-4-166 href=#__codelineno-4-166></a>
|
||
|
</span><span id=__span-4-167><a id=__codelineno-4-167 name=__codelineno-4-167 href=#__codelineno-4-167></a> <span class=nb>Set-WinUtilProgressBar</span> <span class=n>-label</span> <span class=s2>"</span><span class=p>$(</span><span class=nv>$Action</span><span class=p>)</span><span class=s2>ation done"</span> <span class=n>-percent</span> <span class=n>100</span>
|
||
|
</span><span id=__span-4-168><a id=__codelineno-4-168 name=__codelineno-4-168 href=#__codelineno-4-168></a> <span class=k>return</span> <span class=nv>$failedPackages</span>
|
||
|
</span><span id=__span-4-169><a id=__codelineno-4-169 name=__codelineno-4-169 href=#__codelineno-4-169></a><span class=p>}</span>
|
||
|
</span></code></pre></div> <h2 id=function-set-winutilprogressbar>Function: Set-WinUtilProgressbar<a class=headerlink href=#function-set-winutilprogressbar title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-5-1><a id=__codelineno-5-1 name=__codelineno-5-1 href=#__codelineno-5-1></a><span class=k>function</span> <span class=nb>Set-WinUtilProgressbar</span><span class=p>{</span>
|
||
|
</span><span id=__span-5-2><a id=__codelineno-5-2 name=__codelineno-5-2 href=#__codelineno-5-2></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-5-3><a id=__codelineno-5-3 name=__codelineno-5-3 href=#__codelineno-5-3></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-5-4><a id=__codelineno-5-4 name=__codelineno-5-4 href=#__codelineno-5-4></a><span class=cm> This function is used to Update the Progress Bar displayed in the winutil GUI.</span>
|
||
|
</span><span id=__span-5-5><a id=__codelineno-5-5 name=__codelineno-5-5 href=#__codelineno-5-5></a><span class=cm> It will be automatically hidden if the user clicks something and no process is running</span>
|
||
|
</span><span id=__span-5-6><a id=__codelineno-5-6 name=__codelineno-5-6 href=#__codelineno-5-6></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> Label</span>
|
||
|
</span><span id=__span-5-7><a id=__codelineno-5-7 name=__codelineno-5-7 href=#__codelineno-5-7></a><span class=cm> The Text to be overlayed onto the Progress Bar</span>
|
||
|
</span><span id=__span-5-8><a id=__codelineno-5-8 name=__codelineno-5-8 href=#__codelineno-5-8></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> PERCENT</span>
|
||
|
</span><span id=__span-5-9><a id=__codelineno-5-9 name=__codelineno-5-9 href=#__codelineno-5-9></a><span class=cm> The percentage of the Progress Bar that should be filled (0-100)</span>
|
||
|
</span><span id=__span-5-10><a id=__codelineno-5-10 name=__codelineno-5-10 href=#__codelineno-5-10></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> Hide</span>
|
||
|
</span><span id=__span-5-11><a id=__codelineno-5-11 name=__codelineno-5-11 href=#__codelineno-5-11></a><span class=cm> If provided, the Progress Bar and the label will be hidden</span>
|
||
|
</span><span id=__span-5-12><a id=__codelineno-5-12 name=__codelineno-5-12 href=#__codelineno-5-12></a><span class=cm> #></span>
|
||
|
</span><span id=__span-5-13><a id=__codelineno-5-13 name=__codelineno-5-13 href=#__codelineno-5-13></a> <span class=k>param</span><span class=p>(</span>
|
||
|
</span><span id=__span-5-14><a id=__codelineno-5-14 name=__codelineno-5-14 href=#__codelineno-5-14></a> <span class=no>[string]</span><span class=nv>$Label</span><span class=p>,</span>
|
||
|
</span><span id=__span-5-15><a id=__codelineno-5-15 name=__codelineno-5-15 href=#__codelineno-5-15></a> <span class=p>[</span><span class=k>ValidateRange</span><span class=p>(</span><span class=n>0</span><span class=p>,</span><span class=n>100</span><span class=p>)]</span>
|
||
|
</span><span id=__span-5-16><a id=__codelineno-5-16 name=__codelineno-5-16 href=#__codelineno-5-16></a> <span class=no>[int]</span><span class=nv>$Percent</span><span class=p>,</span>
|
||
|
</span><span id=__span-5-17><a id=__codelineno-5-17 name=__codelineno-5-17 href=#__codelineno-5-17></a> <span class=nv>$Hide</span>
|
||
|
</span><span id=__span-5-18><a id=__codelineno-5-18 name=__codelineno-5-18 href=#__codelineno-5-18></a> <span class=p>)</span>
|
||
|
</span><span id=__span-5-19><a id=__codelineno-5-19 name=__codelineno-5-19 href=#__codelineno-5-19></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$hide</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-5-20><a id=__codelineno-5-20 name=__codelineno-5-20 href=#__codelineno-5-20></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBarLabel</span><span class=p>.</span><span class=n>Visibility</span> <span class=p>=</span> <span class=s2>"Collapsed"</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-21><a id=__codelineno-5-21 name=__codelineno-5-21 href=#__codelineno-5-21></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBar</span><span class=p>.</span><span class=n>Visibility</span> <span class=p>=</span> <span class=s2>"Collapsed"</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-22><a id=__codelineno-5-22 name=__codelineno-5-22 href=#__codelineno-5-22></a> <span class=p>}</span> <span class=k>else</span> <span class=p>{</span>
|
||
|
</span><span id=__span-5-23><a id=__codelineno-5-23 name=__codelineno-5-23 href=#__codelineno-5-23></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBarLabel</span><span class=p>.</span><span class=n>Visibility</span> <span class=p>=</span> <span class=s2>"Visible"</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-24><a id=__codelineno-5-24 name=__codelineno-5-24 href=#__codelineno-5-24></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBar</span><span class=p>.</span><span class=n>Visibility</span> <span class=p>=</span> <span class=s2>"Visible"</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-25><a id=__codelineno-5-25 name=__codelineno-5-25 href=#__codelineno-5-25></a> <span class=p>}</span>
|
||
|
</span><span id=__span-5-26><a id=__codelineno-5-26 name=__codelineno-5-26 href=#__codelineno-5-26></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBarLabel</span><span class=p>.</span><span class=n>Content</span><span class=p>.</span><span class=n>Text</span> <span class=p>=</span> <span class=nv>$label</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-27><a id=__codelineno-5-27 name=__codelineno-5-27 href=#__codelineno-5-27></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span><span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBarLabel</span><span class=p>.</span><span class=n>Content</span><span class=p>.</span><span class=n>ToolTip</span> <span class=p>=</span> <span class=nv>$label</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-28><a id=__codelineno-5-28 name=__codelineno-5-28 href=#__codelineno-5-28></a> <span class=nv>$sync</span><span class=p>.</span><span class=n>form</span><span class=p>.</span><span class=n>Dispatcher</span><span class=p>.</span><span class=n>Invoke</span><span class=p>(</span><span class=no>[action]</span><span class=p>{</span> <span class=nv>$sync</span><span class=p>.</span><span class=n>ProgressBar</span><span class=p>.</span><span class=n>Value</span> <span class=p>=</span> <span class=nv>$percent</span><span class=p>})</span>
|
||
|
</span><span id=__span-5-29><a id=__codelineno-5-29 name=__codelineno-5-29 href=#__codelineno-5-29></a>
|
||
|
</span><span id=__span-5-30><a id=__codelineno-5-30 name=__codelineno-5-30 href=#__codelineno-5-30></a><span class=p>}</span>
|
||
|
</span></code></pre></div> <h2 id=function-set-winutiltaskbaritem>Function: Set-WinUtilTaskbarItem<a class=headerlink href=#function-set-winutiltaskbaritem title="Permanent link">¶</a></h2> <div class="language-powershell highlight"><pre><span></span><code><span id=__span-6-1><a id=__codelineno-6-1 name=__codelineno-6-1 href=#__codelineno-6-1></a><span class=k>function</span> <span class=nb>Set-WinUtilTaskbaritem</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-2><a id=__codelineno-6-2 name=__codelineno-6-2 href=#__codelineno-6-2></a> <span class=cm><#</span>
|
||
|
</span><span id=__span-6-3><a id=__codelineno-6-3 name=__codelineno-6-3 href=#__codelineno-6-3></a>
|
||
|
</span><span id=__span-6-4><a id=__codelineno-6-4 name=__codelineno-6-4 href=#__codelineno-6-4></a><span class=cm> </span><span class=sd>.SYNOPSIS</span>
|
||
|
</span><span id=__span-6-5><a id=__codelineno-6-5 name=__codelineno-6-5 href=#__codelineno-6-5></a><span class=cm> Modifies the Taskbaritem of the WPF Form</span>
|
||
|
</span><span id=__span-6-6><a id=__codelineno-6-6 name=__codelineno-6-6 href=#__codelineno-6-6></a>
|
||
|
</span><span id=__span-6-7><a id=__codelineno-6-7 name=__codelineno-6-7 href=#__codelineno-6-7></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> value</span>
|
||
|
</span><span id=__span-6-8><a id=__codelineno-6-8 name=__codelineno-6-8 href=#__codelineno-6-8></a><span class=cm> Value can be between 0 and 1, 0 being no progress done yet and 1 being fully completed</span>
|
||
|
</span><span id=__span-6-9><a id=__codelineno-6-9 name=__codelineno-6-9 href=#__codelineno-6-9></a><span class=cm> Value does not affect item without setting the state to 'Normal', 'Error' or 'Paused'</span>
|
||
|
</span><span id=__span-6-10><a id=__codelineno-6-10 name=__codelineno-6-10 href=#__codelineno-6-10></a><span class=cm> Set-WinUtilTaskbaritem -value 0.5</span>
|
||
|
</span><span id=__span-6-11><a id=__codelineno-6-11 name=__codelineno-6-11 href=#__codelineno-6-11></a>
|
||
|
</span><span id=__span-6-12><a id=__codelineno-6-12 name=__codelineno-6-12 href=#__codelineno-6-12></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> state</span>
|
||
|
</span><span id=__span-6-13><a id=__codelineno-6-13 name=__codelineno-6-13 href=#__codelineno-6-13></a><span class=cm> State can be 'None' > No progress, 'Indeterminate' > inf. loading gray, 'Normal' > Gray, 'Error' > Red, 'Paused' > Yellow</span>
|
||
|
</span><span id=__span-6-14><a id=__codelineno-6-14 name=__codelineno-6-14 href=#__codelineno-6-14></a><span class=cm> no value needed:</span>
|
||
|
</span><span id=__span-6-15><a id=__codelineno-6-15 name=__codelineno-6-15 href=#__codelineno-6-15></a><span class=cm> - Set-WinUtilTaskbaritem -state "None"</span>
|
||
|
</span><span id=__span-6-16><a id=__codelineno-6-16 name=__codelineno-6-16 href=#__codelineno-6-16></a><span class=cm> - Set-WinUtilTaskbaritem -state "Indeterminate"</span>
|
||
|
</span><span id=__span-6-17><a id=__codelineno-6-17 name=__codelineno-6-17 href=#__codelineno-6-17></a><span class=cm> value needed:</span>
|
||
|
</span><span id=__span-6-18><a id=__codelineno-6-18 name=__codelineno-6-18 href=#__codelineno-6-18></a><span class=cm> - Set-WinUtilTaskbaritem -state "Error"</span>
|
||
|
</span><span id=__span-6-19><a id=__codelineno-6-19 name=__codelineno-6-19 href=#__codelineno-6-19></a><span class=cm> - Set-WinUtilTaskbaritem -state "Normal"</span>
|
||
|
</span><span id=__span-6-20><a id=__codelineno-6-20 name=__codelineno-6-20 href=#__codelineno-6-20></a><span class=cm> - Set-WinUtilTaskbaritem -state "Paused"</span>
|
||
|
</span><span id=__span-6-21><a id=__codelineno-6-21 name=__codelineno-6-21 href=#__codelineno-6-21></a>
|
||
|
</span><span id=__span-6-22><a id=__codelineno-6-22 name=__codelineno-6-22 href=#__codelineno-6-22></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> overlay</span>
|
||
|
</span><span id=__span-6-23><a id=__codelineno-6-23 name=__codelineno-6-23 href=#__codelineno-6-23></a><span class=cm> Overlay icon to display on the taskbar item, there are the presets 'None', 'logo' and 'checkmark' or you can specify a path/link to an image file.</span>
|
||
|
</span><span id=__span-6-24><a id=__codelineno-6-24 name=__codelineno-6-24 href=#__codelineno-6-24></a><span class=cm> CTT logo preset:</span>
|
||
|
</span><span id=__span-6-25><a id=__codelineno-6-25 name=__codelineno-6-25 href=#__codelineno-6-25></a><span class=cm> - Set-WinUtilTaskbaritem -overlay "logo"</span>
|
||
|
</span><span id=__span-6-26><a id=__codelineno-6-26 name=__codelineno-6-26 href=#__codelineno-6-26></a><span class=cm> Checkmark preset:</span>
|
||
|
</span><span id=__span-6-27><a id=__codelineno-6-27 name=__codelineno-6-27 href=#__codelineno-6-27></a><span class=cm> - Set-WinUtilTaskbaritem -overlay "checkmark"</span>
|
||
|
</span><span id=__span-6-28><a id=__codelineno-6-28 name=__codelineno-6-28 href=#__codelineno-6-28></a><span class=cm> Warning preset:</span>
|
||
|
</span><span id=__span-6-29><a id=__codelineno-6-29 name=__codelineno-6-29 href=#__codelineno-6-29></a><span class=cm> - Set-WinUtilTaskbaritem -overlay "warning"</span>
|
||
|
</span><span id=__span-6-30><a id=__codelineno-6-30 name=__codelineno-6-30 href=#__codelineno-6-30></a><span class=cm> No overlay:</span>
|
||
|
</span><span id=__span-6-31><a id=__codelineno-6-31 name=__codelineno-6-31 href=#__codelineno-6-31></a><span class=cm> - Set-WinUtilTaskbaritem -overlay "None"</span>
|
||
|
</span><span id=__span-6-32><a id=__codelineno-6-32 name=__codelineno-6-32 href=#__codelineno-6-32></a><span class=cm> Custom icon (needs to be supported by WPF):</span>
|
||
|
</span><span id=__span-6-33><a id=__codelineno-6-33 name=__codelineno-6-33 href=#__codelineno-6-33></a><span class=cm> - Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"</span>
|
||
|
</span><span id=__span-6-34><a id=__codelineno-6-34 name=__codelineno-6-34 href=#__codelineno-6-34></a>
|
||
|
</span><span id=__span-6-35><a id=__codelineno-6-35 name=__codelineno-6-35 href=#__codelineno-6-35></a><span class=cm> </span><span class=sd>.PARAMETER</span><span class=cm> description</span>
|
||
|
</span><span id=__span-6-36><a id=__codelineno-6-36 name=__codelineno-6-36 href=#__codelineno-6-36></a><span class=cm> Description to display on the taskbar item preview</span>
|
||
|
</span><span id=__span-6-37><a id=__codelineno-6-37 name=__codelineno-6-37 href=#__codelineno-6-37></a><span class=cm> Set-WinUtilTaskbaritem -description "This is a description"</span>
|
||
|
</span><span id=__span-6-38><a id=__codelineno-6-38 name=__codelineno-6-38 href=#__codelineno-6-38></a><span class=cm> #></span>
|
||
|
</span><span id=__span-6-39><a id=__codelineno-6-39 name=__codelineno-6-39 href=#__codelineno-6-39></a> <span class=k>param</span> <span class=p>(</span>
|
||
|
</span><span id=__span-6-40><a id=__codelineno-6-40 name=__codelineno-6-40 href=#__codelineno-6-40></a> <span class=no>[string]</span><span class=nv>$state</span><span class=p>,</span>
|
||
|
</span><span id=__span-6-41><a id=__codelineno-6-41 name=__codelineno-6-41 href=#__codelineno-6-41></a> <span class=no>[double]</span><span class=nv>$value</span><span class=p>,</span>
|
||
|
</span><span id=__span-6-42><a id=__codelineno-6-42 name=__codelineno-6-42 href=#__codelineno-6-42></a> <span class=no>[string]</span><span class=nv>$overlay</span><span class=p>,</span>
|
||
|
</span><span id=__span-6-43><a id=__codelineno-6-43 name=__codelineno-6-43 href=#__codelineno-6-43></a> <span class=no>[string]</span><span class=nv>$description</span>
|
||
|
</span><span id=__span-6-44><a id=__codelineno-6-44 name=__codelineno-6-44 href=#__codelineno-6-44></a> <span class=p>)</span>
|
||
|
</span><span id=__span-6-45><a id=__codelineno-6-45 name=__codelineno-6-45 href=#__codelineno-6-45></a>
|
||
|
</span><span id=__span-6-46><a id=__codelineno-6-46 name=__codelineno-6-46 href=#__codelineno-6-46></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$value</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-47><a id=__codelineno-6-47 name=__codelineno-6-47 href=#__codelineno-6-47></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressValue</span> <span class=p>=</span> <span class=nv>$value</span>
|
||
|
</span><span id=__span-6-48><a id=__codelineno-6-48 name=__codelineno-6-48 href=#__codelineno-6-48></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-49><a id=__codelineno-6-49 name=__codelineno-6-49 href=#__codelineno-6-49></a>
|
||
|
</span><span id=__span-6-50><a id=__codelineno-6-50 name=__codelineno-6-50 href=#__codelineno-6-50></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$state</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-51><a id=__codelineno-6-51 name=__codelineno-6-51 href=#__codelineno-6-51></a> <span class=k>switch</span> <span class=p>(</span><span class=nv>$state</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-52><a id=__codelineno-6-52 name=__codelineno-6-52 href=#__codelineno-6-52></a> <span class=s1>'None'</span> <span class=p>{</span> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressState</span> <span class=p>=</span> <span class=s2>"None"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-53><a id=__codelineno-6-53 name=__codelineno-6-53 href=#__codelineno-6-53></a> <span class=s1>'Indeterminate'</span> <span class=p>{</span> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressState</span> <span class=p>=</span> <span class=s2>"Indeterminate"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-54><a id=__codelineno-6-54 name=__codelineno-6-54 href=#__codelineno-6-54></a> <span class=s1>'Normal'</span> <span class=p>{</span> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressState</span> <span class=p>=</span> <span class=s2>"Normal"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-55><a id=__codelineno-6-55 name=__codelineno-6-55 href=#__codelineno-6-55></a> <span class=s1>'Error'</span> <span class=p>{</span> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressState</span> <span class=p>=</span> <span class=s2>"Error"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-56><a id=__codelineno-6-56 name=__codelineno-6-56 href=#__codelineno-6-56></a> <span class=s1>'Paused'</span> <span class=p>{</span> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>ProgressState</span> <span class=p>=</span> <span class=s2>"Paused"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-57><a id=__codelineno-6-57 name=__codelineno-6-57 href=#__codelineno-6-57></a> <span class=k>default</span> <span class=p>{</span> <span class=k>throw</span> <span class=s2>"[Set-WinUtilTaskbarItem] Invalid state"</span> <span class=p>}</span>
|
||
|
</span><span id=__span-6-58><a id=__codelineno-6-58 name=__codelineno-6-58 href=#__codelineno-6-58></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-59><a id=__codelineno-6-59 name=__codelineno-6-59 href=#__codelineno-6-59></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-60><a id=__codelineno-6-60 name=__codelineno-6-60 href=#__codelineno-6-60></a>
|
||
|
</span><span id=__span-6-61><a id=__codelineno-6-61 name=__codelineno-6-61 href=#__codelineno-6-61></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$overlay</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-62><a id=__codelineno-6-62 name=__codelineno-6-62 href=#__codelineno-6-62></a> <span class=k>switch</span> <span class=p>(</span><span class=nv>$overlay</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-63><a id=__codelineno-6-63 name=__codelineno-6-63 href=#__codelineno-6-63></a> <span class=s1>'logo'</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-64><a id=__codelineno-6-64 name=__codelineno-6-64 href=#__codelineno-6-64></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Overlay</span> <span class=p>=</span> <span class=s2>"$env:LOCALAPPDATA\winutil\cttlogo.png"</span>
|
||
|
</span><span id=__span-6-65><a id=__codelineno-6-65 name=__codelineno-6-65 href=#__codelineno-6-65></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-66><a id=__codelineno-6-66 name=__codelineno-6-66 href=#__codelineno-6-66></a> <span class=s1>'checkmark'</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-67><a id=__codelineno-6-67 name=__codelineno-6-67 href=#__codelineno-6-67></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Overlay</span> <span class=p>=</span> <span class=s2>"$env:LOCALAPPDATA\winutil\checkmark.png"</span>
|
||
|
</span><span id=__span-6-68><a id=__codelineno-6-68 name=__codelineno-6-68 href=#__codelineno-6-68></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-69><a id=__codelineno-6-69 name=__codelineno-6-69 href=#__codelineno-6-69></a> <span class=s1>'warning'</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-70><a id=__codelineno-6-70 name=__codelineno-6-70 href=#__codelineno-6-70></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Overlay</span> <span class=p>=</span> <span class=s2>"$env:LOCALAPPDATA\winutil\warning.png"</span>
|
||
|
</span><span id=__span-6-71><a id=__codelineno-6-71 name=__codelineno-6-71 href=#__codelineno-6-71></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-72><a id=__codelineno-6-72 name=__codelineno-6-72 href=#__codelineno-6-72></a> <span class=s1>'None'</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-73><a id=__codelineno-6-73 name=__codelineno-6-73 href=#__codelineno-6-73></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Overlay</span> <span class=p>=</span> <span class=nv>$null</span>
|
||
|
</span><span id=__span-6-74><a id=__codelineno-6-74 name=__codelineno-6-74 href=#__codelineno-6-74></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-75><a id=__codelineno-6-75 name=__codelineno-6-75 href=#__codelineno-6-75></a> <span class=k>default</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-76><a id=__codelineno-6-76 name=__codelineno-6-76 href=#__codelineno-6-76></a> <span class=k>if</span> <span class=p>(</span><span class=nb>Test-Path</span> <span class=nv>$overlay</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-77><a id=__codelineno-6-77 name=__codelineno-6-77 href=#__codelineno-6-77></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Overlay</span> <span class=p>=</span> <span class=nv>$overlay</span>
|
||
|
</span><span id=__span-6-78><a id=__codelineno-6-78 name=__codelineno-6-78 href=#__codelineno-6-78></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-79><a id=__codelineno-6-79 name=__codelineno-6-79 href=#__codelineno-6-79></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-80><a id=__codelineno-6-80 name=__codelineno-6-80 href=#__codelineno-6-80></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-81><a id=__codelineno-6-81 name=__codelineno-6-81 href=#__codelineno-6-81></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-82><a id=__codelineno-6-82 name=__codelineno-6-82 href=#__codelineno-6-82></a>
|
||
|
</span><span id=__span-6-83><a id=__codelineno-6-83 name=__codelineno-6-83 href=#__codelineno-6-83></a> <span class=k>if</span> <span class=p>(</span><span class=nv>$description</span><span class=p>)</span> <span class=p>{</span>
|
||
|
</span><span id=__span-6-84><a id=__codelineno-6-84 name=__codelineno-6-84 href=#__codelineno-6-84></a> <span class=nv>$sync</span><span class=p>[</span><span class=s2>"Form"</span><span class=p>].</span><span class=n>taskbarItemInfo</span><span class=p>.</span><span class=n>Description</span> <span class=p>=</span> <span class=nv>$description</span>
|
||
|
</span><span id=__span-6-85><a id=__codelineno-6-85 name=__codelineno-6-85 href=#__codelineno-6-85></a> <span class=p>}</span>
|
||
|
</span><span id=__span-6-86><a id=__codelineno-6-86 name=__codelineno-6-86 href=#__codelineno-6-86></a><span class=p>}</span>
|
||
|
</span></code></pre></div> <p><a href=https://github.com/ChrisTitusTech/winutil/tree/main/config/tweaks.json>View the JSON file</a></p> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">August 8, 2024</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var tab,labels=set.querySelector(".tabbed-labels");for(tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg> Back to top </button> </main> </div> <div class=md-dialog data-md-component=dialog> <div class="md-dialog__inner md-typeset"></div> </div> <script id=__config type=application/json>{"base": "../../../..", "features": ["navigation.tabs", "navigation.sections", "toc.integrate", "navigation.top", "search.suggest", "search.highlight", "content.tabs.link", "content.code.annotation", "content.code.copy"], "search": "../../../../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script> <script src=../../../../assets/javascripts/bundle.fe8b6f2b.min.js></script> </body> </html>
|