VBS 스크립팅 - samAccountName을 사용하여 LDAP 사용자 개체에 액세스

VBS 스크립팅 - samAccountName을 사용하여 LDAP 사용자 개체에 액세스

두 가지 요구 사항을 충족하는 VBScript를 작성하려고 합니다.

  1. 사용자 계정의 잠금을 해제합니다.
  2. 그렇게 하고 samAccountName을 사용하여 사용자를 참조할 수 있습니다.

# 1이 작동합니다. 그러나 제가 작업한 아래 스크립트는 사용자의 전체 AD 이름만 참조합니다.

' UnlockUserAccount.vbs
Option Explicit

'Get the arguments
dim oArgs, strUser, strContainer
set oArgs = WScript.Arguments
strUser = "CN=" & trim(oArgs(0)) & "," 
strContainer = "OU=User Accounts,OU=Staff,OU=Org," 

' Bind to Active Directory and get the user object
dim objRootLDAP, objUser
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objUser = GetObject("LDAP://" & strUser & strContainer & objRootLDAP.Get("defaultNamingContext"))

'Unlock the user's account
objUser.IsAccountLocked = False
objUser.SetInfo

Wscript.Quit(1)

예를 들어, 전체 이름이 Bill Smith인 사용자 'bsmith'가 있다고 가정합니다.

이 스크립트를 호출하고 "Bill Smithi"를 사용자로 전달해야만 작동되도록 할 수 있습니다.

"bsmith"를 전달하는 사용자를 어떻게 참조합니까? 나는 이것을 이해할 수 없다.

답변1

VBS는 거의 쓸모가 없으므로 PowerShell에서 시도해 보는 것이 좋습니다. get-aduser 및 set-aduser를 사용하면 거의 간단합니다. 이 시도:

 get-aduser bsmith |Unlock-ADAccount

관련 정보