Hi,
I am unable to exit or continue from script after validation
Please help
$vms = Read-Host "Enter VM Name "
if ($vms | where $_.'VM PowerState' -eq 'PoweredOn') {Exit}
Write-Host "Cannot Continue When VM is Powered On" -ForegroundColor Red
else
{
Write-Host
$newsizeGB = Read-Host "Enter New Disk Size In GB "
}
Error
Where-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At D:\myreports\vm1.ps1:146 char:18
+ if ($vms | where $_.'VM PowerState' -eq 'PoweredOn') {Exit}
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Where-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WhereObjectCommand
Cannot Continue When VM is Powered On
else : The term 'else' 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 D:\myreports\vm1.ps1:148 char:1
+ else
+ ~~~~
+ CategoryInfo : ObjectNotFound: (else:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException