Author Posts

May 26, 2017 at 6:58 pm

I am trying to learn powershell my book has a lab and i can not get my code to execute without an error.
here is the error, I can't figure out what i am doing wrong any help would be appreciated.
Elseif : The term 'Elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Administrator\Scripts\Get-Inventorya.ps1:39 char:1
+ Elseif ( $menu_choice -eq "X" )
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (Elseif:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
##################################################################################################################################
Here is the code I have
#################################################################################################################################
#Initialization
# This section contains variable declarations and assignments
$menu_choice = “”
$menu = @”
Inventory System Menu
===================================================
A – Installed Software Inventory
B – Basic Hardware Inventory
X – Exit
===================================================
“@

#Main Body
#This section contains the code that implements that main function of the script.#
$menu
$menu_choice = Read-Host -Prompt “Choose a menu option”
$sure = Read-Host -Prompt “Are you sure you want to exit? (Y)”
if ($sure -eq “Y”)
{
Write-Host “This I can do.”
Write-Host “Exiting…”
}
Else
{
Write-Host "Not Exiting :)"
}
ElseIf ( $menu_choice -eq “X” )
{
$sure = Read-Host -prompt "are you sure you want to exit? (Y)"
{
Write-Host “This I can do.”
Write-Host “Exiting…”
}
Else
{
Write-host "Not Exiting :)"
}
}

May 26, 2017 at 7:16 pm

The last post did, I didn't see it had to refresh.