Using PowerShell to Determine AppAssure Agent Status and Version

The Get-ProtectedServers PowerShell cmdlet which is part of the AppAssure PowerShell Module that’s installed on your AppAssure Core server version 5.3.1 or higher allows you to determine what servers are being protected by a particular AppAssure Core server.

Since I’m running PowerShell version 3 on the AppAssure Core server shown in the example below, I didn’t have to explicitly import the AppAssure PowerShell module, if you’re running PowerShell version 2, you would need to run Import-Module AppAssurePowerShellModule prior to running the Get-ProtectedServers cmdlet. The following example shows that you can retrieve some useful information with the Get-ProtectedServers cmdlet by simply running it without any parameters:

appassure1

To determine what other properties are available for this cmdlet, just like any other cmdlet that produces output, pipe it to Get-Member. One thing to note is the column headers such as “Display Name” and “Is Paused” as shown in the previous example which have a space between the words are not the actual property names. The property name for each of these items as shown in the following results doesn’t contain a space between the words:

appassure2

I want to filter the output of the Get-ProtectedServers cmdlet down to a subset so I’ll view the full help for this cmdlet to determine if it has any parameters to filter with:

appassure3

Based on the results of the full help in the previous image, there are no parameters for filtering left so we’ll have to resort to piping our results to the Where-Object cmdlet and perform our filtering with that cmdlet. I only want to return a list of servers that should be protected by this AppAssure Core server where the current status is not equal to protected (show me any servers with a status other than protected):

Note: Each of the following examples use the new PowerShell version 3 simplified Where-Object syntax.

appassure4

I’ve been working on updating these client agents to the latest version of AppAssure so the problem is probably that the AppAssure Agent service is not running on those particular servers. Now I only want to retrieve a list of just the server names where the status is not protected. By using the -expand property with the Select-Object cmdlet, the server names are returned as strings without a column header:

appassure5

PowerShell remoting is enabled on all of the servers in this environment. I’m now going to place the command we previously created inside of parentheses to feed the Invoke-Command cmdlet the list of server names that aren’t currently protected to determine what the status of the AppAssureAgent service is on them:

appassure6

Let’s modify the previous command slightly to attempt to start the AppAssureAgent service on each of these servers. I’ve replaced the Get-Service cmdlet with the Start-Service cmdlet. I’ve also added the -Passthru parameter since the Start-Service cmdlet doesn’t return any results by default and I want to see what the results are without having to run another PowerShell command:

appassure7

Now that all of the agents are protected, I want to see which ones are still in need of updating. I’ll sort the results so the servers with the out of date agents are listed first:

appassure8

Let’s refine that list a little more and only return a list where the version is not equal to the latest version. The sorting isn’t really necessary in this scenario, although if more than one previous version of the AppAssure agent was on different servers, it would have mattered:

appassure9

Looks like I have three more servers to update the AppAssure agent on and all of them will be updated, then I can move on to doing more fun stuff with PowerShell.

µ

About Mike Robbins

PowerShell Enthusiast | IT Pro | Winner of the Advanced Category in the 2013 PowerShell Scripting Games | Author of Chapter 6 in the PowerShell Deep Dives Book.
This entry was posted in AppAssure, PowerShell and tagged , . Bookmark the permalink.

4 Responses to Using PowerShell to Determine AppAssure Agent Status and Version

  1. Harold says:

    I am having a problem with Appassure restarting/running when servers get rebooted. The following script doesn’t work when running from task scheduler but runs find from command line.
    Any ideas? Think it is a timing issue.

    $servers = Get-ProtectedServers | where status -ne protected | select -expand displayname
    if ($servers.count -ne 0) {
    foreach ($server in $servers){
    Invoke-Command -ComputerName $server -ScriptBlock {Restart-Service AppAssureAgent -PassThru}
    $SmtpClient = new-object system.net.mail.smtpClient
    $MailMessage = New-Object system.net.mail.mailmessage
    $SmtpClient.Host = “smtp.local.com”
    $mailmessage.from = (“mgmt2_task@local.com “)
    $mailmessage.To.add(“admin@local.com”)
    $mailmessage.Subject = “AppAssure Agent restarted on $server”
    $mailmessage.Body = “Powershell script ran from task scheduler on mgmt2”
    $smtpclient.Send($mailmessage)
    }
    }

  2. Harold says:

    This script works from command line but not from powershell. Any clues?
    powershell -file “C:Program FilesAppRecoverygetAAstatus.ps1″

    $servers = Get-ProtectedServers | where status -ne protected | select -expand displayname
    if ($servers.count -ne 0) {
    foreach ($server in $servers){
    Invoke-Command -ComputerName $server -ScriptBlock {Restart-Service AppAssureAgent -PassThru}
    $SmtpClient = new-object system.net.mail.smtpClient
    $MailMessage = New-Object system.net.mail.mailmessage
    $SmtpClient.Host = “smtp.local.com”
    $mailmessage.from = (“mgmt2_task@local.com “)
    $mailmessage.To.add(“admin@local.com”)
    $mailmessage.Subject = “AppAssure Agent restarted on $server”
    $mailmessage.Body = “Powershell script ran from task scheduler on mgmt2”
    $smtpclient.Send($mailmessage)
    }
    }

    • Based on my experience with running PowerShell scripts as a scheduled task, I’m going to make the assumption that you’re running it as a different user when it’s running as a scheduled task. Try it with the same user account if this is the case and see if that works. If it does, make sure the user that’s executing the scheduled task has logged into the machine where the scheduled task is setup. I’ve found if the user doesn’t have a profile on the machine, it can cause the problem you’re experiencing. If that doesn’t fix the issue, let me know and I have a few other things you can try.

  3. Wolfgang says:

    It is likely because AppAssure has released a number of new versions since this post, but in order to get the Agent Version listing to work correctly, I had to modify the command line to this:

    Get-protectedServers | where {$_.version -ne “5.3.2.61676”} | select displayname, version | sort displayname

    Mike, thank you for this article, it has been a great starting point for solving some of my information gathering problems in AppAssure.

Leave a Reply