top of page

USING POWERSHELL AND IVANTI UWM API FOR MACHINE POLLING

I was working on a project where we built a complex Environment Manager config. It made sense to have this config start doing its magic on the workstation during the SCCM build Task sequence, but we didn’t want to have to maintain a config package in SCCM.


I decided to search around to find out how to force a poll at the time of install for the Ivanti Client Communication Agent during the SCCM task sequence. Forcing a poll ensures that the EM Config is downloaded to the endpoint after establishing communication with the management server.


Unfortunately, this was not as straight forward as it looked, and doing it manually through the management center console was not an option.


Ivanti provides a document titled “AppSense Management Center v10.0 Web Services API Guide” which is the latest version I could find in their Knowledge Base. This document lays out what services and functions are available through a set of APIs designed for this type of solution.


This article showed me how to perform a Machine move and provided a template for how to load the API objects using libraries that are installed with the console.

The following PowerShell snippet is an example of calling the WebServices API:


While the blog article explains how to find machines using the WebServices API, it doesn’t provide much information on how to execute a poll.


I discovered that a method for executing a poll involves a process by creating “instructions” and executing them:

Notice the parameter “Initiating Script Client Poll”. This will show up in the console when the action executes.


You also need to make sure that there are no existing instructions. The console automatically takes existing instructions into account, so you’ll need to make sure to delete any existing instructions before adding a new one.


And then it’s a matter of performing an “activate” function which will run the loaded instruction as shown below:

If you want a simple PowerShell script to poll a machine in your Ivanti Management Center, use my script below!


Make sure to run the script on a computer with the Management Center Console installed. Info-wise, you just need the name of your Management Server, the Port that’s configured to receive Web Service requests, and the name of the Machine that you want to poll.


An easy way to get this info is to see how you’re connecting to your management server with the MC Console.

Your script call should look something like this:


When the script is run, you’ll see this message in the console for the machine:



There are a lot of these great little functions hidden away in the Ivanti Management Server Web Services, so check in again soon to see the other scripts we’ve come up with.

<#

.SYNOPSIS
	This script will run a poll on a workstation in the Ivanti Management Center
.DESCRIPTION
    This script will run a poll on a workstation in the Ivanti Management Center
.PARAMETER ManagementServerName
    The name of the Ivanti Management Center Server
.PARAMETER Port
	Default is 80. Can also be set to 443
.PARAMETER Name
	Machine Name
.EXAMPLE
    .\Poll-MCMachine.ps1 -ManagementServerName "amc.lab.com" -Port 80 -Name "Win10-2"

.LINK 
	http://criticaldesign.sharepoint.com

#>
Param (
	[Parameter(Mandatory=$True)]
	[string]$ManagementServerName,
    [ValidateSet(80,443)]
	[string]$Port=80,
	[Parameter(Mandatory=$True)]
	[string]$Name
)


If($Port = 80) {
    $Protocol = "http"
}Else {
    $Protocol = "https"
}


$ManagementServerUrl = "$($Protocol)://$($ManagementServerName):$($Port)/ManagementServer"

If(Test-Path "${Env:ProgramFiles}\AppSense\Management Center\Console\ManagementConsole.WebServices.dll"){
    Add-Type -Path "${Env:ProgramFiles}\AppSense\Management Center\Console\ManagementConsole.WebServices.dll"
    
}

$ConnectionCredentials = $([System.Net.CredentialCache]::DefaultCredentials).GetCredential($ManagementServerUrl, "Basic")

[ManagementConsole.WebServices]::Connect($ManagementServerUrl, $ConnectionCredentials)

$MachinesWebService = [ManagementConsole.WebServices]::Machines
$DeploymentWebService = [ManagementConsole.WebServices]::Deployment

$TargetMachineObject = $MachinesWebService.FindMachines('%').Machines | Where-Object {$_.NetBiosName -eq $Name}
$TargetMachineKey =  $($TargetMachineObject | Select-Object MachineKey).MachineKey

$DeploymentWebService.GetDeploymentInstructionsFromDiscoveredMachineKey($TargetMachineKey).Instructions|Foreach-Object {$DeploymentWebService.DeleteInstructions($_.InstructionKey,$Null)}

$PollActionGuid = [guid]::newguid()

$DeploymentWebService.CreateInstructions($PollActionGuid,129,$Null,"DeployNowPlugin.dll",$TargetMachineKey,"Initiating Script Client Poll")|Out-Null
$DeploymentWebService.ActivateDeploymentService(129)|Out-Null

Did you find this helpful? Have more questions? Send us a message!


Comments


Commenting has been turned off.
bottom of page