3

I have a script that lists Windows 10 Apps to the user, and the user can select an app from the list, and it will remove the app. This is where I started from: Uninstall Windows 10 Apps.

My Code:

$appArray = @("3dbuilder", "windowsalarms", "Appconnector", "windowscalculator", "windowscommunicationsapps", "windowscamera", "CandyCrushSaga",
              "officehub", "skypeapp", "getstarted","zunemusic", "windowsmaps", "Messaging", "solitairecollection", "ConnectivityStore", "bingfinance",
              "zunevideo", "bingnews", "onenote", "people", "CommsPhone", "windowsphone", "photos", "WindowsScan", "bingsports", "windowsstore",
              "Office.Sway", "Twitter", "soundrecord", "bingweather", "xboxapp", "XboxOneSmartGlass")
$appNames = @("3D Builder", "Alarms & Clock", "App Connector", "Calculator", "Calendar and Mail", "Camera", "Candy Crush Saga", "Get Office", "Get Skype", 
              "Get Started", "Groove Music", "Maps", "Messaging", "Microsoft Solitaire Collection", "Microsoft Wi-Fi", "Money", "Movie & TV", "News", 
              "OneNote", "People", "Phone", "Phone Companion", "Photos", "Scan", "Sports", "Store (Not Recommended)", "Sway", "Twitter", "Voice Recorder", 
              "Weather", "Xbox", "Xbox One SmartGlass")

Do{
    $index = 1;

    Write-Host "Select An Option Below to Uninstall...`n"

    foreach ($app in $appNames){
        Write-Host "'$index': $app"
        $index++
    }

    Write-Host "'0': Exit"

    Write-Host "`n"
    $userOption = Read-Host -Prompt "Option: "

    if($userOption -gt 0){

        $appOption = $userOption - 1

        Get-appxpackage -allusers | where-object {$_.packagefullname -like "*$appArray[$appOption]*"} | remove-appxpackage
        Get-appxprovisionedpackage –online | where-object {$_.packagefullname –like "*$appArray[$appOption]*"} | remove-appxprovisionedpackage –online

        $appList = Get-appxpackage -allusers | where-object {$_.packagename -like "*$appArray[$appOption]*"}

        Write-Host "'$appList'"

        $userOption = 0
    }

}While($userOption -ne 0)


Write-Host "Exiting Script..."

The Problem:

The script runs without an error, but then none of the apps get removed. I added in these lines to see what the app it finds is, but it comes out as an empty string.

$appList = Get-appxpackage -allusers | where-object {$_.packagename -like "*$appArray[$appOption]*"}
Write-Host "'$appList'"

An example result would look like so:

Option: : 1
''
Exiting Script...

CaptainQuint
  • 332
  • 6
  • 22

1 Answers1

4

Use "*$($appArray[$appOption])*" instead of "*$appArray[$appOption]*"

Martin
  • 1,853
  • 3
  • 15
  • 22
  • That works, perfect. I have also found that the command I'm running should have `$_.packagefullname` as opposed to `$_.packagename`. I'll update my question with this new found information. – CaptainQuint Feb 17 '16 at 17:53