1 2 Previous Next 25 Replies Latest reply on Jun 21, 2018 10:25 AM by LucD

    How to force users to choose only from a list of hosts, datastores, VLANs, etc

    emcclure Enthusiast

      So it seems I'm never done with this script.  I want there to be default answers in some areas, and if a user passes something that's invalid it asks again until they pass a proper bit of info.

       

      $type = Read-Host "Enter Host or Cluster"

      if ($type -eq "Cluster")

      {

      Get-Cluster | Select Name | sort Name | Format-List #Gets a list of clusters in the vCenter#

      $Cluster = Read-Host "Enter Cluster Name"

      $myCluster = Get-Cluster -Name "$Cluster"

      Get-VMHost -Location "$myCluster" -state "Connected" | sort Name | Select Name,ConnectionState,PowerState | Format-Table #Lists the host from the cluster specified earlier#

      }

      else

      {

      Get-VMHost | where {$_.state -eq "Connected"} | sort Name | Select Name,ConnectionState,PowerState | Format-Table

      }

      $vmHost = Read-Host "Enter host name"

      Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS"} | Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} | Out-Default #Lists datastores and capacity#

      $datastore = Read-Host "Enter Datastore Name"

      $myDatastore = Get-DataStore -Name "$datastore"

      $ovfhost = Read-Host "Enter path to OVA/OVF"

      $vmName = Read-Host "Enter a name for the VM"

      $diskStorage = Read-Host "Enter Thin, Thick or EagerZeroedThick for disk format"

      Import-vApp -Source "$ovfhost" -VMHost $vmHost -Location $myCluster -Name "$vmName" -DiskStorageFormat $diskStorage -Datastore $myDatastore #Imports the OVA/OVF into vCenter#

      Sleep 10

      $VMmove = Read-Host "Enter folder to move VM to"

      Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate folder#

      Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {$strClusterName = $_.Parent.Name; Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} #Gets available VLANs from the host#

      $VLAN = Read-Host "Please enter the VLAN name to use"

      $NIC = Get-NetworkAdapter -VM $vmName

       

      So for the first part for $type it defaults to Host which I'm fine with.  After that I get a list of only hosts that are in the Connected state.  I'd like it if someone could just only type a name from the list provided, and if they don't provide one it prompts again.  Same thing would be fore the rest really, for the datastore, disk storage, folder path (hoping they put in a valid path) and VLAN type.  I'm new to all of this and have been googling around, just haven't found what I need yet.

        • 1. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          Did you already consider using Out-GridView?

           

          #Lists the host from the cluster specified earlier

          # User can select one entry and select by <enter>


          $selectEsx = Get-VMHost -Location "Cluster1" -state "Connected" |

            Sort-Object -Property Name |

            Select Name,ConnectionState,PowerState |

            Out-GridView -OutputMode Single


          $selectEsx

          • 2. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
            emcclure Enthusiast

            Hi LucD,

             

            I had not considered that.  I tried changing it, but I'm pretty sure I'm doing something wrong.  I have this now:

             

            $selectEsx = Get-VMHost -Location "$myCluster" -state "Connected" | Sort-Object -Property Name | Select Name,ConnectionState,PowerState | Out-GridView -OutputMode Single #Lists the host from the cluster specified earlier#

            }

            else

            {

            Get-VMHost | where {$_.state -eq "Connected"} | Sort-Object -Property Name | Select Name,ConnectionState,PowerState | Out-GridView -OutputMode Single

            }

            $vmHost = Read-Host "Enter host FQDN name"

            if ($vmHost -eq "Connected")

             

            But if I choose a host in Cluster mode and hit ok on the window it just asks me for the host name.  If I do it in host mode and select the host it inputs the host info into the PowerCLI window, but still asks me for the host name.  Is this really the easiest way to get people to use only what's listed?  I was hoping that whatever I do for the host part I can repeat for the rest of what users need to select.

            • 3. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              You have to replace both parts on the If-Then-Else.

              Something like this for example

               

              $type = "Host","Cluster" | Out-GridView -OutputMode Single

               

              if ($type -eq "Cluster")

              {

                 $cluster = Get-Cluster | Select Name | sort Name | Out-GridView -OutputMode Single

                 $myCluster = Get-Cluster -Name "$Cluster"


                 $vmHost = Get-VMHost -Location "$myCluster" -state "Connected" |

                sort Name |

                Select Name,ConnectionState,PowerState |

                 Out-GridView -OutputMode Single

              }

              else

              {

                 $vmHost = Get-VMHost | where {$_.state -eq "Connected"} |

                sort Name |

                Select Name,ConnectionState,PowerState |

                 Out-GridView -OutputMode Single

              }

               

              $datastore = Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS"} |

                Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,

                 @{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} |

                 Out-GridView -OutputMode Single


              $myDatastore = Get-DataStore -Name "$datastore"

              $ovfhost = Read-Host "Enter path to OVA/OVF"

              $vmName = Read-Host "Enter a name for the VM"


              $diskStorage = "Thin","Thick","EagerZeroedThick" | Out-GridView -OutputMode Single


              $sVapp = @{

                 Source = $ovfhost

                 VMHost = $vmHost

                 Location = $myCluster

                 Name = $vmName

                 DiskStorageFormat = $diskStorage

                 Datastore = $myDatastore

              }

              Import-vApp @sVapp


              Sleep 10


              $VMmove = Read-Host "Enter folder to move VM to"


              Move-VM -VM $vmName -Destination $VMmove


              Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {

                 $strClusterName = $_.Parent.Name

                 $VLAN = Get-VirtualPortGroup $_ |

                 Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} |

                 Out-GridView -OutputMode Single

                 $NIC = Get-NetworkAdapter -VM $vmName

              • 4. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                emcclure Enthusiast

                Hi LucD,

                 

                Here's what I have:

                 

                $type = "Host","Cluster" | Out-GridView -OutputMode Single
                if ($type -eq "Cluster")
                {
                $cluster = Get-Cluster | Select Name | sort Name | Out-GridView -OutputMode Single
                $myCluster = Get-Cluster -Name "$cluster"
                $vmHost = Get-VMHost -Location "$myCluster" -state "Connected" | sort Name | Select Name,ConnectionState,PowerState | Out-GridView -OutputMode Single
                }
                else
                {
                $vmHost = Get-VMHost | where {$_.state -eq "Connected"} | sort Name | Select Name,ConnectionState,PowerState | Out-GridView -OutputMode Single
                }
                $datastore = Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS"} | Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,@{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} | Out-GridView -OutputMode Single #Lists datastores and capacity#

                $myDatastore = Get-DataStore -Name "$datastore"
                $ovfhost = Read-Host "Enter path to OVA/OVF"
                $vmName = Read-Host "Enter a name for the VM"
                $diskStorage = "Thin","Thick","EagerZeroedThick" | Out-GridView -OutputMode Single

                $sVapp = @{
                Source = $ovfhost
                VMHost = $vmHost
                Location = $myCluster
                Name = $vmName
                DiskStorageFormat = $diskStorage
                Datastore = $myDatastore
                }

                Import-vApp @sVapp
                Sleep 10
                $VMmove = Read-Host "Enter folder to move VM to"
                Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate folder#

                Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {$strClusterName = $_.Parent.Name; Get-VirtualPortGroup $_ | Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} | Out-GridView -OutputMode Single #Gets available VLANs from the host#
                $NIC = Get-NetworkAdapter -VM $vmName
                Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "$VLAN" -Confirm:$false #Applies selected VLAN to VM#

                 

                When I choose Cluster I wind up getting this error:

                Get-Cluster : 6/12/2018 8:30:34 AM      Get-Cluster             Cluster with na
                e
                '@{Name=HACluster}' was not found using the specified filter(s).
                At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:11 char:14
                + $myCluster = Get-Cluster -Name "$cluster"
                +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                   utomation.ViCore.Cmdlets.Commands.GetCluster

                Get-VMHost : 6/12/2018 8:30:34 AM       Get-VMHost              VIContainer par
                meter: Could not
                find any of the objects specified by name.
                At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:13 char:11
                + $vmHost = Get-VMHost -Location "$myCluster" -state "Connected" | sort ...
                +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...iner[] Locati
                   on:RuntimePropertyInfo) [Get-VMHost], ObnRecordProcessingFailedException
                    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotF
                   oundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

                Get-Datastore : Cannot validate argument on parameter 'RelatedObject'. The
                argument is null or empty. Provide an argument that is not null or empty, and
                then try the command again.
                At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:19 char:36
                + $datastore = Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS" ...
                +                                    ~~~~~~~
                    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindi
                   ngValidationException
                    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
                   ation.ViCore.Cmdlets.Commands.GetDatastore

                Get-Datastore : 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:\Users\emcclure\Desktop\ImportOVFv3.ps1:21 char:36
                + $myDatastore = Get-DataStore -Name "$datastore"
                +                                    ~~~~~~~~~~~~
                    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindi
                   ngValidationException
                    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
                   ation.ViCore.Cmdlets.Commands.GetDatastore

                 

                And when I choose Host I get this:

                Get-Datastore : Cannot bind parameter 'RelatedObject'. Cannot convert the ""
                value of type "System.Management.Automation.PSCustomObject" to type "VMware.Vim
                Automation.ViCore.Types.V1.RelatedObject.DatastoreRelatedObjectBase".
                At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:19 char:36
                + $datastore = Get-Datastore -VMHost $vmHost | where {$_.type -eq "NFS" ...
                +                                    ~~~~~~~
                    + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], ParameterB
                   indingException
                    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat
                   ion.ViCore.Cmdlets.Commands.GetDatastore

                Get-Datastore : 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:\Users\emcclure\Desktop\ImportOVFv3.ps1:21 char:36
                + $myDatastore = Get-DataStore -Name "$datastore"
                +                                    ~~~~~~~~~~~~
                    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindi
                   ngValidationException
                    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
                   ation.ViCore.Cmdlets.Commands.GetDatastore

                 

                 

                For the cluster I'm prompted for the cluster and select one.  Same thing for the host, but after selecting either and hitting OK I wind up with these errors.  Did I miss something?

                • 5. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  My bad, in there the script feeds objects coming from a Select-Object into the Out-GridView.

                  To refer to the selected cluster, the script needs to specify the Name property.

                   

                  Try like this

                   

                  #Lists the host from the cluster specified earlier#

                  # User can select one entry and select by <enter>


                  $selectEsx = Get-VMHost -Location "Cluster1" -state "Connected" |

                  Sort-Object -Property Name |

                  Select Name,ConnectionState,PowerState |

                  Out-GridView -OutputMode Single


                  $selectEsx

                  $type = "Host","Cluster" | Out-GridView -OutputMode Single


                  if ($type -eq "Cluster")

                  {

                     $cluster = Get-Cluster | Select Name | sort Name | Out-GridView -OutputMode Single

                     $myCluster = Get-Cluster -Name $cluster.Name


                     $vmHost = Get-VMHost -Location $myCluster -state "Connected" |

                    sort Name |

                    Select Name,ConnectionState,PowerState |

                     Out-GridView -OutputMode Single

                  }

                  else

                  {

                     $vmHost = Get-VMHost | where {$_.state -eq "Connected"} |

                    sort Name |

                    Select Name,ConnectionState,PowerState |

                     Out-GridView -OutputMode Single

                  }


                  $datastore = Get-Datastore -VMHost $vmHost.Name | where {$_.type -eq "NFS"} |

                    Select @{N="Cluster";E={$cluster.Name}},Name,CapacityGB,FreespaceGB,

                     @{N='UsedSpace';E={$_.FreeSpaceGB/$_.CapacityGB*100}} |

                     Out-GridView -OutputMode Single


                  $myDatastore = Get-DataStore -Name $datastore.Name

                  $ovfhost = Read-Host "Enter path to OVA/OVF"

                  $vmName = Read-Host "Enter a name for the VM"


                  $diskStorage = "Thin","Thick","EagerZeroedThick" | Out-GridView -OutputMode Single


                  $sVapp = @{

                     Source = $ovfhost

                     VMHost = $vmHost.Name

                     Location = $myCluster

                     Name = $vmName

                     DiskStorageFormat = $diskStorage

                     Datastore = $myDatastore

                  }

                  Import-vApp @sVapp


                  Sleep 10


                  $VMmove = Read-Host "Enter folder to move VM to"


                  Move-VM -VM $vmName -Destination $VMmove


                  Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-Object {

                     $strClusterName = $_.Parent.Name

                     $VLAN = Get-VirtualPortGroup $_ |

                     Select-Object @{N="Cluster";E={$strClusterName}},Name,VLanId} |

                     Out-GridView -OutputMode Single

                     $NIC = Get-NetworkAdapter -VM $vmName

                  • 6. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                    emcclure Enthusiast

                    Hi LucD,

                     

                    That works a lot better.  I had to remove this line from the beginning:

                    $selectEsx = Get-VMHost -Location "Cluster1" -state "Connected" |

                    Sort-Object -Property Name |

                    Select Name,ConnectionState,PowerState |

                    Out-GridView -OutputMode Single

                     

                    As it prompted for the hosts in the cluster I had specified, and then when the script continued it prompted me for Host or Cluster again.  I chose Cluster initially and after it imported the OVA and then moved it to the folder it specified I wound up getting this:

                    Get-Cluster : 6/12/2018 9:15:51 AM      Get-Cluster             Cluster with nam
                    e
                    '@{Name=HACluster}' was not found using the specified filter(s).
                    At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:43 char:1
                    + Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-O ...
                    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                        + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                       utomation.ViCore.Cmdlets.Commands.GetCluster

                    Get-VMHost : 6/12/2018 9:15:51 AM       Get-VMHost              VMHost with name

                    '@{Name=intdomain1.beaqa.lab; ConnectionState=Connected;
                    PowerState=PoweredOn}' was not found using the specified filter(s).
                    At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:43 char:32
                    + Get-Cluster -Name "$Cluster" | Get-VMHost -Name "$vmHost" | Foreach-O ...
                    +                                ~~~~~~~~~~~~~~~~~~~~~~~~~~
                        + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException
                        + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                       utomation.ViCore.Cmdlets.Commands.GetVMHost

                     

                    But then after that it just kept the VLAN the OVA had on it initially and then completed the rest of the script, so it wound up failing on the NIC portion.

                     

                    When I tried using host I got this:

                    Import-VApp : Cannot validate argument on parameter 'Location'. The argument

                    is null or empty. Provide an argument that is not null or empty, and then try

                    the command again.

                    At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:38 char:13

                    + Import-vApp @sVapp

                    +             ~~~~~~

                        + CategoryInfo          : InvalidData: (:) [Import-VApp], ParameterBinding

                       ValidationException

                        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

                       ation.ViCore.Cmdlets.Commands.ImportVApp

                     

                    At this point I had been able to choose the host, specify the datastore, choose disk provisioning, path to the OVA and provide a name, but then I got the above.  It's now prompting me to enter a folder to move the VM to, but it did not import.

                    • 7. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                      LucD Guru
                      Community WarriorsUser ModeratorsvExpert

                      Oops, those lines were leftover from a previous version.
                      They shall be removed.


                      The $myCluster varaiable is only populated when you pick Cluster in the beginning, not when you pick Host.

                      What should be in Location when you picked a Host in the beginning?
                      Should that be the cluster in which the host is located?

                      If yes, you could do

                       

                       

                      $type = "Host","Cluster" | Out-GridView -OutputMode Single

                       


                      if ($type -eq "Cluster")

                      {

                         $cluster = Get-Cluster | Select Name | sort Name | Out-GridView -OutputMode Single

                         $myCluster = Get-Cluster -Name $cluster.Name


                         $vmHost = Get-VMHost -Location $myCluster -state "Connected" |

                        sort Name |

                        Select Name,ConnectionState,PowerState |

                         Out-GridView -OutputMode Single

                      }

                      else

                      {

                         $vmHost = Get-VMHost | where {$_.state -eq "Connected"} |

                        sort Name |

                        Select Name,ConnectionState,PowerState |

                         Out-GridView -OutputMode Single

                         $myCluster = Get-Cluster -VMHost $vmHost.Name                                               # <== This line added

                      }

                      • 8. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                        emcclure Enthusiast

                        Hmm seems better, but I'm still getting some errors for some reason.

                         

                        I got this one after specifying the folder to move to:

                        Get-Cluster : 6/12/2018 11:21:23 AM     Get-Cluster             Cluster with nam
                        e
                        '@{Name=HACluster}' was not found using the specified filter(s).
                        At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:1
                        + Get-Cluster -Name "$cluster" | Get-VMHost -Name "$vmHost" | Foreach-O ...
                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                            + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                           utomation.ViCore.Cmdlets.Commands.GetCluster

                        Get-VMHost : 6/12/2018 11:21:23 AM      Get-VMHost              VMHost with name

                        '@{Name=isecpod17.beaqa.lab; ConnectionState=Connected; PowerState=PoweredOn}'
                        was not found using the specified filter(s).
                        At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:32
                        + Get-Cluster -Name "$cluster" | Get-VMHost -Name "$vmHost" | Foreach-O ...
                        +                                ~~~~~~~~~~~~~~~~~~~~~~~~~~
                            + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException
                            + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                           utomation.ViCore.Cmdlets.Commands.GetVMHost

                         

                        And of course that broke it where I wasn't able to change the VLAN.  I then got another error when it was getting ready to modify the vmx and then power it on:

                         

                        Get-VM : 6/12/2018 11:21:27 AM  Get-VM          VM with name '@{Name=EN-2K16Dx64

                        ;

                        Powerstate=PoweredOff}' was not found using the specified filter(s).

                        At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:49 char:1

                        + Get-VM -Name $vmName | New-AdvancedSetting -Name "isolation.tools.gue ...

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

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

                            + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA

                           utomation.ViCore.Cmdlets.Commands.GetVM

                        • 9. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

                          I suspect we might not be looking at the same code anymore.

                          That error message lists a line I don't see in my last version of the script.

                           

                          Perhaps you could attach a file with your current version?

                          • 10. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                            emcclure Enthusiast

                            Hi LucD,

                             

                            Here's a copy of what I'm running now.  I think I added a couple things to it, like near the bottom it says $VMname.Name, which before it was just $VMname, but was reporting the errors I had earlier.  That didn't seem to make an improvement either.  I wound up getting a some new errors:

                            WARNING: The size of the file '2k16x64S_disk0.vmdk' is 4387437056 bytes where
                            12977371648 bytes is expected.
                            Import-vApp : 6/13/2018 8:24:26 AM      Import-VApp             Cannot be less t
                            han zero
                            Parameter name: value
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:36 char:1
                            + Import-vApp @sVapp
                            + ~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : NotSpecified: (:) [Import-VApp], ViError
                                + FullyQualifiedErrorId : Client20_NfcLease_RunNfcTask_Error,VMware.VimAut
                               omation.ViCore.Cmdlets.Commands.ImportVApp

                            Enter folder to move VM to: ForOVA
                            Move-VM : 6/13/2018 8:25:31 AM  Move-VM         Could not find VirtualMachine wi
                            th
                            name 'ImportTest'.
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:39 char:1
                            + Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate ...
                            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (ImportTest:String) [Move-VM], V
                               imException
                                + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNo
                               tFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

                            Move-VM : 6/13/2018 8:25:31 AM  Move-VM         Value cannot be found for the
                            mandatory parameter VM
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:39 char:1
                            + Move-VM -VM $vmName -Destination $VMmove #Moves VM to the appropriate ...
                            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException
                                + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
                               n.ViCore.Cmdlets.Commands.MoveVM

                            Get-Cluster : 6/13/2018 8:25:31 AM      Get-Cluster             Cluster with nam
                            e
                            '@{Name=HACluster}.Name' was not found using the specified filter(s).
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:1
                            + Get-Cluster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | ...
                            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                               utomation.ViCore.Cmdlets.Commands.GetCluster

                            Get-VMHost : 6/13/2018 8:25:31 AM       Get-VMHost              VMHost with name

                            '@{Name=isecpod17.beaqa.lab; ConnectionState=Connected;
                            PowerState=PoweredOn}.Name' was not found using the specified filter(s).

                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:37
                            + ... uster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | Forea ...
                            +                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException
                                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                               utomation.ViCore.Cmdlets.Commands.GetVMHost

                            Get-NetworkAdapter : 6/13/2018 8:25:35 AM       Get-NetworkAdapter
                            Could not find
                            VirtualMachine with name 'ImportTest'.

                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:42 char:8
                            + $NIC = Get-NetworkAdapter -VM $vmName
                            +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (ImportTest:String) [Get-Network
                               Adapter], VimException
                                + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNo
                               tFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetNetwo
                              rkAdapter

                            Get-NetworkAdapter : 6/13/2018 8:25:35 AM       Get-NetworkAdapter
                            Please specify
                            at least one of the following: VirtualMachine, Template or Snapshot.
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:42 char:8
                            + $NIC = Get-NetworkAdapter -VM $vmName
                            +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : InvalidArgument: (:) [Get-NetworkAdapter], ViErr
                               or
                                + FullyQualifiedErrorId : Core_VirtualDeviceGetter_GetMoListFromCmdletPara
                               meter_InsufficientParameters,VMware.VimAutomation.ViCore.Cmdlets.Commands.
                              VirtualDevice.GetNetworkAdapter

                            Set-NetworkAdapter : Cannot validate argument on parameter 'NetworkAdapter'.
                            The argument is null. Provide a valid value for the argument, and then try
                            running the command again.
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:43 char:36
                            + Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "$VLAN" -Confirm ...
                            +                                    ~~~~
                                + CategoryInfo          : InvalidData: (:) [Set-NetworkAdapter], Parameter
                               BindingValidationException
                                + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom
                               ation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

                            Script will now prompt for VM name to perform Windows updates.  If a linux machi
                            ne press Ctrl+C to end the script once the OVF deployment has completed.
                            ImportTest
                            Get-VM : 6/13/2018 8:25:36 AM   Get-VM          VM with name 'ImportTest' was no
                            t found
                            using the specified filter(s).
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:46 char:11
                            + $VMname = Get-VM -Name $vmName | Select Name, @{N="Powerstate";E={($_ ...
                            +           ~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException
                                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                               utomation.ViCore.Cmdlets.Commands.GetVM

                             

                            It wound up canceling the import for this one.

                             

                            And then on another OVA that I was trying to import that was failing just thru the web client I wound up getting this:

                             

                            Get-Cluster : 6/13/2018 8:29:52 AM      Get-Cluster             Cluster with nam
                            e
                            '@{Name=HACluster}.Name' was not found using the specified filter(s).
                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:1
                            + Get-Cluster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | ...
                            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                               utomation.ViCore.Cmdlets.Commands.GetCluster

                            Get-VMHost : 6/13/2018 8:29:52 AM       Get-VMHost              VMHost with name

                            '@{Name=isecpod18.beaqa.lab; ConnectionState=Connected;
                            PowerState=PoweredOn}.Name' was not found using the specified filter(s).

                            At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:41 char:37
                            + ... uster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | Forea ...
                            +                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException
                                + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                               utomation.ViCore.Cmdlets.Commands.GetVMHost

                             

                            It then threw up all the VLANs but didn't let me select any and then threw this:

                             

                            Get-VM : 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:\Users\emcclure\Desktop\ImportOVFv3.ps1:49 char:14

                            + Get-VM -Name $vm.Name | New-AdvancedSetting -Name "isolation.tools.gu ...

                            +              ~~~~~~~~

                                + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValid

                               ationException

                                + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

                               ation.ViCore.Cmdlets.Commands.GetVM

                             

                            When I run the script before the mods (basically using the PowerCLI window only) it works just fine.

                            • 12. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                              emcclure Enthusiast

                              Hi LucD,

                               

                              So it imports the file, however when it gets to the VLAN portion it gives me this:

                              Set-NetworkAdapter : 6/13/2018 11:10:36 AM      Set-NetworkAdapter
                              The network
                              "@{Cluster=HACluster; Name=VLAN3653; VLanId=3653}" doesn't exist on the host.

                              At C:\Users\emcclure\Desktop\test.ps1:48 char:1
                              + Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName $vlan -Confirm:$ ...
                              + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  + CategoryInfo          : ResourceUnavailable: (@{Cluster=HAClu...3; VLanI
                                 d=3653}:String) [Set-NetworkAdapter], ViError
                                  + FullyQualifiedErrorId : Client20_VmHostServiceImpl_TryGetHostNetworkByNa
                                 me_NonexistentNetwork,VMware.VimAutomation.ViCore.Cmdlets.Commands.Virtual
                                Device.SetNetworkAdapter

                               

                              I notice that when the window opens up for the VLAN it shows the VLAN id with a comma in it, instead of something like 4094.  Would that cause an issue somehow?

                              • 13. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                                LucD Guru
                                vExpertUser ModeratorsCommunity Warriors

                                Try changing that line to

                                 

                                Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName $vlan.Name -Confirm:$false #Applies selected VLAN to VM#

                                 

                                • 14. Re: How to force users to choose only from a list of hosts, datastores, VLANs, etc
                                  emcclure Enthusiast

                                  Hmm, no better.  After I got prompted to move the folder I then got this:

                                   

                                  Get-Cluster : 6/14/2018 8:27:29 AM      Get-Cluster             Cluster with nam
                                  e
                                  '@{Name=HACluster}.Name' was not found using the specified filter(s).
                                  At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:42 char:1
                                  + Get-Cluster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | ...
                                  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      + CategoryInfo          : ObjectNotFound: (:) [Get-Cluster], VimException
                                      + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                                     utomation.ViCore.Cmdlets.Commands.GetCluster

                                  Get-VMHost : 6/14/2018 8:27:29 AM       Get-VMHost              VMHost with name

                                  '@{Name=isecpod17.beaqa.lab; ConnectionState=Connected;
                                  PowerState=PoweredOn}.Name' was not found using the specified filter(s).

                                  At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:42 char:37
                                  + ... uster -Name "$cluster.Name" | Get-VMHost -Name "$vmHost.Name" | Forea ...
                                  +                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException
                                      + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
                                     utomation.ViCore.Cmdlets.Commands.GetVMHost

                                  Set-NetworkAdapter : 6/14/2018 8:27:31 AM       Set-NetworkAdapter
                                  The network
                                  ".Name" doesn't exist on the host.
                                  At C:\Users\emcclure\Desktop\ImportOVFv3.ps1:44 char:1
                                  + Set-NetworkAdapter -NetworkAdapter $NIC -NetworkName "$vlan.Name" -Co ...
                                  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      + CategoryInfo          : ResourceUnavailable: (.Name:String) [Set-Network
                                     Adapter], ViError
                                      + FullyQualifiedErrorId : Client20_VmHostServiceImpl_TryGetHostNetworkByNa
                                     me_NonexistentNetwork,VMware.VimAutomation.ViCore.Cmdlets.Commands.Virtual
                                    Device.SetNetworkAdapter

                                   

                                  never got prompted for the network info either.

                                  1 2 Previous Next