Endpoint Protection

 View Only

SEPM12.1 RU2 WebServices - Importing a policy example 

Nov 29, 2012 08:05 AM

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

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

 

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
zip file
ImportPolicy.zip   810 B   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

Jul 25, 2013 04:29 AM

As a user report, ". $ScriptDir\common\Get-SepmRmmWebService.ps1" isn't included in download.

It's because this script (and many others), are provided by Symantec on the "SEP12 RUx part2 - Tools" download in which you'll find Documentations and PowerShell scripts examples about SEP WebServices.

My script need to be installed into the top directory of PowerShell sample scripts provided by Symantec.

They are located in "Integration\SEPM_WebService_SDK\Sample_Code\PowerShell" in the "SEP12 RUx part2 - Tools" CD.

 

Don't hesitate to contact me if you have questions about webservices

Related Entries and Links

No Related Resource entered.