powershell - For loop med DISM for at fjerne uønskede programmer i Windows 10

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg har problemer med nedenstående script. Selv om det siger, at det lykkes i løbetid, er applikationerne stadig til stede i operativsystemet. DISM logfiler er heller ikke nyttige.


# 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:$\_}

Bedste reference


Sådan fjerner du apps fra den aktuelle bruger:


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


Hvis du vil fjerne apps fra nye brugere, der logger ind på en systembrug, men ikke fjerner fra eksisterende brugere:


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

Andre referencer 1


Jeg bruger Remove-AppxProvisionedPackage i stedet for 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
}