Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

powershell try catch connect-viserver

  try {
    Write-debug "Connecting to vCenter, please wait.."
    #Connect to vCenter
    Connect-ViServer -server $vcInfo.server -credential $creds -ErrorAction Stop | Out-Null
  }
  catch [Exception]{
    $status = 1
    $exception = $_.Exception
    Write-debug "Could not connect to vCenter"
    $msg = "Could not connect to vCenter"
    LogSysTo-File $msg $status $env:username $exception.message
  }
Source by zeleskitech.com #
 
PREVIOUS NEXT
Tagged: #powershell #catch
ADD COMMENT
Topic
Name
3+7 =