Changes

WPKG with Active Directory

3,031 bytes added, 09:32, 9 August 2011
Multiple Profile Method: new code - insert additional manual profiles
' Modifed by: Marc Ozin
' Modified Date: 2010-03-02
 
' Modification:
' Hosts generated with multiple Profile-IDs to show each sub OU the Host resides within.
' e.g. if Computer1 is contained within Head-Office/Finance/Payroll the following Profile-IDs will be generated:
' <host name="Computer1" >' <profile-id="/root"/>' <profile -id="/root/Head-Office" />' <profile -id="/root/Head-Office/Finance" />' <profile -id="/root/Head-Office/Finance/Payroll" />
' </host>
' Modifed by: Marc Ozin' Modified Date: 2011-08-09' Modification:' after compiling profiles from AD, any computers listed that also exist in the hosts-manual.xml file have extra profiles attached.' the format of the hosts-manual.xml is as follows:' <wpkg>' <profile>' <profile id="manualprofile1">' <host name="computer1"/>' <host name="computer2"/>' <host name="computer3"/>' </profile>' <profile id="manualprofile2">' <host name="computer1"/>' <host name="computer4"/>' <host name="computer6"/>' </profile>'</wpkg>
Const ADS_SCOPE_SUBTREE = 2
Const VBquot = """"
Const ManualHostFile = "hosts-manual.xml"
Const wpkgPath = "\\myserver\wpkg$"
 
Dim objProfileNodes, ProfileNodeItem, objHostNodes
 
set fs = CreateObject("Scripting.FileSystemObject")
set textstream = fs.CreateTextFile(wpkgPath & "\hosts.xml", True)
textstream.WriteLine "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf
textstream.WriteLine "<!-- automagically generated with " & Wscript.ScriptFullName
textstream.WriteLine "</wpkg>"
textstream.close
Wscript ' * Add manual entries from hosts-manual.Echo xml ************************************************************************************************************* if bFileExists(wpkgPath & "Finished\" & ManualHostFile) then Set objDOMHosts = CreateObject("Microsoft.XMLDOM") objDOMHosts.async = false objDOMHosts.load(wpkgPath & "\hosts.xml") Set objDOMHostsManual = CreateObject("Microsoft.XMLDOM") objDOMHostsManual.async = False objDOMHostsManual.load(wpkgPath & "\" & ManualHostFile)   Set objProfileNodes = objDOMHostsManual.documentElement.childNodes  For Each ProfileNodeItem In objProfileNodes if ProfileNodeItem.nodeName = "profile" then' wscript.echo ProfileNodeItem.getAttribute("id") Set objHostNodes = ProfileNodeItem.childNodes For Each HostNodeItem In objHostNodes' wscript.echo HostNodeItem.getAttribute("name") strXPath = "/wpkg/host[@name='" & HostNodeItem.getAttribute("name") & "']" Set objParentNode = CreateObject("Microsoft.XMLDOM") set objParentNode = objDOMHosts.selectSingleNode(strXPath) AddProfile objParentNode, ProfileNodeItem.getAttribute("id") next end if Next  objDOMHosts.save(wpkgPath & "\hosts.xml") end if  ' * Subs & Functions *************************************************************************************************************  sub AddProfile(objParentNode, strValue) Dim objDOMHosts, objNode, strName, objAttrib Set objDOMHosts = CreateObject("Microsoft.XMLDOM") Set objNode = objDOMHosts.createElement("Profile") objNode.setAttribute "id", strValue objParentNode.appendChild objNodeEnd sub  Function bFileExists(strFile) set objFSO = createobject("Scripting.FileSystemObject") bFileExists = objFSO.FileExists(strFile) end function
</source>
You'll need to edit the line:<source lang="vb">Const wpkgPath = "\\myserver\wpkg$"</source>...replacing it with the path to your wpkg folder.
Don't forget you'll need to create a profile definition in the profiles.xml for all of the profiles that this script will create!
This version also allows you to build manual profile entries as well.
to use additional manual profiles, create a file called hosts-manual.xml in the wpkg folder like this:
<source lang="xml">
<wpkg>
<profile>
<profile id="manualprofile1">
<host name="computer1"/>
<host name="computer2"/>
<host name="computer3"/>
</profile>
<profile id="manualprofile2">
<host name="computer1"/>
<host name="computer4"/>
<host name="computer6"/>
</profile>
</wpkg>
</source>
[[category:Documentation]]
[[category:Installation]]
73
edits