Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WMI删除程序后的输出-Powershell_Powershell - Fatal编程技术网

使用WMI删除程序后的输出-Powershell

使用WMI删除程序后的输出-Powershell,powershell,Powershell,我正在使用WMI远程卸载软件,删除该软件工作正常。我正在努力解决的是使用结果(成功与否)给出一个简单的输出消息,而不是命令的正常输出。我通常使用$lastexitcode进行此操作,但无论命令是否成功,它都会运行到我的成功卸载消息。以下是我试图使用的: $app = Get-WmiObject Win32_Product -ComputerName "$computer" | where { $_.vendor -eq "APN, LLC" } $app.Uninstall() if ($las

我正在使用WMI远程卸载软件,删除该软件工作正常。我正在努力解决的是使用结果(成功与否)给出一个简单的输出消息,而不是命令的正常输出。我通常使用$lastexitcode进行此操作,但无论命令是否成功,它都会运行到我的成功卸载消息。以下是我试图使用的:

$app = Get-WmiObject Win32_Product -ComputerName "$computer" | where { $_.vendor -eq "APN, LLC" }
$app.Uninstall()
if ($lastexitcode -eq 0)
        {
        write-host -ForegroundColor Green "Programm Successfully Removed"
        }    
    else
        {
        write-host -ForegroundColor red "There was a problem uninstalling the program"
        }
当我将操作的输出保留在其上时,它将返回:

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :
我想我可以用ReturnValue做点什么,但我不确定如何做。任何帮助都将不胜感激


编辑:由于Bruce的回答,解决方案如下:

$app = Get-WmiObject Win32_Product -ComputerName "$computer" | where { $_.vendor -eq "APN, LLC" }
$appuninstall = $app.Uninstall()
if ($appuninstall.returnvalue -eq 0)
        {
        write-host -ForegroundColor Green "Programm Successfully Removed"
        }    
    else
        {
        write-host -ForegroundColor red "There was a problem uninstalling the program"
        }

$LastExitCode
仅在运行本机命令(external.exes)时设置。在代码中,您希望在变量中捕获调用
Uninstall()
的结果,然后在
if
语句中使用该对象的返回代码属性。

仅在运行本机命令(external.exes)时设置。在代码中,您希望在变量中捕获调用
Uninstall()
的结果,然后在
if
语句中使用该对象的返回代码属性