Gpo et vbscript

ismfou Messages postés 11 Date d'inscription dimanche 1 février 2009 Statut Membre Dernière intervention 11 mai 2009 - 29 avril 2009 à 01:23
cs_ElDentiste Messages postés 3 Date d'inscription jeudi 30 avril 2009 Statut Membre Dernière intervention 4 mai 2009 - 30 avril 2009 à 10:48
Bonsoir,
voila je travaille sur une application en C# qui gère
l'active directory  et les GPO , et mon probleme c que jai pas put
coder des script qui gere les gpo en C# ou en VB.net tous ce que jai
trouvé c en VBscript que je ne comprend rien du tou , je vous demande
bien de m'aidé sur sa ou d'essay de me faire comprendre ce script que
jai ramené de  msdn qui fais la relation entre une OU  et les gpo ,
tout aide mes indesponssable et favorable merci voici le script
.  et si il ya une methode pr importe du vbscript en C# jaimerai bien la conetre
merci
This code links a GPO to an OU in the specified domain

' ------ SCRIPT CONFIGURATION -----

strDomainDN = "<tt><DomainDN>
</tt>
" ' e.g. dc=adatum,dc=com

strGPO = "<tt><GPOName>
</tt>
" ' e.g. WorkstationsGPO

strOUDN = "<tt><OrgUnitDN>
</tt>
" ' e.g. ou=Workstations,dc=adatum,dc=com

' ------ END CONFIGURATION --------

strBaseDN = "<LDAP://cn=policies,cn=system,dc=" & strDomainDN & ">;"

strFilter = "(&(objectcategory=grouppolicycontainer)" & _

"(objectclass=grouppolicycontainer)" & _

"(displayname=" & strGPO & "));"

strAttrs = "ADsPath;"

strScope = "OneLevel"

set objConn = CreateObject("ADODB.Connection")

objConn.Provider = "ADsDSOObject"

objConn.Open "Active Directory Provider"

set objRS = objConn.Execute(strBaseDN & strFilter & strAttrs & strScope)

if objRS.EOF <> TRUE then

objRS.MoveFirst

end if

if objRS.RecordCount = 1 then

strGPOADsPath = objRS.Fields(0).Value

WScript.Echo "GPO Found: " & strGPOADsPath

elseif objRS.RecordCount = 0 then

WScript.Echo "Did not founding matching GPO for: " & strGPO

Wscript.Quit

elseif objRS.RecordCount > 1 then

WScript.Echo "More than 1 GPO found matching: " & strGPO

Wscript.Quit

end if

set objOU = GetObject("LDAP://" & strOUDN)

on error resume next

strGPLink = objOU.Get("gpLink")

if Err.Number then

if Err.Number <> -2147463155 then

WScript.Echo "Fatal error while retrieving gpLink attribute: " & _

Err.Description

Wscript.Quit

end if

end if

on error goto 0

objOU.Put "gpLink", strGPLink & "[" & strGPOADsPath & ";0]"

objOU.SetInfo

WScript.Echo "GPO successfully linked"

' The following code segment will remove any GPOs that

' are linked to an OU

Const ADS_PROPERTY_CLEAR = 1

Set objContainer = GetObject _

("LDAP://<<tt>OU DN
</tt>
>") ' i.e. "ou=Finance,dc=adatum,dc=com"

objContainer.PutEx ADS_PROPERTY_CLEAR, "gPLink", 0

objContainer.PutEx ADS_PROPERTY_CLEAR, "gPOptions", 0

objContainer.SetInfo

1 réponse

cs_ElDentiste Messages postés 3 Date d'inscription jeudi 30 avril 2009 Statut Membre Dernière intervention 4 mai 2009
30 avril 2009 à 10:48
Bonjour,

Je suis clairement pas un expert, mais je peux t'indiquer une aide non négligeable : script center.chm de Microsoft.
Tu retrouveras énormément d'exemples des scripts vbs pour toutes les fonctions, dont l'AD et notamment les OU.
Ca vaut le coup d'oeil si tu dois faire du vbs.

http://www.microsoft.com/downloads/details.aspx?FamilyID=b4cb2678-dafb-4e30-b2da-b8814fe2da5a&DisplayLang=en
0
Rejoignez-nous