Meilleur auteur de réponses
Imprimantes et active directory

Question
-
Bonjour
Je voudrais nettoyer mon ad, car j'ai toujours des imprimantes qui apparaissent dans la liste de choix pour les utilisateurs, mais ces imprimantes ainsi que les ordinateurs qui les gérées ne sont plus sur le réseau depuis longtemps . AD 2003
D'avance merci
- Déplacé Dan BajenaruMicrosoft employee lundi 22 juillet 2013 15:37
lundi 22 juillet 2013 14:56
Réponses
-
Bonjour,
Pour savoir les ordinateurs inactif et les supprimer, vous pouvez combiner les commandes dsquery et dsrm:
dsquery computer –inactive i | dsrm -noprompt
i correspond au nombre de semaine , si vous souhaiter savoir la liste des computer inactif depuis un moi mettez 4 par exemple.
Pour avoir plus des détails veuillez consulter ce lien :
Best regards Bourbita Thameur Microsoft Certified Technology Specialist: Windows Server 2008 R2,Server Virtualizaton
- Proposé comme réponse LoicVeirman mardi 23 juillet 2013 09:41
- Marqué comme réponse Dan BajenaruMicrosoft employee mercredi 24 juillet 2013 12:48
lundi 22 juillet 2013 15:48
Toutes les réponses
-
Bonjour,
Pour savoir les ordinateurs inactif et les supprimer, vous pouvez combiner les commandes dsquery et dsrm:
dsquery computer –inactive i | dsrm -noprompt
i correspond au nombre de semaine , si vous souhaiter savoir la liste des computer inactif depuis un moi mettez 4 par exemple.
Pour avoir plus des détails veuillez consulter ce lien :
Best regards Bourbita Thameur Microsoft Certified Technology Specialist: Windows Server 2008 R2,Server Virtualizaton
- Proposé comme réponse LoicVeirman mardi 23 juillet 2013 09:41
- Marqué comme réponse Dan BajenaruMicrosoft employee mercredi 24 juillet 2013 12:48
lundi 22 juillet 2013 15:48 -
Attention avec cette commande, un utilisateur parti en vacances avec son PC éteins ou un pc portable qui ne se connecte que rarement au réseau et "pouf" voilà un objet qui vous posera des problèmes ! ne faite pas le dsrm sans un contrôle préalable (surtout en plein juillet !).
lundi 22 juillet 2013 20:17 -
Merci pour votre aide
mardi 23 juillet 2013 08:28 -
Bien sur je vai utiliser cette commande avec beaucoup de circonspection
merci a vous deux
mardi 23 juillet 2013 08:30 -
Bonjour
j'ai ce script qui vérifie les pc dans les OU respectifs et il les déplacent sans désactivation ni delete a vous de voir le details des pc sur vers une OU nommé "Inactive Computers" avec une durée de 90jours modifiable en vbs et a modifier le domain et vos OU
=====================
'this scirpt will allow you to target diffrent OUs within your domain to clean up obsolete computers. The
'script will identify and move comptuers. The disable function has been remed out so no action will be performed
'on the clients after they are moved. If you would like to disable accoutns, unrem objComputer.AccountDisabled = False
'and change to true
Option Explicit
Dim strFilePath, objFSO, objFile
Dim objShell, lngBiasKey, lngBias
Dim k, arrOUPaths, sOU
Dim intDays, strTargetOU, objTargetOU
Dim intTxxxl, intInactive, intNotMoved, intNotDisabled, strFilter, strquery, objComputer, strcomputerdn, objdate, dtmpwdlastset
'Update string of OUs the you would like to target
arrOUPaths = Array("OU=CDS,OU=XXX Computers,DC=domain,DC=com", "OU=Sites,OU=XXX Computers,DC=domain,DC=com")
' Specify the log file. This file will be created if it does not ' exist. Otherwise, the program will append to the file.
strFilePath = "c:\ADComputerCleanup\OldComputers.log"
' Specify the minimum number of days since the password was last set for ' the computer account to be considered inactive.
intDays = 90
' Specify the Distinguished Name of the Organizational Unit into ' which inactive computer objects will be moved.
strTargetOU = "ou=Inactive Computers,dc=domain,dc=COM"
' Bind to target Organizational Unit.
On Error Resume Next
Set objTargetOU = GetObject("LDAP://" & strTargetOU)
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Organization Unit not found: " & strTargetOU
Wscript.Quit
End If
On Error GoTo 0
' Open the log file for write access. Append to this file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFile = objFSO.OpenTextFile(strFilePath, 8, True, 0)
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "File " & strFilePath & " cannot be opened"
Set objFSO = Nothing
Wscript.Quit
End If
On Error GoTo 0
' Obtain local time zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
'Initialize txxxls.
intTxxxl = 0
intInactive = 0
intNotMoved = 0
intNotDisabled = 0
'Loop through array of OUPaths
For Each sOU In arrOUPaths
SearchOU sOU
Next
' Write txxxls to log file.
objFile.WriteLine "Finished: " & Now
objFile.WriteLine "Txxxl computer objects found: " & intTxxxl
objFile.WriteLine "Inactive: " & intInactive
objFile.WriteLine "Inactive accounts not moved: " & intNotMoved
objFile.WriteLine "Inactive accounts not disabled: " & intNotDisabled
objFile.WriteLine "----------------------------------------------"
' Display summary.
Wscript.Echo "Computer objects found: " & intTxxxl
Wscript.Echo "Inactive: " & intInactive
Wscript.Echo "Inactive accounts not moved: " & intNotMoved
Wscript.Echo "Inactive accounts not disabled: " & intNotDisabled
Wscript.Echo "See log file: " & strFilePath
' Clean up.
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing
Wscript.Echo "Done"
Function SearchOU(sOUPath)
Dim adoConnection, adoCommand, adoRecordset 'Dim objRootDSE, strDNSDomain Dim strFilter, strQuery, strComputerDN Dim objComputer, objDate, dtmPwdLastSet On Error Resume Next
' Use ADO to search the domain for all computers.
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOOBject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
' Determine the DNS domain from the RootDSE object.
'Set objRootDSE = GetObject("LDAP://RootDSE")
'strDNSDomain = objRootDSE.Get("DefaultNamingContext")
' Filter to retrieve all computer objects.
strFilter = "(objectCategory=computer)"
' Retrieve Distinguished Name and date password last set.
strQuery = "<LDAP://" & sOUPath & ">;" & strFilter _
& ";distinguishedName,pwdLastSet;subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Write information to log file.
objFile.WriteLine "Search for Inactive Computer Accounts"
objFile.WriteLine "Start: " & Now
objFile.WriteLine "Base of search: " & sOUPath
objFile.WriteLine "Log File: " & strFilePath
objFile.WriteLine "Inactive if password not set in days: " & intDays
objFile.WriteLine "Inactive accounts moved to: " & strTargetOU
objFile.WriteLine "----------------------------------------------"
' Enumerate all computers and determine which are inactive.
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
strComputerDN = adoRecordset.Fields("distinguishedName").Value
' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
strComputerDN = Replace(strComputerDN, "/", "\/")
intTxxxl = intTxxxl + 1
' Determine date when password last set.
Set objDate = adoRecordset.Fields("pwdLastSet").Value
dtmPwdLastSet = Integer8Date(objDate, lngBias)
' Check if computer object inactive.
If (DateDiff("d", dtmPwdLastSet, Now) > intDays) Then
' Computer object inactive.
intInactive = intInactive + 1
objFile.WriteLine "Inactive: " & strComputerDN _
& " - password last set: " & dtmPwdLastSet
' Move computer object to the target OU.
On Error Resume Next
Set objComputer = objTargetOU.MoveHere("LDAP://" _
& strComputerDN, vbNullString)
If (Err.Number <> 0) Then
On Error GoTo 0
intNotMoved = intNotMoved + 1
objFile.WriteLine "Cannot move: " & strComputerDN
End If
' Disable the computer account.
On Error Resume Next
'objComputer.AccountDisabled = False
' Save changes to Active Directory.
objComputer.SetInfo
If (Err.Number <> 0) Then
On Error GoTo 0
intNotDisabled = intNotDisabled + 1
objFile.WriteLine "Cannot disable: " & strComputerDN
End If
On Error GoTo 0
End If
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoConnection = Nothing
Set adoCommand = Nothing
'Set objRootDSE = Nothing
Set adoRecordset = Nothing
Set objComputer = Nothing
End Function
Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
' Account for bug in IADsLargeInteger property methods.
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
Integer8Date = CDate(lngDate)
End Function
Partager c'est avancer : Votez!SVP
- Modifié Nabil-IT mardi 23 juillet 2013 13:26 add in
mardi 23 juillet 2013 13:25