简体   繁体   English

Powershell在启动时运行但未执行Remove-AppxPackage

[英]Powershell is running at startup but not executing Remove-AppxPackage

Executing a Powershell script at startup to strip out some of the bloat which comes with Windows 10. It includes a check to see if it has already executed, which creates a flag file (so I know the script is running). 在启动时执行Powershell脚本以消除Windows 10附带的一些膨胀。它包括检查它是否已经执行,这将创建一个标志文件(所以我知道脚本正在运行)。 However, the uninstall commands are not running (they run fine manually). 但是,卸载命令未运行(它们可以手动运行)。

Hosts are running Windows 10 Pro. 主机正在运行Windows 10 Pro。 Script is being delivered via GPO; 脚本正在通过GPO提供; being applied ok as evidenced by the script running. 正如运行脚本所证明的那样正确应用。

$DestinationFile = "C:\BloatFlag.txt"
if (Test-Path $DestinationFile) {

echo "Already Done"

} else {

Get-AppXPackage Microsoft.Microsoft3DViewer | Remove-AppXPackage
Get-AppXPackage DellInc.DellSupportAssistforPCs | Remove-AppXPackage
Get-AppXPackage DellInc.DellCommandUpdate | Remove-AppXPackage
# and the list goes on

echo "ONLY DELETE THIS FILE IF YOU REQUIRE TO RUN THE BLOAT REMOVAL SCRIPT AGAIN" > "C:\BloatFlag.txt"

}
  • BloatFlag.txt is created when checking C:\\ . 检查C:\\时创建BloatFlag.txt。
  • None of the listed software has been removed 所有列出的软件均未被删除

I expected the apps would have been removed if the code reached creation of the text file. 我预计如果代码到达文本文件的创建,应用程序将被删除。

Maybe. 也许。 Maybe not. 也许不吧。 Here is what I mean... 这就是我的意思......

a) If Get-AppXPackage doesn't return anything, Remove-AppXPackage won't delete anything, and the marker file will still be created. a)如果Get-AppXPackage没有返回任何内容,则Remove-AppXPackage不会删除任何内容,仍会创建标记文件。

b) If either statement throws an exception, from what you've coded, that won't stop script execution and the marker file will be created. b)如果任何一个语句根据您编码的内容抛出异常,则不会停止脚本执行,并且将创建标记文件。 For example, stick the following in a file and run it. 例如,将以下内容保存在文件中并运行它。 You'll see Remove-AppXPackage throw an exception, but thinger.txt still gets created. 您将看到Remove-AppXPackage抛出异常,但仍会创建thinger.txt

Remove-AppXPackage xyz
write-output 'test' > thinger.txt

When the script executes during the boot/login/whatever process, does it run as the user who's app-packages are being removed, or does it run under a different user's context? 当脚本在引导/登录/任何进程期间执行时,它是作为正在删除app-packages的用户运行,还是在不同用户的上下文下运行? If the latter, the user needs to be an admin (running under elevated permissions) to delete app-packages from another user's profile. 如果是后者,则用户需要是管理员(在提升的权限下运行)才能从其他用户的配置文件中删除app-packages。 if you're not sure, add a whoami to the output in the marker file you're creating. 如果您不确定,请在您正在创建的标记文件中为输出添加whoami

Just a side note, I vaguely recall people Remove-AppxPackage and Remove-ProvisionedAppxPackage . 只是旁注,我模糊地回忆起人们Remove-AppxPackageRemove-ProvisionedAppxPackage The first removed the package for a given local user. 第一个删除了给定本地用户的包。 The second removes the package from the machine, so new users won't have the package installed. 第二个从计算机中删除程序包,因此新用户将不会安装该程序包。 It wouldn't surprise me if you needed to run Remove-ProvisionedAppxPackage with elevated permissions, but I don't see that in the cmdlet's documentation. 如果您需要使用提升的权限运行Remove-ProvisionedAppxPackage ,我不会感到惊讶,但我没有在cmdlet的文档中看到它。

Remove-Appxpackage is largely disabled these days, unless you want to do some sqlite database manipulation. 除非你想做一些sqlite数据库操作,否则这些天大部分时间都禁用了Remove-Appxpackage。 https://superuser.com/questions/1115801/unable-to-uninstall-universal-apps-through-powershell https://superuser.com/questions/1115801/unable-to-uninstall-universal-apps-through-powershell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 所有用户的 Remove-AppxPackage - Remove-AppxPackage for all users 控制台中的Remove-AppxPackage嘈杂 - Remove-AppxPackage noisy in the console C# - PowerShell 对象成功执行 Remove-AppxPackage 但无法从其他用户删除应用程序 - C# - PowerShell object execute Remove-AppxPackage successfully but unable to remove application from another user 如何创建由批处理命令执行的Powershell脚本Remove-appxpackage Windows内置应用程序? - How to Create Powershell Script Remove-appxpackage Windows Built-in App Executed by Batch Command? Remove-AppxPackage 失败,错误为 0x80070002 - Remove-AppxPackage fails with error 0x80070002 使用 Get-AppxPackage/Remove-AppxPackage 将包排除(foreach-notlike)列入白名单 - Whitelisted package exclusion (foreach-notlike) with Get-AppxPackage/Remove-AppxPackage Get-Help 显示 Remove-AppxPackage 的 `-AllUser` 参数,那么为什么 cmdlet 不接受它呢? - Get-Help shows `-AllUser` parameter for Remove-AppxPackage, so why won't the cmdlet won't accept it? 消除启动时的Powershell错误 - Remove Powershell error on startup 使用C#调用Powershell Cmd进行Add-AppxPackage Remove-AppPackage - Invoke Powershell Cmd for Add-AppxPackage Remove-AppPackage using C# 在计算机启动时运行 powershell 网络脚本将失败 - Running powershell network script at computer startup will fail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM