David Pekmez's Weblog

Unified Communications Blog

Articles reli´s: «:script»

Diagnostic Logging Exchange 2007

Posté par David PEKMEZ le août 17, 2008

 

Ce script vous permettra en quelques clics rapides d’activer ou désactiver le diagnostic level d’Exchange 2007

Source :
http://gsexdev.blogspot.com/2007/01/exchange-2007-diagnostic-logging.html

Téléchargement :
http://msgdev.mvps.org/exdevblog/diaglogv2.zip

Lancez le script et changer rapidement la configuration


David

Publié dans Exchange Server 2007, Powershell, script | Taggé: , , | Laisser un commentaire »

Export des utilisateurs Active Directory dans Excel

Posté par David PEKMEZ le août 17, 2008

Un petit script qui vous permettra facilement d’Exporter la liste des utilisateurs et leur propriétés dans Excel,

ce script peut très simplement être modifié suivant les informations que vous désirez remonter

‘—————————————————————-
‘  Name: Export_Users_to_Excel.vbs   
‘ Exporte les Utilisateurs AD vers Excel
‘ Pekmez David 21 Sept 2005.
‘  V2:
‘ - Optimisation de l’Autofit des cellules Excel
‘ - Enregistrement du fichier dans le répertoire courant
‘ v3:
‘ - Ajout du UserAccountControl: Enabled / Disabled
”—————————————————————–

DIM accountcontrol
Const ADS_SCOPE_SUBTREE = 2
Set objExcel = CreateObject(“Excel.Application”)
Set fso   = WScript.CreateObject(“Scripting.FileSystemObject”)
objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = “Liste des Comptes ” & ” le ” & FormatDateTime(now, vbLongDate)
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Font.Size = 10
objExcel.Cells(1, 1).Font.ColorIndex = 3

objExcel.Cells(2, 2).Value = “Last name”
objExcel.Cells(2, 2).Font.ColorIndex = 5
objExcel.Cells(2, 3).Value = “First name”
objExcel.Cells(2, 3).Font.ColorIndex = 5
objExcel.Cells(2, 4).Value = “samAccountName”
objExcel.Cells(2, 4).Font.ColorIndex = 5
objExcel.Cells(2, 5).Value = “Department”
objExcel.Cells(2, 5).Font.ColorIndex = 5
objExcel.Cells(2, 6).Value = “Phone number”
objExcel.Cells(2, 6).Font.ColorIndex = 5
objExcel.Cells(2, 7).Value = “Mail”
objExcel.Cells(2, 7).Font.ColorIndex = 5
objExcel.Cells(2, 8).Value = “userPrincipalName”
objExcel.Cells(2, 8).Font.ColorIndex = 5
objExcel.Cells(2, 9).Value = “distinguishedName”
objExcel.Cells(2, 9).Font.ColorIndex = 5
objExcel.Cells(2, 10).Value = “homeDirectory”
objExcel.Cells(2, 10).Font.ColorIndex = 5
objExcel.Cells(2, 11).Value = “homeDrive”
objExcel.Cells(2, 11).Font.ColorIndex = 5
objExcel.Cells(2, 12).Value = “canonicalName”
objExcel.Cells(2, 12).Font.ColorIndex = 5
objExcel.Cells(2, 13).Value = “scriptPath”
objExcel.Cells(2, 13).Font.ColorIndex = 5
objExcel.Cells(2, 14).Value = “userAccountControl”
objExcel.Cells(2, 14).Font.ColorIndex = 5
‘objExcel.Cells(2, 15).Value = “userAccountControl”
‘objExcel.Cells(2, 15).Font.ColorIndex = 5

‘ Connexion Active directory et selection des données

Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand =   CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”

‘ Remplacer & “‘LDAP://dc=INTRA,dc=NET’ WHERE ” le nom de domaine

Set objCommand.ActiveConnection = objConnection
objCommand.Properties(“Page Size”) = 100
objCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
    “SELECT givenName, SN, samAccountName, department, telephoneNumber, mail, userPrincipalName, distinguishedName, homeDirectory, homeDrive, canonicalName, scriptPath, userAccountControl FROM ” _
        & “‘LDAP://dc=INTRA,dc=NET‘ WHERE ” _
            & “objectCategory=’person’ AND objectClass=’user’ ORDER BY samAccountName”
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 3

‘ Export des données vers Excel

