Re: Command line policy synchronization (568 Views)
Reply
Trusted Contributor
Ken Strauss_2
Posts: 402
Registered: ‎01-21-2005
Message 1 of 8 (568 Views)
Accepted Solution

Command line policy synchronization

We need a way to synchronize the policy status in the OMw console on a scheduled basis. Our user base regularly changes the policy status on the managed nodes and then management server console is out of sync.
Honored Contributor
Mahmoud Ibrahim
Posts: 1,575
Registered: ‎05-21-2008
Message 2 of 8 (568 Views)

Re: Command line policy synchronization

Hi Ken,
We have two options to acheive this, either by get the Assigned policies from OMW and assing them back to the nodes; this will ensure what you see in the OMW as Policy Inventory for the Node will be redeployed to the node.

The second option is to requests the node to send the updated information to overwrite the OMW inventory for this node by the current policies deployed; This is typically done by right click the node and then Sync Inventory option, we want to script this part.

Regards,
Mahmoud Ibrahim
http://www.mahmoudthoughts.com
Regards,
Mahmoud Ibrahim
http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • Honored Contributor
    Mahmoud Ibrahim
    Posts: 1,575
    Registered: ‎05-21-2008
    Message 3 of 8 (568 Views)

    Re: Command line policy synchronization

    For option number one:
    Thre is script available on the Online Help which re-deploys all policies that are currently installed on the specified node.

    Usage: cscript.exe RedployAllPolicies.vbs nodeName

    ------RedployAllPolicies.vbs----
    '//get the name of the managed node from the command line
    Dim argsObj
    Set argsObj=WScript.Arguments

    If argsObj.Count=0 Then
    WScript.echo "Usage: cscript.exe RedployAllPolicies.vbs "
    WScript.Quit (1)
    End If

    '//create connection to policy management server
    Dim PMAD
    Set PMAD = CreateObject("PMAD.OvPmdPolicyManager")
    PMAD.ConnectDB

    '//access the managed node in WMI
    Dim objLocator
    Set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Dim objNode
    Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "")
    objNode.Security_.impersonationlevel = 3

    '//iterate over the specified node list
    Dim nodeName
    Dim numOfNodes
    For numOfNodes = 0 To argsObj.Count - 1
    '//get the primary node name as it was specified on the command line
    nodeName = argsObj(numOfNodes)

    '//get the node from WMI
    Dim msgQuery
    msgQuery = "Select * from ov_managednode where primarynodename = """ & nodeName & """"
    Dim objNodeList
    Set objNodeList = objNode.ExecQuery(msgQuery)

    '//get the GUID of the managed node object
    Dim nodeGuid
    Dim wmiNode
    For Each wmiNode In objNodeList
    '//assign the node GUID to the variable "nodeGuid"
    nodeGuid = wmiNode.Name
    '//other node properties, such as system type or OS type, can be determine the same way
    '//for example, osType = wmiNode.OSType or sysType = wmiNode.SystemType)
    Next

    '//release objects
    Set wmiNode = Nothing
    Set objNodeList = Nothing

    If PMAD.DBConnected And nodeGuid <> "" Then
    '//get the pmad node object, or create it if it does not yet exist)
    Dim node
    Set node = PMAD.CreateNode(nodeGuid)

    '//get the list of policies that are currently installed on the node
    Dim policyList
    policyList = PMAD.CVar(node.GetPolicyList)

    WScript.echo "The following policies are redeployed on node '" & nodeName & "':" & vrLf
    Dim policy
    Dim policyObj
    Dim policyString
    For Each policy In policyList
    '//get the policy object
    Set policyObj = policy

    '//print out policy that is redployed
    policyString = " " & policyObj.GetName & " " & policyObj.GetVersionString & vrLf
    WScript.echo policyString

    '//deploy the policy to the node
    call policyObj.DeployOnNodes(nodeGuid, false, true)
    Next
    WScript.echo " " & vrLf
    Set policy = Nothing
    Set policyList = Nothing
    Set node = Nothing
    Else
    If nodeGuid = "" Then
    WScript.echo "Error: The node '" & nodeName & "' that you specified on the command line cannot be found in WMI!"
    Else
    WScript.echo "Error: Unable to connect to the policy management server!"
    End If
    End If
    Next

    '//release objects
    Set objNode = Nothing
    Set objLocator = Nothing
    Set PMAD = Nothing


    ------

    Regards,
    Mahmoud Ibrahim
    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • Honored Contributor
    Mahmoud Ibrahim
    Posts: 1,575
    Registered: ‎05-21-2008
    Message 4 of 8 (568 Views)

    Re: Command line policy synchronization

    Hi Ken,

    For the second option, I am currently building script to use Synchronize() function to acheive the same as Right Click the node All Task Sync Inventory.

    I will update you shortly.

    Regards,
    Mahmoud Ibrahim
    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • Honored Contributor
    Mahmoud Ibrahim
    Posts: 1,575
    Registered: ‎05-21-2008
    Message 5 of 8 (568 Views)

    Re: Command line policy synchronization

    Hi Ken,
    Here below the promised script for Sync node inventory using command line
    Usage: cscript.exe SyncInventory.vbs "
    The command below acheives sync policies only typical to right click -> Synchronize Inventory -> Policies Only

    cscript.exe SyncInventory.vbs node.abc.com PoliciesOnly

    -----SyncInventory.vbs-----

    '//get the name of the managed node from the command line
    '//This script performs a node-to-server (or upward) synchronization.
    '//This means the node is considered more up-to-date than the server (with regards to installed policies and packages).
    '//As a result, the server inventory for the node is deleted, and filled with the policies and packages that are returned by the node inventory.
    '//This script is created by Mahmoud Ibrahim http://www.mahmoudthoughts.com to assist HP Operations Administrator to sync node inventory using command line.
    '//Special thanks to HP ITRC forum that exploit my scripting thoughts

    Dim argsObj
    Set argsObj=WScript.Arguments

    If argsObj.Count<2 Then
    WScript.echo "Usage: cscript.exe SyncInventory.vbs "
    WScript.Quit (1)
    End If


    Select Case argsObj(1)
    Case "PoliciesOnly"
    syncFlag = 2048
    Case "PackagesOnly"
    syncFlag = 1024
    Case "PoliciesPackages"
    syncFlag = 0
    Case Else
    syncFlag = 2048
    End Select

    '//create connection to policy management server
    Dim PMAD
    Set PMAD = CreateObject("PMAD.OvPmdPolicyManager")
    PMAD.ConnectDB

    '//access the managed node in WMI
    Dim objLocator
    Set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Dim objNode
    Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "")
    objNode.Security_.impersonationlevel = 3

    '//iterate over the specified node list
    Dim nodeName
    Dim numOfNodes
    For numOfNodes = 0 To argsObj.Count - 1
    '//get the primary node name as it was specified on the command line
    nodeName = argsObj(numOfNodes)

    '//get the node from WMI
    Dim msgQuery
    msgQuery = "Select * from ov_managednode where primarynodename = """ & nodeName & """"
    Dim objNodeList
    Set objNodeList = objNode.ExecQuery(msgQuery)

    '//get the GUID of the managed node object
    Dim nodeGuid
    Dim wmiNode
    For Each wmiNode In objNodeList
    '//assign the node GUID to the variable "nodeGuid"
    nodeGuid = wmiNode.Name
    '//other node properties, such as system type or OS type, can be determine the same way
    '//for example, osType = wmiNode.OSType or sysType = wmiNode.SystemType)
    Next

    '//release objects
    Set wmiNode = Nothing
    Set objNodeList = Nothing

    If PMAD.DBConnected And nodeGuid <> "" Then
    '//get the pmad node object, or create it if it does not yet exist)
    Dim node
    Set node = PMAD.CreateNode(nodeGuid)

    '//Start sync list of policies or packages that are currently installed on the node
    Dim syncNode
    sysncNode = node.Synchronize(syncFlag)
    Else
    If nodeGuid = "" Then
    WScript.echo "Error: The node '" & nodeName & "' that you specified on the command line cannot be found in WMI!"
    Else
    WScript.echo "Error: Unable to connect to the management server!"
    End If

    end if
    Next
    -----


    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • Honored Contributor
    Mahmoud Ibrahim
    Posts: 1,575
    Registered: ‎05-21-2008
    Message 6 of 8 (568 Views)

    Re: Command line policy synchronization

    Hi Ken,
    I hope those scripts will achieve what you originally requested.
    It took one hour to develop and test the second script.
    Please find the second script in the attached.

    Assigning points is appreciated.

    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • Trusted Contributor
    Ken Strauss_2
    Posts: 402
    Registered: ‎01-21-2005
    Message 7 of 8 (568 Views)

    Re: Command line policy synchronization

    Great stuff, Mahmoud, Thanks!
    Honored Contributor
    Mahmoud Ibrahim
    Posts: 1,575
    Registered: ‎05-21-2008
    Message 8 of 8 (568 Views)

    Re: Command line policy synchronization

    Thanks for the points..
    Regards,
    Mahmoud Ibrahim
    http://www.mahmoudthoughts.com
  • Say thanks by clicking the "Kudos! Star" which is on the left.

  • Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue.
  • The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.