@@ -96,6 +96,20 @@ Justification='This script is not intended for pipelining.')]
96
96
)
97
97
Begin
98
98
{
99
+ function Test-EmptyDesktop ([switch ] $Shared )
100
+ {
101
+ if ($Shared -and ! (Test-Administrator.ps1 )) {return $false }
102
+ $dir = [environment ]::GetFolderPath(($Shared ? ' CommonDesktopDirectory' : ' Desktop' ))
103
+ return ! (Get-ChildItem - Path $dir - Filter * .lnk)
104
+ }
105
+
106
+ function Clear-Desktop ([switch ] $Shared )
107
+ {
108
+ if ($Shared -and ! (Test-Administrator.ps1 )) {return }
109
+ $dir = [environment ]::GetFolderPath(($Shared ? ' CommonDesktopDirectory' : ' Desktop' ))
110
+ Remove-Item - Path $dir - Filter * .lnk
111
+ }
112
+
99
113
Set-Variable ' UP!' " $ ( [char ]0xD83C ) $ ( [char ]0xDD99 ) " - Option Constant - Scope Script - Description ' UP! symbol'
100
114
101
115
function Write-Step ([string ]$Message )
@@ -115,7 +129,7 @@ Begin
115
129
116
130
function Update-Essential
117
131
{
118
- if (! (Test-Administrator.ps1 )) {Write-Warning " Not running as admin; skipping Essentials ." ; return }
132
+ if (! (Test-Administrator.ps1 )) {Write-Warning " Not running as admin; skipping Essential ." ; return }
119
133
Write-Step " $ ( [char ]0xD83D ) $ ( [char ]0xDD1C ) Checking for essential updates"
120
134
if (Get-Command choco - ErrorAction Ignore)
121
135
{
@@ -142,6 +156,7 @@ Begin
142
156
143
157
function Update-WindowsStore
144
158
{
159
+ if (! (Test-Administrator.ps1 )) {Write-Warning " Not running as admin; skipping WindowsStore." ; return }
145
160
if (! (Get-Command Get-CimInstance - ErrorAction Ignore))
146
161
{Write-Verbose ' Get-CimInstance not found, skipping WindowsStore updates' ; return }
147
162
Write-Step " ${UP!} Updating Windows Store apps (asynchronously)"
@@ -250,4 +265,14 @@ Begin
250
265
}
251
266
}
252
267
253
- Process {$Steps | ForEach-Object {& " Update-$_ " }}
268
+ Process
269
+ {
270
+ $emptyShared = Test-EmptyDesktop - Shared
271
+ $empty = Test-EmptyDesktop
272
+ try {$Steps | ForEach-Object {& " Update-$_ " }}
273
+ finally
274
+ {
275
+ if ($emptyShared ) {Clear-Desktop - Shared}
276
+ if ($empty ) {Clear-Desktop }
277
+ }
278
+ }
0 commit comments