如何创建Powershell脚本删除-appxpackage由批处理命令执行的Windows内置应用程序?

时间:2015-08-27 04:21:34

标签: powershell batch-file cmd

有人可以确认此脚本是否正确。

批量cmd Execute.bat:

@echo off
color d
echo Execute Powershell Script With Administrative Privileges
echo.
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
echo.
timeout /t 5

对于Powerhsell.ps1:

Remove-appxpackage Microsoft.XboxApp_5.6.17000.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.XboxGameCallableUI_1000.10240.16384.0_neutral_neutral_cw5n1h2txyewy

Remove-appxpackage Microsoft.XboxIdentityProvider_1000.10240.16384.0_neutral_neutral_cw5n1h2txyewy

Remove-appxpackage Windows.ContactSupport_10.0.10240.16384_neutral_neutral_cw5n1h2txyewy

Remove-appxpackage Microsoft.BingNews_4.3.193.0_x86__8wekyb3d8bbwe

Remove-appxpackage Microsoft.BingFinance_4.3.193.0_x86__8wekyb3d8bbwe

Remove-appxpackage Microsoft.BingWeather_4.3.193.0_x86__8wekyb3d8bbwe

Remove-appxpackage Microsoft.Getstarted_2.1.9.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.SkypeApp_3.2.1.0_x86__kzf8qxf38zg5c

Remove-appxpackage Microsoft.WindowsPhone_10.1506.20010.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.WindowsMaps_4.1505.50619.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.People_1.10159.0.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.Office.OneNote_17.4201.10091.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.MicrosoftSolitaireCollection_3.1.6103.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.MicrosoftOfficeHub_17.4218.23751.0_x64__8wekyb3d8bbwe

Remove-appxpackage Microsoft.BingSports_4.3.193.0_x86__8wekyb3d8bbwe

Remove-appxpackage Microsoft.Appconnector_1.3.3.0_neutral__8wekyb3d8bbwe

Remove-appxpackage Microsoft.3DBuilder_10.0.0.0_x64__8wekyb3d8bbwe

Remove-appxpackage microsoft.windowscommunicationsapps_17.6002.42251.0_x64__8wekyb3d8bbwe

如何在powershell中添加等待时间?

2 个答案:

答案 0 :(得分:1)

是的,如果脚本位于确切的位置并且与批处理文件具有相同的名称,那么它应该可以工作。我不确定你为什么要在PowerShell中添加等待时间,但是你要找的cmdlet是start-sleep

答案 1 :(得分:0)

您可以将包放在文本文件中并执行此操作:

$packages = Get-Content c:\scripts\packages.txt
Foreach ($package in $packages){
 Remove-appxpackage $package
  Start-Sleep -Seconds 15 #change this as needed
}