ElseIf and Else are not recognizable

Welcome Forums General PowerShell Q&A ElseIf and Else are not recognizable

Viewing 1 reply thread
  • Author
    Posts
    • #221493
      Participant
      Topics: 1
      Replies: 1
      Points: 57
      Rank: Member

      I’m trying to perform this script but ElseIf part is not recognizable by PowerShell (The term ‘ElseIf’ is not recognized as the name of a cmdlet, function), where I’m wrong?

      $Yes = "Yes"
      $No = "No"
      $PCNameStatus = Read-Host -Prompt "Yes/No"
      If ($Yes -match $PCNameStatus) {
          $PCNAME = Read-Host -Prompt "Please specify the name you want to assign"
          Rename-Computer -NewName $PCNAME
      }
      
      ElseIf ($No -match $PCNameStatus) {
          Write-Host "It's time to reboot"
          Start-Sleep -Seconds 10
          Restart-Computer
      }
      
      Else {
          Write-Host "The answer wasn't in Yes/No format"
      }
    • #221505
      Participant
      Topics: 1
      Replies: 1
      Points: 57
      Rank: Member

      False alarm. Everything is ok.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.