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"
}