Back to User management: Provision
DESCRIPTION
This script sample demonstrates how to programmatically populate an existing PVG policy with a possible values list from a external text file.
N.B. It is not an ARS script policy, but external script that works with ARS.
Note This code may use functions from the ARS Script Policy Best Practices. Please, follow the link to obtain instructions and code for those functions.
SCRIPT
'*********************************************************************************
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
' PLEASE CONTACT QUEST PROFESSIONAL SERVICES.
'*********************************************************************************
'
' This code is published on the ActiveRoles Script Center:
' http://communities.quest.com/docs/DOC-9991
'
' This code may use functions from the ARS Script Policy Best Practices:
' http://communities.quest.com/docs/DOC-10016
'
' Please, follow the link to obtain instructions and code for those functions.
'*********************************************************************************
Option Explicit
'--- Custimizable settings. You should modify it ------------
Const strClassName = "user" ' - class: User
Const strAttribName = "l" ' - attribute: City
Const strPolicyObjectDN = "CN=Sample Policy,CN=Policy Objects,CN=Configuration"
'--- ARS specific constants -----------
Const EDS_APE_TYPE_PV = 35
'--- variables ------------------------
Dim objFSO, objFile, strLine, strXML
Dim objPolicy, objEntry, objSetting
Dim boolEntryFound
'--- MAIN ROUTINE ---------------------
' - open a text file that have lines with values
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\source.txt", 1, False)
' - read lines from the file and construct a XML for PVG policy
strXML = "<PVGRules Version=""1.0""><PVRuleItem operator=""=="" linkID=""and"">"
Do While (Not objFile.AtEndOfStream)
strLine = objFile.ReadLine()
strXML = strXML & "<value linkID=""or"" displayName="""">" & strLine & "</value>"
Loop
strXML = strXML & "</PVRuleItem></PVGRules>"
' - bind to the specified policy object
Set objPolicy = GetObject("EDMS://" & strPolicyObjectDN)
boolEntryFound = False
' - itterate all entries in the policy object
For Each objEntry In objPolicy
' - if an entry is PVG policy for the specified attribute of the specified class
If ((objEntry.Type = EDS_APE_TYPE_PV) And _
(objEntry.Item(50) = strClassName) And _
(objEntry.Item(40) = strAttribName)) Then
' - remove administrative note & possible values list
objEntry.RemovePolicySettingByName(67)
objEntry.RemovePolicySettingByName(2)
' - add new possible values list
Set objSetting = objEntry.CreatePolicySetting()
objSetting.SettingID = 2
objSetting.Value = strXML
objEntry.AddPolicySetting(objSetting)
boolEntryFound = True
End If
Next
If (Not boolEntryFound) Then
MsgBox "Error: No PVG policy entry found for " & strClassName & " class and " & strAttribName & " attribute!"
Else
' - apply changes
objPolicy.SetInfo
MsgBox "Done!"
End If
'***** END OF CODE ***************************************************************
COMPATIBILITY
Script compatible with the following version(s): <Not specified>