使用 Powershell 脚本删除 Windows 10 应用程序 [英] Removing Windows 10 Apps with Powershell Script

查看:58
本文介绍了使用 Powershell 脚本删除 Windows 10 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向用户列出 Windows 10 应用程序的脚本,用户可以从列表中选择一个应用程序,它将删除该应用程序.这是我开始的地方:卸载 Windows 10 应用程序.

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.

我的代码:

$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 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'"

示例结果如下所示:

选项::1
''
退出脚本...

Option: : 1
''
Exiting Script...

推荐答案

使用 "*$($appArray[$appOption])*" 而不是 "*$appArray[$appOption]*"

这篇关于使用 Powershell 脚本删除 Windows 10 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