Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, February 5, 2019 10:33 PM
Objective: A PowerShell Script to find all AD inactive/disabled user accounts, then put their corresponding Citrix XenDesktop VDI in maintenance mode if exist.
I got the below code but not sure how to set the rules in PowerShell for it to trigger correctly. Any help is greatly appreciated.
* Collecting Disabled User Accounts Information
Search-ADAccount –AccountDisabled –UsersOnly –ResultPageSize 2000 –ResultSetSize $null | Select-Object SamAccountName, DistinguishedName
* Collecting Inactive User Accounts The below command uses the –TimeSpan parameter to find user accounts that have been inactive for the last 90 days. The output is exported to the C:\Temp\InActiveUsers.CSV file.
Search-ADAccount –AccountInActive –TimeSpan 90:00:00:00 –ResultPageSize 2000 –ResultSetSize $null | ?{$_.Enabled –eq $True} | Select-Object Name, SamAccountName, DistinguishedName | Export-CSV “C:\Temp\InActiveUsers.CSV” –NoTypeInformation
*Citrix maintenance mode via PowerShell
Firstly, launch PowerShell either via studio or by running Add-PSSnapin Citrix.* within your PowerShell console.
Machines used in scenarios:
- CitrixDesktop1
- CitrixDesktop2
- CitrixDesktop3
Scenario 1 – Put CitrixDesktop1 in to maintenance mode
- Set-BrokerMachineMaintenanceMode -InputObject DOMAIN\CitrixDesktop1 $true
- Get-BrokerMachine -MachineName DOMAIN\CitrixDesktop1 | fl InMaintenanceMode
*The first command sets the machine in maintenance mode. The second queries for the end result.
*
Scenario 2 – Put CitrixDesktop1 and CitrixDesktop2 in to maintenance mode
- Set-BrokerMachineMaintenanceMode -InputObject DOMAIN\CitrixDesktop1, DOMAIN\CitrixDesktop2 $true
Scenario 3 – Put all three machines in to maintenance mode
- $machines = Get-BrokerMachine -MachineName DOMAIN\CitrixDesktop*
- Set-BrokerMachineMaintenanceMode -InputObject $machines $true
The first command gets a list of machines with CitrixDesktop in their name. The second puts them in to maintenance mode.
All replies (4)
Tuesday, February 5, 2019 11:20 PM
Sorry but this is not a Citrix forum. You will have to post this in the Citrix forum for your issue.
We cannot teach you PowerShell and how to use it with Citrix. That is beyond the scope of this forum.
\(ツ)_/
Tuesday, February 5, 2019 11:25 PM
Will do, Thanks.
Wednesday, February 6, 2019 6:37 AM
Not big deal Voev it is nothing strange to ask this question here. Our PowerShell community will definitely help you with it.
Wednesday, February 6, 2019 6:45 AM
Not big deal Voev it is nothing strange to ask this question here. Our PowerShell community will definitely help you with it.
Please refrain form off-topic comments. If you have a solution post it, otherwise the question needs to be asked in a Citrix forum as this is a forum for Microsoft products.
\(ツ)_/