检查命令是否已成功运行 [英] Check if a command has run successfully
本文介绍了检查命令是否已成功运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已尝试在if语句中包含以下内容,以便在成功时执行另一个命令:
I've tried enclosing the following in an if statement so I can execute another command if this succeeds:
Get-WmiObject -Class Win32_Share -ComputerName $Server.name -Credential $credentials -Filter "Description='Default share'" | Foreach-Object {
$Localdrives += $_.Path
但我不能弄清楚该怎么做。我甚至尝试创建一个函数,但我无法弄清楚如何检查函数是否已成功完成。
but I can't figure out how to do it. I even tried creating a function but I couldn't figure out how to check if the function had successfully completed either.
推荐答案
你可以尝试:
$res = get-WmiObject -Class Win32_Share -Filter "Description='Default share'"
if ($res -ne $null)
{
foreach ($drv in $res)
{
$Localdrives += $drv.Path
}
}
else
{
# your error
}
这篇关于检查命令是否已成功运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文