I have written follow script with if condition but when I choose 3 it shows many error although I want it just show "Insert correct digit" "Please choose an Option to apply configurations:" "1- Sel...
See more...
I have written follow script with if condition but when I choose 3 it shows many error although I want it just show "Insert correct digit" "Please choose an Option to apply configurations:" "1- Select Host" "2- Apply on All ESXi Host" $options= Read-Host "Enter your Number 1/2" if ( 1 -eq $options ) { $hostname= read-host "Please enter your hostname" Write-Output "esxi-7.account-auto-unlock-time" | Green Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900 } if ( 2 -eq $options ) { Write-Output "6- esxi-7.account-auto-unlock-time" | Green Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900 } else { Write-Output "Insert correct number" } When insert 3 it shows follow error Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At C:\HP server\security.ps1:92 char:14 + Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.kee ... + ~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost Although it just shows Insert correct number