none
How to code this powershell? RRS feed

  • Question

  • I would like to know on how to handle error if $temp = NULL on if statement

    $temp = "I go to school by bus"

    If $temp.Substring(0,4) -eq "abcd" { Write-host "Pass"}


    Does anyone have any suggestions?
    Thanks in advance for any suggestions




    Thanks in advance for any suggestions

    Thursday, March 22, 2018 6:18 AM

Answers

  • If($temp -is [string]){
         # process temp
    }else{
         Write-Host 'variable is not a string
    }


    \_(ツ)_/

    • Proposed as answer by tonibert Thursday, March 22, 2018 6:32 AM
    • Marked as answer by oemMicrosoft Thursday, March 22, 2018 11:17 AM
    Thursday, March 22, 2018 6:24 AM

All replies

  • If($temp -is [string]){
         # process temp
    }else{
         Write-Host 'variable is not a string
    }


    \_(ツ)_/

    • Proposed as answer by tonibert Thursday, March 22, 2018 6:32 AM
    • Marked as answer by oemMicrosoft Thursday, March 22, 2018 11:17 AM
    Thursday, March 22, 2018 6:24 AM
  • Thank you very much for suggestions (^v^)

    Thanks in advance for any suggestions

    Thursday, March 22, 2018 11:17 AM