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...

1
  • Should be a gist Commented Jun 12, 2019 at 21:48

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.