OVH Cloud OVH Cloud

Script AD

7 réponses
Avatar
Système
Bonjour,

Je voudrais créer un script qui m'indique dans quel conteneur est mon PC.

En général, après avoir installé et mis un PC dans le domaine, je les place
dans une OU (qui n'est pas la même pour tous les PC) afin de lui appliquer
des stratégies. Je voudrais créer un script, à lancer sur le PC client, qui
m'indique dans quel OU se trouve le PC.

Si vous avez une idée sur la manière de procéder, cela me rendrait un grand
service.

Merci pour votre aide.

7 réponses

Avatar
Sebastien M.
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage
Avatar
Système
J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage




Avatar
davidr
Ci-joint une fonction qui répond à tes besoins:

Function Transition
Set objNewOU = GetObject("LDAP://OU=Transition, DC=nafta, DC=mahle, DC=com")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & movingcpu &
",CN=Computers,DC=nafta,DC=mahle,DC=com", "CN=" & movingcpu)
objEShell.LogEvent 0, "Moved Computer Object to Transition OU. Computer
Name: " & movingcpu

end Fonction

a++

J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage









Avatar
Système
Bonjour,

Je ne veux pas déplacer un ordinateur, je veux savoir où il setrouve.

Cordialement.

"davidr" a écrit dans le message de news:

Ci-joint une fonction qui répond à tes besoins:

Function Transition
Set objNewOU = GetObject("LDAP://OU=Transition, DC=nafta, DC=mahle,
DC=com")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & movingcpu &
",CN=Computers,DC=nafta,DC=mahle,DC=com", "CN=" & movingcpu)
objEShell.LogEvent 0, "Moved Computer Object to Transition OU. Computer
Name: " & movingcpu

end Fonction

a++

J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage











Avatar
Système
Bonjour,

J'ai trouvé la fonction dont j'ai besoin.

Si ça peut intéresser quelqu'un :
********************************************************************************
strComputer = "ABCDEF"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select ADsPath from 'LDAP://DC=Societe,DC=com'
where objectClass='Computer' and Name = '" & strComputer & "'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = 2
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
strResult = objRecordSet.Fields("ADsPath").Value
WScript.Echo strResult
********************************************************************************

Merci à tous.



"davidr" a écrit dans le message de news:

Ci-joint une fonction qui répond à tes besoins:

Function Transition
Set objNewOU = GetObject("LDAP://OU=Transition, DC=nafta, DC=mahle,
DC=com")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & movingcpu &
",CN=Computers,DC=nafta,DC=mahle,DC=com", "CN=" & movingcpu)
objEShell.LogEvent 0, "Moved Computer Object to Transition OU. Computer
Name: " & movingcpu

end Fonction

a++

J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage











Avatar
davidr
ok, si tu veux j'ai cette fonction que tu peux utiliser pour tous les types
d'objets:

'********************************************************************
'* Function : GetDN(Object, ObjectType)
'* Purpose : This function retrieves the distinguished name of the object
'* It uses sDomain global variable
'*
'* Input : Name of the object and type of the object
'*
'* Output : string distinguished naming context of the user
'*
'********************************************************************
Function GetDN(Object, ObjectType)

On Error Resume Next

Dim dbConn, dbCmd, rs

'Create ADO connection object for Active Directory
Set dbConn = CreateObject("ADODB.Connection")
dbConn.Provider = "ADsDSOObject"
dbConn.Open

'Create ADO command object for the connection
Set dbCmd = CreateObject("ADODB.Command")
dbCmd.ActiveConnection = dbConn
dbCmd.CommandText = "select sAMAccountName,distinguishedname from 'LDAP://"
& sDomain & "' WHERE objectClass='" & ObjectType & "' AND sAMAccountName='" &
Object & "'"

'Execute the query
Set rs = dbCmd.Execute
While Not rs.EOF
GetDN = rs.Fields("distinguishedname")
rs.MoveNext
Wend
End Function



Bonjour,

J'ai trouvé la fonction dont j'ai besoin.

Si ça peut intéresser quelqu'un :
********************************************************************************
strComputer = "ABCDEF"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select ADsPath from 'LDAP://DC=Societe,DC=com'
where objectClass='Computer' and Name = '" & strComputer & "'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = 2
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
strResult = objRecordSet.Fields("ADsPath").Value
WScript.Echo strResult
********************************************************************************

Merci à tous.



"davidr" a écrit dans le message de news:

Ci-joint une fonction qui répond à tes besoins:

Function Transition
Set objNewOU = GetObject("LDAP://OU=Transition, DC=nafta, DC=mahle,
DC=com")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & movingcpu &
",CN=Computers,DC=nafta,DC=mahle,DC=com", "CN=" & movingcpu)
objEShell.LogEvent 0, "Moved Computer Object to Transition OU. Computer
Name: " & movingcpu

end Fonction

a++

J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage
















Avatar
davidr
ok, si tu veux j'ai une fonction qui permet de répondre pour tous types
d'objets:

'********************************************************************
'* Function : GetDN(Object, ObjectType)
'* Purpose : This function retrieves the distinguished name of the object
'* It uses sDomain global variable
'*
'* Input : Name of the object and type of the object
'*
'* Output : string distinguished naming context of the user
'*
'********************************************************************
Function GetDN(Object, ObjectType)

On Error Resume Next

Dim dbConn, dbCmd, rs

'Create ADO connection object for Active Directory
Set dbConn = CreateObject("ADODB.Connection")
dbConn.Provider = "ADsDSOObject"
dbConn.Open

'Create ADO command object for the connection
Set dbCmd = CreateObject("ADODB.Command")
dbCmd.ActiveConnection = dbConn
dbCmd.CommandText = "select sAMAccountName,distinguishedname from 'LDAP://"
& sDomain & "' WHERE objectClass='" & ObjectType & "' AND sAMAccountName='" &
Object & "'"

'Execute the query
Set rs = dbCmd.Execute
While Not rs.EOF
GetDN = rs.Fields("distinguishedname")
rs.MoveNext
Wend
End Function



Bonjour,

J'ai trouvé la fonction dont j'ai besoin.

Si ça peut intéresser quelqu'un :
********************************************************************************
strComputer = "ABCDEF"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select ADsPath from 'LDAP://DC=Societe,DC=com'
where objectClass='Computer' and Name = '" & strComputer & "'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = 2
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
strResult = objRecordSet.Fields("ADsPath").Value
WScript.Echo strResult
********************************************************************************

Merci à tous.



"davidr" a écrit dans le message de news:

Ci-joint une fonction qui répond à tes besoins:

Function Transition
Set objNewOU = GetObject("LDAP://OU=Transition, DC=nafta, DC=mahle,
DC=com")
Set objMoveComputer = objNewOU.MoveHere("LDAP://CN=" & movingcpu &
",CN=Computers,DC=nafta,DC=mahle,DC=com", "CN=" & movingcpu)
objEShell.LogEvent 0, "Moved Computer Object to Transition OU. Computer
Name: " & movingcpu

end Fonction

a++

J'avais déja cherché dans ces leins mais n'ai rien trouvé.

Merci.


"Sebastien M." a écrit dans le
message de news:
bonjour,
je ne pourrais pas de donner le script mais sur
http://www.microsoft.com/technet/scriptcenter/default.mspx
tu pourras surement le trouver ou au moins comment le réaliser?

bon courage