添加最后一个login到AD用户和计算机描述字段的用户

我工作的最后一个地方是在AD用户和计算机控制台中的每个计算机帐户的说明字段中的AD设置方式,它将说明谁最后login和何时login。 你如何设置它?

很可能,编辑该字段的权限被委派给用户,并且将通过GPO部署将写入该属性的login脚本。 没有内置的function来实现这一点。

这里有一个很早以前放在一起的用户login脚本,它将用户的login名,时间戳和IP地址添加到AD中计算机对象的描述中。 您可以按原样使用,或更改以适合您。 脚本执行后的说明…

On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") 'Bind to AD Set objNet = CreateObject("WScript.Network") strCompDN = objSysInfo.ComputerName 'DN for computer, eg "CN=VISTAWORKSTATION,OU=Child OU Name,OU=Parent OU Name,DC=domain,DC=com" Set objComp = GetObject("LDAP://" & strCompDN) 'IADsComputer object strUserDN = objSysInfo.UserName 'DN for user, eg "CN=John Smith,OU=Child OU Name,OU=Parent OU Name,DC=domain,DC=com" Set objUser = GetObject("LDAP://" & strUserDN) 'IADsUser object strUsrLogin = LCase(objNet.UserName) strNow = Now strDateStamp = DatePart("yyyy",strNow) & _ Right("0" & DatePart("m",strNow), 2) & _ Right("0" & DatePart("d",strNow), 2) & _ "@" & _ Right("0" & DatePart("h",strNow), 2) & _ Right("0" & DatePart("n",strNow), 2) 'RegExp object used to perform a simple match on IP address Set objRE = New RegExp objRE.IgnoreCase = True 'Note this regexp pattern isn't "correct" for matching an IPv4 address properly, but since WMI will return an 'array of IP addresses, this is sufficient to distinguish IPv4 vs IPv6 objRE.Pattern = "^\d+\.\d+\.\d+\.\d+$" strIP = "" 'Connect to WMI and retreive all network adapters Set objWMI = GetObject("winmgmts:") Set colNICs = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration") 'Get the IP(s) assigned to whichever network adapter has our default gateway If colNICs.Count > 0 Then For Each objNIC in colNICs If IsArray(objNIC.DefaultIPGateway) Then arrIP = objNIC.IPAddress For i = 0 To UBound(arrip) If objRE.Test(arrIP(i)) Then strIP = strIP & " " & arrIP(i) Next strMAC = objNIC.MACAddress End If Next End If strIP = Trim(strIP) objComp.Description = strDateStamp & " " & strUsrLogin & " " & strIP objComp.Put "extensionAttribute1", strUsrLogin objComp.Put "extensionAttribute2", strIP objComp.Put "extensionAttribute3", strMAC objComp.SetInfo 

将脚本保存在您的数据中心的SYSVOL共享位置。 然后使用组策略将其分配为用户login脚本。

最后,因为普通用户通常不能改变计算机对象的描述,所以你需要给他们许可,像这样:

  1. 打开AD用户和计算机。
  2. 右键单击左侧导航树中的yourdomain ,然后select委派控制。
  3. 控制向导代理出现。 点击下一步。
  4. 在用户或组页面上,添加“已validation的用户”,然后单击下一步。
  5. 在要委派的任务页上,select自定义任务选项,然后单击下一步。
  6. 在Active Directory对象types页面上,只select计算机对象,然后单击下一步。
  7. 在“权限”页面上,选中“属性专用”框,然后选中列表中相应的权限框:
    • 写描述
    • 写入extensionAttribute1
    • 写extensionAttribute2
    • 写extensionAttribute3
    • 写extensionAttribute4
    • 写extensionAttribute5
    • 写extensionAttribute6
    • 写extensionAttribute7
    • 写extensionAttribute8
    • 写入extensionAttribute9
    • 写extensionAttribute10
    • 写extensionAttribute11
    • 写extensionAttribute12
    • 写extensionAttribute13
    • 写extensionAttribute14
    • 写extensionAttribute15
  8. 点击下一步
  9. validation委派操作的摘要显示正确,然后单击完成。

添加到MarkM的答案 ,代表完成后,这样的VBScript将做你想要的:

 Set objADSystemInfo = CreateObject("ADSystemInfo") Set objLDAPComp = GetObject("LDAP://" & objADSystemInfo.ComputerName) objLDAPComp.Description = objADSystemInfo.UserName & " " & Now() objLDAPComp.SetInfo 

这将导致计算机的描述字段被设置为沿着
CN=Joe Blow,OU=The Users,DC=example,DC=com 6/2/2011 10:55:00 AM