用于循环使用DISM删除Windows 10中不需要的应用程序

时间:2017-07-25 11:28:32

标签: windows powershell dism

我在使用以下脚本时遇到问题。尽管它表示在运行期间它是成功的,但应用程序仍然存在于操作系统中。 DISM日志文件也没有帮助。

# Remove non-corporate apps
$AppsList = "Microsoft.3DBuilder",`
            "Microsoft.Advertising.Xaml",`
            "Microsoft.Messaging",`
            "Microsoft.Microsoft3DViewer",`
            "Microsoft.Messaging",`
            "Microsoft.MicrosoftOfficeHub",`
            "Microsoft.MicrosoftSolitaireCollection",`
            "Microsoft.Office.OneNote",`
            "Microsoft.OneConnect",`
            "Microsoft.People",`
            "Microsoft.SkypeApp",`
            #"Microsoft.StorePurchaseApp",`
            "Microsoft.Wallet",`
            "Microsoft.XboxApp",`
            "Microsoft.XboxGameOverlay",`
            "Microsoft.XboxIdentityProvider",`
            "Microsoft.XboxSpeechToTextOverlay",`
            "Microsoft.ZuneMusic",`
            "Microsoft.ZuneVideo",`
            #"Microsoft.WindowsStore",`
            "microsoft.windowscommunicationsapps",`
            "Microsoft.WindowsPhone",`
            "Microsoft.Office.Sway",`
            "Microsoft.ConnectivityStore",`
            "Microsoft.CommsPhone",`
            "Microsoft.BingFinance"

ForEach ($app in $AppsList){
$variable = DISM /Online /Get-ProvisionedAppxPackages | select-string Packagename
$variable2 = $variable -replace "PackageName : ", ""
}

$variable2| % {DISM /Online /Remove-ProvisionedAppxPackage /PackageName:$_}

2 个答案:

答案 0 :(得分:1)

要从当前用户中删除应用:

ForEach ($app in $AppsList)
{
    Get-AppxPackage -Name $app | Remove-AppxPackage
}

要从登录系统使用的新用户中删除应用,但不要从现有用户中删除:

ForEach ($app in $AppsList)
{
Get-AppXProvisionedPackage -Online | Where-Object { $_.DisplayName -eq  $app } | Remove-AppxProvisionedPackage -Online
}

答案 1 :(得分:0)

我使用Remove-AppxProvisionedPackage代替DISM

# Remove non-corporate apps
$AppsList = "Microsoft.3DBuilder",`
            "Microsoft.Advertising.Xaml",`
            "Microsoft.Messaging",`
            "Microsoft.Microsoft3DViewer",`
            "Microsoft.Messaging",`
            "Microsoft.MicrosoftOfficeHub",`
            "Microsoft.MicrosoftSolitaireCollection",`
            "Microsoft.Office.OneNote",`
            "Microsoft.OneConnect",`
            "Microsoft.People",`
            "Microsoft.SkypeApp",`
            #"Microsoft.StorePurchaseApp",`
            "Microsoft.Wallet",`
            "Microsoft.XboxApp",`
            "Microsoft.XboxGameOverlay",`
            "Microsoft.XboxIdentityProvider",`
            "Microsoft.XboxSpeechToTextOverlay",`
            "Microsoft.ZuneMusic",`
            "Microsoft.ZuneVideo",`
            #"Microsoft.WindowsStore",`
            "microsoft.windowscommunicationsapps",`
            "Microsoft.WindowsPhone",`
            "Microsoft.Office.Sway",`
            "Microsoft.ConnectivityStore",`
            "Microsoft.CommsPhone",`
            "Microsoft.BingFinance"

ForEach ($app in $AppsList){
    Remove-AppxProvisionedPackage -Online -PackageName $app
}