Saturday, July 29, 2017

powershell script to clean unwanted apps in windows 10 1703

Hi,

2017-07-31 10:11
App removal section was remade with "familyname"


This powershell script (that you can run in a unattend windows installation) will clean up some unwanted apps

It can clear only the menu item ot the complete app and prevent futur installation from store

If you run it in unattend windows installation, you must include this command in autounattent.xml:

<SynchronousCommand wcm:action="add">
<Description>powershell permission remotesigned</Description>
<Order>1</Order>
<CommandLine>reg add HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ /v ExecutionPolicy /t Reg_SZ /d "RemoteSigned" /f</CommandLine>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>

Note: it allow local powershell script executions. you should block it in domain GPO later, it is not secure to let it allowed (Expecially if the user have admin right on it's own computer)



#Set-ExecutionPolicy -scope localmachine remotesigned

### run as admin
#If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))

#{  
#$arguments = "& '" + $myinvocation.mycommand.definition + "'"
#Start-Process powershell -Verb runAs -ArgumentList $arguments
#Break
#}

### just list the items that are in the array, do not remove anything
$listonly01 = 0

### remove menu item only

write-host "=== will remove menu icon"

[string[]]$items01="SkypeApp_kzf8qxf38zg5c"
$items01+="OneNote_8wekyb3d8bbwe"
$items01+="MicrosoftEdge_8wekyb3d8bbwe"
$items01+="HolographicFirstRun_cw5n1h2txyewy"
$items01+="ContactSupport_cw5n1h2txyewy"
$items01+="3DBuilder_8wekyb3d8bbwe"
$items01+="Getstarted_8wekyb3d8bbwe"

$items01+="Photos_8wekyb3d8bbwe"
$items01+="WindowsCamera_8wekyb3d8bbwe"
$items01+="windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.calendar"
$items01+="windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.mail"
$items01+="BingWeather_8wekyb3d8bbwe"
$items01+="actualité"
$items01+="twitter"
$items01+="sketchbook"

$action01 = "*Détacher de l*écran d*accueil*"

foreach ($item01 in $items01)
    {
    if ($listonly01 -eq 1)
        {
        ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | select name, path | where-object {$_.path –like "*$item01*" -or $_.name –like "*$item01*"})
        }
        else
        {
        ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | where-object {$_.path –like "*$item01*"}).Verbs() | ?{$_.Name.replace('&','') -like "$action01"} | %{$_.DOIT()}
        }
   
    }

### remove menu item, app, lock future installation
write-host "=== will remove menu icon, delete app, prevent futur install"

[string[]]$items02="http://java.com/help"
$items02+="MicrosoftSolitaireCollection_8wekyb3d8bbwe"
$items02+="MSPaint_8wekyb3d8bbwe"
$items02+="Microsoft3DViewer_8wekyb3d8bbwe"
$items02+="XboxApp_8wekyb3d8bbwe"
$items02+="ZuneMusic_8wekyb3d8bbwe"
$items02+="ZuneVideo_8wekyb3d8bbwe"
$items02+="MicrosoftOfficeHub_8wekyb3d8bbwe"
$items02+="http://java.com/"
$items02+="asphalt*8*airborne"
$items02+="marchofempire"
$items02+="bubblewitch3saga"
$items02+="candycrushsodasaga"
$items02+="asphalt*8*airborne"
$items02+="minecraft"
$items02+="xbox"

$action01 = "*Détacher de l*écran d*accueil*"

foreach ($item02 in $items02)
    {
    if ($listonly01 -eq 1)
        {
        ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | select name, path | where-object {$_.path –like "*$item02*" -or $_.name –like "*$item02*"})
        }
        else
        {
        write-host $action01 ":" $item02
        ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | where-object {$_.path –like "*$item02*"}).Verbs() | ?{$_.Name.replace('&','') -like "$action01"} | %{$_.doit()}
       
        write-host "removing: " $item02
        (Get-AppxPackage -allusers | where-object {$_.name –like "*$item02*" -or $_.PackageFamilyName –like "*$item02*"}) | Remove-AppxPackage
       
        write-host "removing online install: " $item02
        Get-appxprovisionedpackage –online | where-object {$_.name –like "*$item02*" -or $_.PackageFamilyName –like "*$item02*"} | remove-appxprovisionedpackage –online
        }
    }


1 comment: