Citrix - Adding machines to Catalog

I am trying to run below code to add machines to my Citrix catalog but getting error , any help appreciated


PS Code-
Machine = Get-Content “C:\temp\machine.txt”
$HostID = Get-Content “C:\Temp\HostID.txt”

for ($i=0;$i-le $Machine.length-1;$i++)
{
$x = $Machine
$y = $HostID

New-BrokerMachine -MachineName $x -HostedMachineId $y -CatalogUid 18 -HypervisorConnectionUid 2

}

Output error-

New-BrokerMachine : Cannot convert ‘System.Object’ to the type ‘System.String’ required by parameter ‘MachineName’. Specified method is not supported.
At line:6 char:32

  • New-BrokerMachine -MachineName $Machine -HostedMachineId $HostID -Cat …
  •                            ~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [New-BrokerMachine], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgument,Citrix.Broker.Admin.SDK.NewBrokerMachineCommand

Hi, welcome to the forum :wave:

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

Can tell us what the goal is here?
Right now, for every iteration of your loop you’re assigning everything in machine.txt to $x and everything in hostID.txt to $y. I’m assuming you actually want to do this line-by-line? Are machine.txt and hostID.txt the same length?