'//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 <nodeNameList>" 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
Dim nodeName Dim category Dim argsObj Set argsObj=WScript.Arguments If argsObj.Count=2 Then nodeName = argsObj(0) category = argsObj(1) Else WScript.echo "usage: cscript.exe ovdeplinstrum.vbs <nodeName> <instrum_category>" WScript.Quit (1) End If '//Look up the node name (GUID) in WMI '//Create Locator object to connect to remote CIM object manager Dim objLocator Set objLocator = CreateObject("WbemScripting.SWbemLocator") '//Connect to the namespace, which can be either local or remote Dim objNode Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "") objNode.Security_.impersonationlevel = 3 '//build the WMI query Dim msgquery msgquery = "Select * from ov_managednode where primarynodename = """ & nodeName & """" '//execute the query Dim objNodeList Set objNodeList = objNode.ExecQuery(msgquery) '//Get the node GUID Dim nodeGuid Dim wminode For Each wminode In objNodeList nodeGuid = wminode.Name Next '//Destroy all of the objects used for the WMI query Set wminode = Nothing Set objNodeList = Nothing Set objNode = Nothing Set objLocator = Nothing '//Now connect to PMAD and get the policy information Dim pmad set pmad = CreateObject("PMAD.OvPmdPolicyManager") pmad.ConnectDB 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) call node.DeployInstrumentation2(category, false) Set node = Nothing Else wscript.echo "node not found or invalid, or cannot connect to database!" End If '//destroy the connection to PMAD! Set pmad = Nothing
Set objArgs = wscript.arguments If objArgs.Count = 0 Then '//You must provide the node group name (ID) from the WMI node group object '//(not its caption); the WMI property is called "Name" wscript.echo "usage: cscript.exe RemovePoliciesFromNodeGroup.vbs <NodeGroupID>" wscript.quit(1) Else szNodeGroup = objArgs(0) End If Set objNodeGroup = GetObject("WinMgmts:{impersonationLevel=impersonate}!root\hewlettpackard\openview\data:ov_nodegroup.name=""" & szNodeGroup & """") '//Now connect to PMAD and get the policy information Set objPmad = CreateObject("PMAD.OvPmdPolicyManager") objPmad.ConnectDB If objPmad.DBConnected Then '//get the members of the node group Set objGroupMembers = objNodeGroup.Associators_ '//loop through each of the members For Each objItem In ObjGroupMembers '//make sure the member is an ov_managednode (not an ov_nodegroup) If lcase(objItem.path_.class) = "ov_managednode" Then wscript.echo "Found node " & objItem.Caption wscript.echo "OSType " & objItem.OSType '//ignore nodes that cannot have policies (unknown, snmp) If objItem.OsType <> 65535 then ' get the node Set objNode = objPmad.GetNode(objItem.name) '//This throws an error if no policies are installed. arrPolicyList = objPmad.cvar(objNode.GetPolicyList) //loop through the policy list For Each objPolicy In arrPolicyList '//get the policy name wscript.echo objPolicy.GetName '//remove the policy from the node objPolicy.RemoveFromNodes objItem.name Next ' //next policy End If '//if not snmp/other End If '//if not an ov_managednode Next '//member of the group Else wscript.echo "cannot connect to database!" End If '//destroy the connection to PMAD! Set objPmad = Nothing
Set objArgs = Wscript.arguments If objArgs.Count = 1 Then szServerName = objArgs(0) Else wscript.echo "usage: cscript.exe updatepolicies.vbs <nodeName>" wscript.echo "where node name is the host name of the node you want to update" wscript.quit(0) End If Dim szNodeGuid Dim objLocator Dim objNode Dim msgquery Dim objNodeList Dim wminode '//Look up the host GUID (Name) '//Create the Locator object to connect to the remote CIM object manager Set objLocator = CreateObject("WbemScripting.SWbemLocator") '//Connect to the namespace, which is either local or remote Set objNode = objLocator.ConnectServer("", "root\hewlettpackard\openview\data", "", "") objNode.Security_.impersonationlevel = 3 '//build the wmi query msgquery = "Select * from ov_managednode where primarynodename = """ & szServerName & """" '//execute the query Set objNodeList = objNode.ExecQuery(msgquery) '//Get the node GUID For Each wminode In objNodeList szNodeGuid = wminode.Name Next '//Destroy all of the objects used for the WMI query Set wminode = Nothing Set objNodeList = Nothing Set objNode = Nothing Set objLocator = Nothing '//Now connect to PMAD, and get the policy information Set pmad = CreateObject("PMAD.OvPmdPolicyManager") pmad.ConnectDB Dim node Dim updatedpolicycount Dim policycount Dim policylist Dim policyitemenum Dim szNodeGuidArray If pmad.DBConnected And szNodeGuid <> "" Then '//open up the node reference, based on the GUID retrieved from WMI Set node = pmad.GetNode(szNodeGuid) '//This throws an error if no policies are installed. policylist = pmad.cvar(node.GetPolicyList) '//loop through the policy list For Each policyitemenum In policylist '//dim our local policy objects Dim latestpolicy Dim policyitem Dim policytype '//increment the policy count policycount = policycount + 1 ReDim Preserve szInstalledPolicyList(policycount) '//have to do this rather than using policyitem in enumeration. Set policyitem = policyitemenum '//get the policytype object Set policytype = policyitem.GetPolicyType '//Build a text name list. szInstalledPolicyList(policycount) = "CURRENTLY INSTALLED: " & policyitem.GetName & " " & policyitem.GetVersionString & " " & policytype.GetName(1) wscript.echo szInstalledPolicyList(policycount) '//get the latest version of the policy we found Set latestpolicy = policyitem.GetLatestVersion If policyitem.GetVersionString <> latestpolicy.GetVersionString Then Dim latestpolicytype '//increment the count updatedpolicycount = updatedpolicycount + 1 '//redimension the array with one more item ReDim Preserve szUpdatedPolicyList(updatedpolicycount) '//get the policytype object Set latestpolicytype = latestpolicy.GetPolicyType '//Build a text name list. szUpdatedPolicyList(updatedpolicycount) = "UPDATED TO:" & latestpolicy.GetName & " " & latestpolicy.GetVersionString & " " & latestpolicytype.GetName(1) wscript.echo szUpdatedPolicyList(updatedpolicycount) szNodeGuidArray = Array(szNodeGuid) 'NodeGuid '//Deploy on the node. latestpolicy.DeployOnNodes szNodeGuidArray, True, True '//destroy the policytype object Set latestpolicytype = Nothing End If '//destroy the policy objects, and move on. Set policytype = Nothing Set latestpolicy = Nothing Set policyitem = Nothing '//loop to the next item in the policy list Next Else wscript.echo "node not found or invalid, or cannot connect to database!" End If '//destroy the connection to PMAD! Set node = Nothing Set pmad = Nothing