SEPM12.1 RU2 WebServices - Importing a policy example
Hi everybody,
Here a little "Howto" in PowerShell to import a policy into SEPM 12.1 RU2. No example is attached by default, so here it is:
# Directory where this script is located
$ScriptDir = Split-Path $MyInvocation.MyCommand.Path# Dot-Source includes from our common library
. $ScriptDir\common\Get-SepmRmmWebService.ps1function importLUPolicy{
param([ValidateNotNullOrEmpty()]$configFile = "$($ScriptDir)\Config.xml")
try
{
# Read our config file
[xml]$config = Get-Content $configFile
# Generate a client proxy for communicating with the command web service.
$policyService = Get-SepmRmmWebService -HostName $config.SepmWS.HostIpAddress -Port $config.SepmWS.PortNo -WsdlFile "$($config.SepmWS.wsdlDir)\PolicyService.wsdl" -AccessToken $config.SepmWS.AccessToken
#Read the policy file
$bytes = [System.IO.File]::ReadAllBytes("$($ScriptDir)\policy.dat")
#Import policy
$policyService.importPolicy("My Imported Policy","","",$bytes)
}
catch [System.Web.Services.Protocols.SoapException]
{
Write-Error "Unexpected SoapException: $_.Exception.Detail.FirstChild.get_Name() - $_.Exception.Detail.FirstChild.message"
}
catch
{
$error[0].Exception | Format-List -Force
Write-Error ("Unexpected error")
}
finally
{
$policyService.Dispose()
}
}importLUPolicy
policy.dat file has to be exported from a SEPM and is located in the same directory than the script himself.