Local User Account yaratmak ve Gruba eklemek (Script-1)

13 Ekim 2010 Çarşamba

Bazı durumlarda client’lar üzerinde yeni bir local user account (yerel kullanıcı hesabı) yaratıp, bu hesabı ilgili gruba üye yapmamız gerekebilir. Domain user account yaratmak kolaydır çünkü active directory üzerinde oluşturduğumuz domain user account, eğer aksi bir ayar yok ise organizasyon içerisindeki tüm client’larda oturum açabilir. Ama söz konusu local user account ise, bu hesabın her bir client üzerinde tek tek yaratılması gerekir. Bu gibi durumlarda kolaylık olması için aşağıdaki script’i kullanabilirsiniz.

Bu script sayesinde bilgisayar üzerinde yeni bir local user account yaratılmış, bu local user account’a bir password atanmış ve account ilgili gruba member edilmiş olur. Bununla birlikte account için “password never expires” ayarıda enable olur yani password süresiz olarak geçerlidir.

Script’i asagidaki gibi çalıştırabilirsiniz.

specify account to create
strAccount = “ercumentt”
strPswd = “12345test”

‘ get local computer name
Set objNetwork = CreateObject(“Wscript.Network”)
strComputer = objNetwork.ComputerName

‘ check if local account already exists
intExists = 0
Set colAccounts = GetObject(“WinNT://” & strComputer & “”)
colAccounts.Filter = Array(“user”)
For Each objUser In colAccounts
    If objUser.Name = strAccount Then
     intExists = 1
  End If
Next

If intExists = 0 Then
   ‘ create local user
   Set colAccounts = GetObject(“WinNT://” & strComputer & “”)
   Set objUser = colAccounts.Create(“user”, strAccount)

   ‘ set pswd
   objUser.SetPassword strPswd
   objUser.SetInfo

   ‘ set pswd never expires
   Set objUser = GetObject(“WinNT://” & strComputer & “/” & strAccount & “,User”)
   objUserFlags = objUser.Get(“UserFlags”)
   objPasswordExpirationFlag = objUserFlags Or ADS_UF_DONT_EXPIRE_PASSWD
   objUser.Put “userFlags”, objPasswordExpirationFlag
   objUser.SetInfo

   ‘ add to local admins group
   Set objGroup = GetObject(“WinNT://” & strComputer & “/Administrators,group”)
   Set objUser = GetObject(“WinNT://” & strComputer & “/” & strAccount & “,user”)
   objGroup.Add(objUser.ADsPath)
End If


Share/Bookmark

0 comments :