Home | Windows | Network | Interview Questions | Database | Virtualization | Knowledge Base | Contact Us

Quick Links

Windows 2003 KB

Windows 2008 KB

Network Int Ques

SQL Int Ques

Windows Int Q&A

Windows Forum

Other Links

DNS FAQ's

DHCP FAQ's

Active Directory FAQ's

AD History

Configuring New Domain

Deleted Object Recovery in AD

 

Global Catalog Server

NetDom Command

Replmon Command

NTDS Utility Guide

FSMO Guide

FSMO Failure

 

Network KB

Knowledge Base Home

Active Directory Trust

Group Policy Guide

IIS 6.0

RAID Levels

 

RPC Guide

Domain & Forest Functional Levels

SQL Failover Cluster

Hyper-V

Print Server

BitLocker

 

PowerShell

Creating Trust

Planning Trust

Windows Useful Scripts !

Joins the local computer to a domain and creates the computer’s account in Active Directory.

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
 
strDomain = “techiebird”
strPassword = “ls4k5ywA”
strUser = “shenalan”
 
Set objNetwork = CreateObject(“WScript.Network”)
strComputer = objNetwork.ComputerName
 
Set objComputer = GetObject(“winmgmts:{impersonationLevel=Impersonate}!\\” & _
    strComputer & “\root\cimv2:Win32_ComputerSystem.Name=’” & _
        strComputer & “‘”)
 
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
    strPassword, strDomain & “\” & strUser, NULL, _
        JOIN_DOMAIN + ACCT_CREATE)
 

Identifies the Active Directory domain controllers providing the five FSMO roles: Schema Master, Domain Naming Master, PDC Emulator, RID Master, and Infrastructure Master

