[英]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"
}
C:\\
. C:\\
时创建BloatFlag.txt。 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-AppxPackage
和Remove-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.