use this in powershell:
Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process
-note: this closes the powershell console or ise too and cannot finish the job!
(get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" } )| stop-process
this way, only PowerShell windows are still alive, but the last command in your script might be
stop-process powershell
Note: this does not affect the minimization of the tray icon process.
EDIT:
to close the "control panel" on xp, try the following:
(New-Object -comObject Shell.Application).Windows() | where-object {$_.LocationName -eq "Control Panel"} | foreach-object {$_.quit()}
close all windows explorer.exe:
(New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()}
source share