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

Powershell script to auto restart desktop


peizhi yu

Question

I want to write a script to auto restart desktop of Unregistered.

 

I can get the information of desktop by the following command:

Get-BrokerMachine | select HostedMachineName,RegistrationState,SessionState

 

result as follows:

HostedMachine      RegistrationState             SessionState
------------        --------------               ------------
Win10-C01            Unregistered
Win10-C02            Registered
Win10-C03            Registered                   Disconnected
Win10-C04            Registered
Win10-C05            Registered
Win10-C06            Registered                    Active

 

How can I get the status of the virtual desktop by HostedMachineName?

 

Link to comment

5 answers to this question

Recommended Posts

  • 0
$Machines = Get-BrokerMachine | Where-Object {$_.RegistrationState -eq "Unregistered"}
foreach ($Machine in $Machines) {
    #Do Something
}

that will get all all unregistered machines which you can then do something with - you can manipulate the above example for whatever you need really

  • Like 1
Link to comment
  • 0
18 minutes ago, James Kindon said:

are you trying to do something more complex than below?


Get-BrokerMachine -HostedMachineName Win10-C01

or more specifically


(Get-BrokerMachine -HostedMachineName Win10-C01).RegistrationState

 

I want to write a loop to iterating over all host.

 

What do I do?

Link to comment
  • 0
On 6/8/2020 at 4:05 PM, James Kindon said:

$Machines = Get-BrokerMachine | Where-Object {$_.RegistrationState -eq "Unregistered"}
foreach ($Machine in $Machines) {
    #Do Something
}

that will get all all unregistered machines which you can then do something with - you can manipulate the above example for whatever you need really

It's working. Thanks your help.

Link to comment

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...