8 Replies Latest reply on Feb 17, 2017 5:46 AM by virtmoos

    simple script issue with datastores

    virtmoos Lurker

      hello,

      i'm new to powercli scripting and i managed to write simple script to create punch of vms with same configuration.

      the strange this that this script sometime run great and some time partially run in mean of if i for example try to create 3 new vms it may create one and fail in the other two vms

      my script is as the following:

      $vcenter="10.200.12.150"

      $vc_user="administrator@vsphere.local"

       

       

       

       

       

      $vmcount= read-host "Enter required quantity of VMs:"

      $ds="T3-Data"

      $disk="15"

      $diskformat="thin"

      $memory="2"

      $cpu="2"

      $cluster="CLS01"

      $folder="RHCSA"

      $guestid="rhel6_64Guest"

      $vm_pref="RHCLIENT"

       

       

      write-host "Connecting to vcenter" -foreground green

      connect-viserver $vcenter -user $vc_user -password $pass  -warningaction 0

      1..$vmcount | foreach {

      $y="{0:D2}" -f $_

      $vmname= $vm_pref + $y

      write-host "Creation of new VMs $vmname initiated" -foreground green

       

      $vmhost = get-cluster $cluster | get-vmhost -state connected | get-random

      new-vm -name $vmname -vmhost $vmhost -Datastore $ds -Location RHCSA -cd -guestid $guestid -memorygb $memory -numcpu $cpu -diskgb $disk -diskstorageformat $diskformat

      Start-Sleep 5

      get-vm $vmname | start-vm

      }

      disconnect-viserver -server * -force -confirm:$false

       

      now the creation fails withe following error:

      Creation of new VMs RHCLIENT02 initiated

      new-vm : 2/15/2017 9:21:58 AM    New-VM        Specified datastore 'T3-Data'

      is invalid for the operation.

      At E:\Scripts\createvms.ps1:25 char:1

      + new-vm -name $vmname -vmhost $vmhost -Datastore $ds -Location RHCSA -cd

      -guestid ...

       

       

       

      please am really in need for your support

        • 1. Re: simple script issue with datastores
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Are you sure that datastore is reachable from all the ESXi nodes in the cluster?

          Do

           

          Get-Datastore -Name T3-Data | Get-VMHost

           

          and

           

          Get-Cluster -Name CLS01 | Get-VMHost 

           

          show the same ESXi nodes?

          • 2. Re: simple script issue with datastores
            virtmoos Lurker

            hello lucd,

             

            it's reachable from my both hosts, and I'm already have vms on this datastore. also as mentioned the script sometimes work and sometimes partially not working as it could create a vm and fail in the rest.

            one thing I tried failed too  I did sleep-start 5 after foreach loops.

             

            thanks and appreciate your support

            • 3. Re: simple script issue with datastores
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Another possibility might be that you have some "ghost" folders on that datastore.

              In other words, a folder with the name of the VM you are trying to create.

              Can you check with the Browse Files option in the Web Client?

              • 4. Re: simple script issue with datastores
                virtmoos Lurker

                i did check for ghost folder name and even i changed the vm name to avoid the issue but no luck the problem still exist.

                attached script output

                • 5. Re: simple script issue with datastores
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  The output seems to indicate that datastore 'FN_OS'  is not found.

                  Are you still using the original script from earlier in this thread?

                  Or can you attach the newer version?

                  • 6. Re: simple script issue with datastores
                    virtmoos Lurker

                    still the same script just changed the $ds="FN_OS" another datastore i have as the following

                    Name                               FreeSpaceGB      CapacityGB

                    ----                               -----------      ----------

                    TIER_I_DS                              780.404         838.250

                    TIER_II_DS                             147.476         465.500

                    datastore1                               0.483           0.500

                    datastore1 (1)                           0.483           0.500

                    FN_OS                                  225.430         249.500

                    T1_CRITICAL                             48.550          49.500

                    T2-Data                                 98.550          99.500

                    T3-Data                                 24.018          72.750

                     

                    the attached output shows that it successfully created 2 vms and failed in the last one on the same datastore.

                    • 7. Re: simple script issue with datastores
                      LucD Guru
                      User ModeratorsvExpertCommunity Warriors

                      Are you sure there is sufficient free space on that datastore to accomdate these VMs?

                      • 8. Re: simple script issue with datastores
                        virtmoos Lurker

                        yes, there is enough space for the vms