2 Replies Latest reply on Aug 9, 2019 6:09 AM by ganapa2000

    Check VM validating failing

    ganapa2000 Hot Shot

      Hi,

       

      I am using the below script to validate if the VM exists, if the VM is valid, the script works fine but for invalid VMs, it is not checking nor I am getting the error message which I defined in the script, directly, I am getting error

       

      $report = @()

      $report = Import-Csv ".\VMNotes0.csv"

      foreach ($VMAttrib in $report){

      if (!$VMAttrib) {

      Write-Host "No VM named $VM exists" }

      else

      {Get-VM $VMAttrib.Name | Set-VM -Notes $VMAttrib.Notes -confirm:$false}

      }

       

      Error :

       

      Get-VM : 09-08-2019 17:49:16Get-VM      VM with name 'MyDB10' was not found using the specified filter(s).

      At D:\export\3.ps1:9 char:2

      + {Get-VM $VMAttrib.Name | Set-VM -Notes $VMAttrib.Notes -confirm:$fals ...

      +  ~~~~~~~~~~~~~~~~~~~~~

      + CategoryInfo      : ObjectNotFound: (:) [Get-VM], VimException
      + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM