整个脚本

整个脚本

我为 Windows 10 编写了一个去臃肿脚本,我将整个应用程序列表放入一个数组中,然后循环运行,直到每个应用程序都被删除。遗憾的是,我无法获得我的试着抓工作,并且以下文本块显示在我的写主机我想要隐藏的命令。

Path          : 
Online        : True
RestartNeeded : False

整个脚本

<#
This script de-bloats unwanted apps from Windows 10.
To keep certain apps and prevent them from being moved 
insert a '#' at the beginning of the line 
and it will be skipped.
#>

Clear-Host
Write-Host "Running Remove bloatware apps from Windows 10..."
Start-Sleep -s 2

IF ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ) {
    Write-Host "Administration privileges have been granted.`n"
    Start-Sleep -s 2
    Clear-Host
} ELSE {
    Write-Host "Requesting administration privileges..."
    Start-Sleep -s 2
    Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}

# Apps
Write-Host "Removing bloatware apps...`n"
Start-Sleep -s 2

$AppNames = @(
    "Microsoft.BingWeather"
    #"Microsoft.DesktopAppInstaller"
    "Microsoft.GetHelp"
    "Microsoft.Getstarted"
    #"Microsoft.HEIFImageExtension"
    "Microsoft.Messaging"
    "Microsoft.Microsoft3DViewer"
    "Microsoft.MicrosoftOfficeHub"
    "Microsoft.MicrosoftSolitaireCollection"
    #"Microsoft.MicrosoftStickyNotes"
    "Microsoft.MixedReality.Portal"
    #"Microsoft.MSPaint"
    "Microsoft.Office.OneNote"
    "Microsoft.OneConnect"
    "Microsoft.People"
    "Microsoft.Print3D"
    "Microsoft.ScreenSketch"
    #"Microsoft.SkypeApp"
    #"Microsoft.StorePurchaseApp"
    #"Microsoft.VP9VideoExtensions"
    "Microsoft.Wallet"
    #"Microsoft.WebMediaExtensions"
    #"Microsoft.WebpImageExtension"
    #"Microsoft.Windows.Photos"
    #"Microsoft.WindowsAlarms"
    #"Microsoft.WindowsCalculator"
    #"Microsoft.WindowsCamera"
    "microsoft.windowscommunicationsapps"
    "Microsoft.WindowsFeedbackHub"
    #"Microsoft.WindowsMaps"
    #"Microsoft.WindowsSoundRecorder"
    #"Microsoft.WindowsStore"
    "Microsoft.Xbox.TCUI"
    "Microsoft.XboxApp"
    "Microsoft.XboxGameOverlay"
    "Microsoft.XboxGamingOverlay"
    "Microsoft.XboxIdentityProvider"
    "Microsoft.XboxSpeechToTextOverlay"
    "Microsoft.YourPhone"
    "Microsoft.ZuneMusic"
    "Microsoft.ZuneVideo"
)

foreach ($app in $AppNames) {
    Write-Host "Attempting to remove $app... " #-NoNewline

    Try{
        Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage
        # | Select-Object Name -ExpandProperty Name
        Get-AppXProvisionedPackage -Online | Where-Object DisplayName -EQ $app | Remove-AppxProvisionedPackage -Online -AllUsers
        # | Select-Object DisplayName -ExpandProperty DisplayName
        Write-Host "Done" -ForegroundColor Green -ErrorAction Stop
    }
    Catch{
        Write-Host "Failed" -ForegroundColor Red
    }
}

Write-Host "Apps removed"
Write-Host "A total of $($error.count) errors were found`n"
Start-Sleep -s 2

# Restore all apps
#Get-AppxPackage -AllUsers | Foreach {
#    Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"
#}

答案1

Get-AppxPackage在and行的末尾Get-AppXProvisionedPackage,添加一个| Out-Null

所以这

Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage

变成

Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage | Out-Null

更多信息出零

相关内容