BGONZALES_ASH
Contributor
Contributor

Hello.. can someone please help me out on the below error or post the script for the Shutdown Power Off VM from a text file so I can see where my mistakes may be.. I have the below, but the VM is not being found.. Thank you!!

ERROR

Get-VM : 3/23/2018 9:08:44 AM   Get-VM          VM with name ''testfailover'' was not found using the specified filter(s).

At C:\temp\new_test.ps1:3 char:11

+     $vm = Get-VM -Name $vmName

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

    + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Stop-VM : Cannot validate argument on parameter 'VM'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At C:\temp\new_test.ps1:7 char:21

+         Stop-VM -VM $vm -confirm:$false

+                     ~~~

    + CategoryInfo          : InvalidData: (:) [Stop-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.StopVM

SCRIPT

foreach($vmName in (Get-Content -Path c:\temp\vm.txt)){

   $vm = Get-VM -Name $vmName

   if($vm.Guest.State -eq "Running"){

  Shutdown-VMGuest -VM $vm -Confirm:$false}

   else{ 

   Stop-VM -VM $vm -confirm:$false

   write-host "Powering Down VM..."

  Count 20

   write-host "Adjusting Compute..."

   set-vm -numCPU 2 -memorygb 4 -confirm:$false

   start-vm -confirm:$false

  Count 120

   write-host "Powering On Server..."


  export "c:\temp\results.csv"}

  }

Reply
0 Kudos