作成 2010.01.07
更新 2010.01.07
VBScript で Active Directory ユーザーの追加
このサンプルでは ADSI を使用してユーザーを追加します。指定したOUがなければ実行エラーになります。
Option Explicit
Const CstrDomain = "example.lan"
Const CstrOUDN = "OU=people,DC=example,DC=lan"
Const CstrUserName = "testuser"
Const CstrPassword = "P@ssw0rd"

Const UF_SCRIPT = &H1
Const UF_ACCOUNT_DISABLE = &H2
Const UF_HOMEDIR_REQUIRED = &H8
Const UF_ACCOUNT_LOCKOUT = &H10
Const UF_PASSWORD_NOT_REQD = &H20
Const UF_PASSWORD_CANT_CHANGE = &H40
Const UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H80
Const UF_DONT_EXPIRE_PASSWORD = &H10000

fUserAdd CstrDomain, CstrOUDN, CstrUserName, CstrPassword
WScript.Echo "end"

Function fUserAdd( strDomain, strOUDN, strUserName, strPassword )
  Dim adsOU
  Dim adsUser
  Dim userFrags
  Set adsOU = GetObject( "LDAP://" & strOUDN )
  Set adsUser = adsOU.Create( "user", "cn=" & strUserName )
  adsUser.Put "sAMAccountName", strUserName
  adsUser.Put "userPrincipalName", strUserName & "@" & strDomain
  adsUser.SetInfo
  adsUser.GetInfo
  adsUser.SetPassword strPassword
  adsUser.IsAccountLocked = False
  adsUser.AccountDisabled = False
  adsUser.SetInfo
  ' パスワードを無期限、パスワード変更不可
  userFrags = adsUser.Get("userAccountControl")
  userFrags = userFrags Or UF_DONT_EXPIRE_PASSWORD
  userFrags = userFrags Or UF_PASSWORD_CANT_CHANGE
  adsUser.Put "userAccountControl", userFrags
  adsUser.SetInfo
  fUserAdd = True
End Function
参考

VBScript で Active Directory ユーザーの削除 | IADsContainer インターフェース | IADsUser インターフェース


©2004-2017 UPKEN IPv4