Jump to content
Welcome to our new Citrix community!
  • 0

Powershell Script to Auto assign users to unassigned VDI machine


Ciri Liaw

Question

Hi Expert,

 

I am looking for some direction and guidance for this Powershell script I wrote. Basically I want to take a list of users from simple txt file and then run the script and have it auto assign unassigned VDI on mentioned delivery groups.

 

This scripts works but if I put 2 or more users, it auto assign single VDI machine to all the users based on the txt file where as I want single user single machine assignment for each users on the list.

 

$ReportFile = "D:\Temp\Output\AssignmentResult.txt"

Remove-item $ReportFile -ErrorAction SilentlyContinue

$UserFile = "D:\Temp\Userlist.txt"

$ThisSTR = "Username ------ Assigned?"

Add-Content $ReportFile $ThisSTR

asnp Citrix.*

$machines = Get-BrokerMachine -desktopgroupname "Win10 Desktops" -filter { IsAssigned -eq $false } -Summarystate available -MaxrecordCount 1000

 

foreach ($User in Get-Content $UserFile)

{

$i=0

    $IsUpdated = "No"

    $Error.Clear()

    if ($machines.associatedusernames -eq $null)

    {

        Add-BrokerUser $User -Machine $machines[$i]

    }

 

IF ($Error.count -eq 0)

{

$IsUpdated = "Yes"

}

 

$i++

    $ThisSTR = $User+","+$IsUpdated

    Add-Content $ReportFile $ThisSTR

}

 

 

Any help appreciated!!!! Thanks in advance.

Link to comment

2 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...