Do Until objRecordSet.EOF
    objExcel.Cells(x, 2).Value = _
        objRecordSet.Fields(“SN”).Value
    objExcel.Cells(x, 3).Value = _
        objRecordSet.Fields(“givenName”).Value
    objExcel.Cells(x, 4).Value = _
        objRecordSet.Fields(“samAccountName”).Value
    objExcel.Cells(x, 5).Value = _
        objRecordSet.Fields(“department”).Value
    objExcel.Cells(x, 6).Value = _
        objRecordSet.Fields(“telephoneNumber”).Value
    objExcel.Cells(x, 7).Value = _
        objRecordSet.Fields(“mail”).Value
    objExcel.Cells(x, 8).Value = _
        objRecordSet.Fields(“userPrincipalName”).Value
    objExcel.Cells(x, 9).Value = _
        objRecordSet.Fields(“distinguishedName”).Value
    objExcel.Cells(x, 10).Value = _
        objRecordSet.Fields(“homeDirectory”).Value
    objExcel.Cells(x, 11).Value = _
        objRecordSet.Fields(“homeDrive”).Value
    objExcel.Cells(x, 12).Value = _
        objRecordSet.Fields(“canonicalName”).Value
    objExcel.Cells(x, 13).Value = _
        objRecordSet.Fields(“scriptPath”).Value
accountcontrol = objRecordSet.Fields(“userAccountControl”).Value

‘ Status du compte (Activé ou désactivé)

   If accountcontrol AND 2 Then
objExcel.Cells(x, 14).Value = “Disabled”
    else  objExcel.Cells(x, 14).Value = “enabled”
    end if

    x = x + 1
    objRecordSet.MoveNext
Loop

objExcel.Columns(“B:N”).Select
objExcel.Selection.Columns.AutoFit
objExcel.Range(“A1″).Select

‘ Enregistrement du fichier en “Liste des comptes du Domaine.xls”
‘ Dans le répertorie courant

ExcelFile=getpath() & “Liste des comptes du domaine” & “.xls”
If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile, true
objExcel.ActiveWorkbook.SaveAs ExcelFile
objExcel.ACtiveWorkbook.Saved = True
Wscript.quit

‘——————————————————————–
Fonction de récupération du répertoire courant
Function GetPath()
Dim path
path = WScript.ScriptFullName
GetPath = Left(path, InStrRev(path, “\”))
End Function
‘——————————————————————–

Publié dans Active Directory, script | Taggé: , | Laisser un commentaire »

Comment trouver les rôles FSMO ?

Posté par David PEKMEZ le août 17, 2008

Voici un script en vbs qui vous permettra d’économiser quelques  clics de souris :)

 Set objRootDSE = GetObject(“LDAP://rootDSE“)
 
Set objSchema = GetObject _
    (“LDAP://” & objRootDSE.Get(“schemaNamingContext”))
strSchemaMaster = objSchema.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strSchemaMaster)
Set objComputerSchema = GetObject(objNtds.Parent)
 
Set objNtds = Nothing
Set objComputer = Nothing
 
Set objPartitions = GetObject(“LDAP://CN=Partitions,” & _
    objRootDSE.Get(“configurationNamingContext”))
strDomainNamingMaster = objPartitions.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strDomainNamingMaster)
Set objComputerNaming = GetObject(objNtds.Parent)
 
Set objDomain = GetObject _
    (“LDAP://” & objRootDSE.Get(“defaultNamingContext”))
strPdcEmulator = objDomain.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strPdcEmulator)
Set objComputerPDC = GetObject(objNtds.Parent)
 
Set objRidManager = GetObject(“LDAP://CN=RID Manager$­,CN=System,” & _
    objRootDSE.Get(“defaultNamingContext”))
strRidMaster = objRidManager.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strRidMaster)
Set objComputerRID = GetObject(objNtds.Parent)
 
Set objInfrastructure = GetObject(“LDAP://CN=Infrastructure,” & _
    objRootDSE.Get(“defaultNamingContext”))
strInfrastructureMaster = objInfrastructure.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strInfrastructureMaster)
Set objComputerInfra = GetObject(objNtds.Parent)

MsgBox “Forest-wide Schema Master FSMO (Contrôleur de schéma): ” & replace(objComputerSchema.Name,”CN=”,”",vbtextcompare) & vbcrlf _
& “Forest-wide Domain Naming Master FSMO (Maitre d’attribution des noms de domaine): ” & replace(objComputerNaming.Name,”CN=”,”",vbtextcompare) & vbcrlf _
& “Domain’s PDC Emulator FSMO (Emulateur PDC): ” & replace(objComputerPDC.Name,”CN=”,”",vbtextcompare) & vbcrlf _
& “Domain’s RID Master FSMO (Maître RID): ” & replace(objComputerRID.Name,”CN=”,”",vbtextcompare) & vbcrlf _
& “Domain’s Infrastructure Master FSMO (Maître d’infrastructure ): ” & replace(objComputerInfra.Name,”CN=”,”",vbtextcompare) & vbcrlf,vbinformation,”Rôles FSMO”

David

Publié dans Active Directory, script | Taggé: , | Laisser un commentaire »