Check if a command has run successfully

前端 未结 4 1535
轮回少年
轮回少年 2020-12-05 04:46

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 $Ser         


        
4条回答
  •  孤城傲影
    2020-12-05 05:10

    you can try :

    $res = get-WmiObject -Class Win32_Share -Filter "Description='Default share'"
    if ($res -ne $null)
    {
      foreach ($drv in $res)
      {
        $Localdrives += $drv.Path
      }
    }
    else
    {
      # your error
    }
    

提交回复
热议问题