Set objRootDSE = GetObject(“LDAP://rootDSE”)
 
Set objSchema = GetObject _
    (“LDAP://” & objRootDSE.Get(“schemaNamingContext”))
strSchemaMaster = objSchema.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strSchemaMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo “Forest-wide Schema Master FSMO: ” & objComputer.Name
 
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 objComputer = GetObject(objNtds.Parent)
WScript.Echo “Forest-wide Domain Naming Master FSMO: ” & objComputer.Name
 
Set objDomain = GetObject _
    (“LDAP://” & objRootDSE.Get(“defaultNamingContext”))
strPdcEmulator = objDomain.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strPdcEmulator)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo “Domain’s PDC Emulator FSMO: ” & objComputer.Name
 
Set objRidManager = GetObject(“LDAP://CN=RID Manager$,CN=System,” & _
    objRootDSE.Get(“defaultNamingContext”))
strRidMaster = objRidManager.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strRidMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo “Domain’s RID Master FSMO: ” & objComputer.Name
 
Set objInfrastructure = GetObject(“LDAP://CN=Infrastructure,” & _
    objRootDSE.Get(“defaultNamingContext”))
strInfrastructureMaster = objInfrastructure.Get(“fSMORoleOwner”)
Set objNtds = GetObject(“LDAP://” & strInfrastructureMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo “Domain’s Infrastructure Master FSMO: ” & objComputer.Name
 

Moves a computer account from the Computers container in Active Directory to the Finance OU in the same domain

Set objNewOU = GetObject(“LDAP://OU=Finance,DC=techiebird,DC=com”)

Set objMoveComputer = objNewOU.MoveHere _
    (“LDAP://CN=atl-pro-03,CN=Computers,DC=techiebird,DC=com”, “CN=atl-pro-03″)
 

Renames an Active Directory computer account

Set objNewOU = GetObject(“LDAP://OU=Finance,DC=techiebird,DC=com”)

Set objMoveComputer = objNewOU.MoveHere _
    (“LDAP://CN=atl-pro-037,OU=Finance,DC=techiebird,DC=com”, _
        “CN=atl-pro-003″)
 

Demonstration script that creates a security group named Group1, and adds one thousand users (UserNo1 through UserNo10000) to that group. This script is not intended for use in a production environment.

Const ADS_PROPERTY_APPEND = 3

Set objRootDSE = GetObject(“LDAP://rootDSE”)
Set objContainer = GetObject(“LDAP://cn=Users,” & _
    objRootDSE.Get(“defaultNamingContext”))
Set objGroup = objContainer.Create(“Group”, “cn=Group1″)
objGroup.Put “sAMAccountName”,”Group1″
objGroup.SetInfo

For i = 1 To 1000
    strDN = “,cn=Users,” & objRootDSE.defaultNamingContext
    objGroup.PutEx ADS_PROPERTY_APPEND, “member”, _
        Array(“cn=UserNo” & i & strDN)
    objGroup.SetInfo
Next
WScript.Echo “Group1 created and 1000 Users added to the group.”
 

Enumerates trust relationships.

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\\” & _
        strComputer & “\root\MicrosoftActiveDirectory”)

Set colTrustList = objWMIService.ExecQuery _
    (“Select * from Microsoft_DomainTrustStatus”)

For each objTrust in colTrustList
    Wscript.Echo “Trusted domain: ” & objTrust.TrustedDomain
    Wscript.Echo “Trust direction: ” & objTrust.TrustDirection
    Wscript.Echo “Trust type: ” & objTrust.TrustType
    Wscript.Echo “Trust attributes: ” & objTrust.TrustAttributes
    Wscript.Echo “Trusted domain controller name: ” & objTrust.TrustedDCName
    Wscript.Echo “Trust status: ” & objTrust.TrustStatus
    Wscript.Echo “Trust is OK: ” & objTrust.TrustIsOK
Next
 

Returns a list of pending replication jobs on a Domain Controller. 

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\\” & _
        strComputer & “\root\MicrosoftActiveDirectory”)

Set colReplicationOperations = objWMIService.ExecQuery _
        (“Select * from MSAD_ReplPendingOp”)

If colReplicationOperations.Count = 0 Then
    Wscript.Echo “There are no replication jobs pending.”
    Wscript.Quit
Else
    For each objReplicationJob in colReplicationOperations
        Wscript.Echo “Serial number: ” & objReplicationJob.SerialNumber
        Wscript.Echo “Time in queue: ” & objReplicationJob.TimeEnqueued
        Wscript.Echo “DSA DN: ” & objReplicationJob.DsaDN
        Wscript.Echo “DSA address: ” & objReplicationJob.DsaAddress
        Wscript.Echo “Naming context DN: ” & objReplicationJob.NamingContextDn
    Next
End If

Creates a new organizational unit within Active Directory

Set objDomain = GetObject(“LDAP://dc=techiebird,dc=com”)

Set objOU = objDomain.Create(“organizationalUnit”, “ou=Management”)
objOU.SetInfo

Changes the password for a user. Requires you to know the user’s previous password.

Set objUser = GetObject _
    (“LDAP://cn=myerken,ou=management,dc=techiebird,dc=com”)

objUser.ChangePassword “i5A2sj*!”, “jl3R86df”
 

Identifies the last time a user password was changed.

Set objUser = GetObject _
    (“LDAP://CN=myerken,OU=management,DC=techiebird,DC=com”)

dtmValue = objUser.PasswordLastChanged
WScript.Echo “Password last changed: ” & dtmValue
 

Returns basic account information for the MyerKen Active Directory user account

On Error Resume Next

Set objUser = GetObject _
    (“LDAP://cn=Myerken,ou=Management,dc=NA,dc=techiebird,dc=com”)
 
WScript.Echo “User Principal Name: ” & objUser.userPrincipalName
WScript.Echo “SAM Account Name: ” & objUser.sAMAccountName
WScript.Echo “User Workstations: ” & objUser.userWorkstations

Set objDomain = GetObject(“LDAP://dc=NA,dc=techiebird,dc=com”)
WScript.Echo “Domain controller: ” & objDomain.dc
 

Creates a user account in active directory. This script only creates the account, it does not enable it.

Set objOU = GetObject(“LDAP://OU=management,dc=techiebird,dc=com”)

Set objUser = objOU.Create(“User”, “cn=MyerKen”)
objUser.Put “sAMAccountName”, “myerken”
objUser.SetInfo

HTML Comment Box is loading comments...

Home | Windows | Network | Post Ur Issues | Database| Knowledge Base | Contact Us


Designed by TechieBird