Powershell script to add list of administrators to citrix
PowerShell Script to Add List of Administrators to Citrix
Script Description
This script uses the Add-AdminRight cmdlet to add rights (role and scope pairs) to an administrator in Citrix. For convenience, the -All parameter can be used to specify the ‘All’ scope. The Get-AdminAdministrator cmdlet is used to determine what rights an administrator has.
Prerequisites: Authenticate to Citrix Cloud
To run this script, you need to log in to Citrix Cloud via PowerShell. Assume that the PowerShell SDK for Citrix is already installed. Here is the process:
Open PowerShell
- Load Citrix Snap-ins
1
asnp citrix*
- Authenticate to Citrix Cloud
1
Get-XDAuthentication
Get-XDAuthenticationwill prompt you to authenticate to Citrix Cloud using your Citrix Cloud identity or Azure AD credentials. It will generate an interactive prompt to sign in to Citrix Cloud and complete MFA. - Set Credentials for Citrix Cloud API
1
Set-XdCredentials
You can use
Set-XdCredentialsto create an authentication profile to connect to Citrix Cloud API using a client ID and secret created in the Citrix Cloud portal. - Authenticate with Customer ID
1
Get-XDAuthentication -CustomerId CUSTOMERID
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Define the path to the CSV file
$csvFilePath = "path\to\administrators.csv"
# Import the CSV file
$admins = Import-Csv -Path $csvFilePath
# Iterate through each row in the CSV
foreach ($admin in $admins) {
$administrator = $admin.Administrator
$role = $admin.Role
$scope = $admin.Scope
# Check if the scope is 'All'
if ($scope -eq 'All') {
# Add the role with 'All' scope
Add-AdminRight -Role $role -All -Administrator $administrator
} else {
# Add the role with specific scope
Add-AdminRight -Role $role -Scope $scope -Administrator $administrator
}
# Output the assigned rights for verification
$assignedRights = Get-AdminAdministrator -Name $administrator
Write-Output "$administrator has been assigned the following rights:"
$assignedRights.Rights | ForEach-Object { Write-Output "Role: $_.Role, Scope: $_.Scope" }
}
Example CSV File (administrators.csv)
1
2
3
4
Administrator,Role,Scope
DOMAIN\Admin1,Help Desk Administrator,London
DOMAIN\Admin2,Full Administrator,All
DOMAIN\Admin3,Read Only Administrator,New York
Explanation
- CSV File Path: Set the
$csvFilePathvariable to the path where your CSV file is located. - Import-Csv: The
Import-Csvcmdlet is used to import the list of administrators from the CSV file. - Iteration: The
foreachloop iterates through each administrator entry in the CSV. - Scope Check: Inside the loop, there’s a check to see if the scope is ‘All’. If it is, the
-Allparameter is used. Otherwise, the-Scopeparameter with the specific scope value is used. - Add-AdminRight: The
Add-AdminRightcmdlet is called to assign the role and scope to the administrator. - Verification: After assigning rights, the script retrieves and outputs the assigned rights for verification purposes.
Running the Script
- Save the script as a
.ps1file, for example,Add-Admins.ps1. - Ensure the CSV file is correctly formatted and saved at the specified path.
- Open PowerShell with administrative privileges.
- Execute the script by navigating to its directory and running:
1
.\Add-Admins.ps1
This script automates the process of adding roles and scopes to multiple administrators in Citrix, making it efficient to manage administrator rights.