ITJef
Enthusiast
Enthusiast

PowerCLI Add machine to Horizon error message

I have a script that builds a machine in vcenter (6.7) and then the last step is to add the machine to a pool in horizon(7.10) and add a user to the machine. Below is the error message i am getting and the script code i am running. I am using powercli 6.5 release 1.

Error Message

Exception calling "VirtualMachine_List" with "2" argument(s): "ExceptionType : VMware.Hv.UnexpectedFault

ErrorMessage : Encountered unexpected error during execution

CauseString : java.lang.IllegalArgumentException: name == null

CauseStackTrace : System.String[]

ErrorCode :

ErrorAttributes : "

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

    + PSComputerName        : Horizonserver.domain.com

Failed to get any Virtual Center machines with the given machines parameter

    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-HVDesktop

    + PSComputerName        : horizonserver.domain.com

Assigning user to machine

E r r o r :   N o   v i r t u a l   o r   p h y s i c a l   m a c h i n e   e n t r y   w a s   f o u n d   m a t c h i n g   t h e   s p e c i f i e d

c r i t e r i a

    + CategoryInfo          : NotSpecified: (E r r o r :   N... r i t e r i a :String) [], RemoteException

    + FullyQualifiedErrorId : NativeCommandError

    + PSComputerName        : Horizonserver.domain.com

Below is the code i am running.

#############################################

# Add Vm to Horizon View and update permissions.

##############################################

write-host "Updating Horizon for " $vmname -ForegroundColor Green

invoke-command -computername $connectionserver -scriptblock {

        param($vmname, $vmviewPool, $vmuser, $HorizonCredential)

  

        $viewServer = "horizonServer.domain.com"

     

        #add-pssnapin vmware.view.broker

        Get-Module -ListAvailable VMware* | Import-Module

        connect-hvserver $viewserver -Credential $horizoncredential

     

        write-host "Adding machine to Horizon" -ForegroundColor green

        #add machine to pool

        add-hvdesktop -pool $vmviewpool -machines $vmname

     

        write-host "Assigning user to machine" -ForegroundColor green

        sleep 5

        $fullUsername = "domain\" + $vmuser

        $cmdString = "vdmadmin -L -d $vmviewpool -m $vmname -u $fullusername"

        Invoke-Expression $cmdString

        disconnect-hvserver $viewserver -confirm:$false

}    -ArgumentList $vmname, $vmviewPool, $vmuser, $HorizonCredential

0 Kudos
3 Replies
LucD
Leadership
Leadership

Looking at the code of the Add-HVDesktop function in VMware.HV.Helper.psm1 line 460, that error is produced when the VM with the name you provide is not found in the vCenter.

Can you verify the name and check if it present in the vCenter?

You could add the -Verbose switch to get some more feedback.

And perhaps use a transcript log (Start-Transcript) in the code.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ITJef
Enthusiast
Enthusiast

Thats the issue. So this script worked great for about 2 years and then last week we upgraded vcenter to 6.7 and the script fails. However when i go to vcenter i can see the vm built properly. I thought it was a timing issue so i tried to make the script wait 30 seconds first before trying to add to horizon and that still does not work. I feel like it is something relating to 6.7 vcenter being a appliance and not a windows server

i am getting those logs now.

0 Kudos
LucD
Leadership
Leadership

Perhaps you could insert a Get-VM in your script to check?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos