powershell - 使用 test-path 的结果执行 powershell 命令
问题描述
如果系统上不存在文件/文件夹,则希望执行将卸载应用程序并清除一些注册表项的 powershell 命令。
目前正在看这样的东西:
if(!(test-path “c:\Windows\mdm” )
{
$productdetails=(Get-WmiObject -Query “Select IdentifyingNumber from win32_product where name = ‘Tesapp’“).identifyingnumber
$proc=(Start-Process -FilePath “msiexec.exe” -ArgumentList “/x $productdetails /qn /l*v c:\temp\Uninstall-testapp.log” -Wait -PassThru).ExitCode
if (!($proc -eq 0 -or $proc -eq 3010))
{
exit(1)
}
$RegKey=“HKLM:\SOFTWARE\Microsoft\TestAppManagement\S-0-0-00-0000000000-0000000000-000000000-000\MSI\{0}” -f $productdetails
if(test-path $RegKey)
{
$op= Get-Item $RegKey | Out-File “c:\windows\temp\TestApp_Reg_backup.reg” -Force
$op= Remove-Item $RegKey -Force
}
}
有趣的是,如果我运行测试路径,它将返回预期的 false,或者如果单独运行应用程序卸载/注册清除,它将按预期工作 - 但是我不能一起运行它们。
我假设我正在犯某种语法/基本逻辑错误?
解决方案
推荐阅读
- pyspark - 不匹配的输入“何时”Pyspark 但语句工作时的其他情况
- php - Laravel 导入错误。应用程序在我的电脑上运行,但在同事的电脑上崩溃
- passenger - Rails 6 Bcrypt 与生产中的乘客错误
- flutter - 当我点击搜索按钮时,它会显示带有一些脏错误的红屏
- api - Firefox - 编辑和重新发送格式?
- firebase - ref.push().key & ref.child (类型不匹配)
- html - 无法居中容器
- html - 更改 CSS 样式
- python-3.x - python中受保护变量和公共变量有什么区别
- apache-kafka - 如何测试 WindowStore 保留期?