none
Abort function and throw error?

    Question

  • Hi,

    I have this function (with a try catch) which sees if a machine has an E-drive, if not checks if vm and if vm adds extra drive.

    Now I would like it to end the function and throw "no e-drive" when it is a physical machine, how do I do that in an if then construction? If I do it with the EXIT it will just close the script, should I use a throw here? Won't it then continue the function or is it really a terminating error?

    try{


        #CHECK FOR E-DRIVE IF NOT EXIST CHECK IF VIRTUAL AND ADD DISK, IF PHYSICAL ABORT AND THROW ERROR
        if (!(invoke-command -ScriptBlock { Test-Path E: } -ComputerName $computername))
       {}
         Invoke-Command -ScriptBlock $sb -ComputerName $computername

          }
        }#EndIf
        else { Throw "E-drive does not exist"}


      }#EndTry
      catch
      {

      }#EndCatch


    }

                       

    Jan Hoedt

    Monday, March 20, 2017 10:17 AM

All replies