AD 登陆脚本 获取计算机信息与用户登陆时间

我如何实现这个效果呢?(黄色标记部分)

image.png

1、开启高级功能

image.png

2、选择 Computer,属性

image.png

3、安全,Authenticated User,高级

image.png

4、Authenticted Users,编辑

image.png

5、选择,应用于后代计算机对象

image.png

6、写入描述,确定,确定,确定

image.png

7,新建(组织单位,名字随你);连接现有GPO(选择,Default Policy);

用户配置,Windows设置,(脚本)登陆/注销

选择(登陆),添加…浏览

image.png

8、新建文本(名字随意),改扩展名为VBS(TXT To VBS),并选择

image.png

9、重点 VBS的脚本,将内容复制到VBS里面

'On Error Resume Next


Set objSysInfo = CreateObject("ADSystemInfo")


Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)


Set objUser = GetObject("LDAP://" & objSysInfo.UserName)


If left(objComputer.description,1) = "`" Then


'If a tilda exists the script will terminate. This allows custom


' descriptions that dont get overwritten.


Wscript.Quit


Else


'Sets variables for Computer name, Manufacturer, Model,


' and Serial number


strComputer = "."


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colComputerSystem = objWMIService.ExecQuery ("Select * from Win32_computersystem")


Set colBIOS = objWMIService.ExecQuery ("Select * from Win32_BIOS")


For each objComputerSystem in colComputerSystem


GetComputerManufacturer = objComputerSystem.Manufacturer


GetComputerModel = objComputerSystem.Model


Next


For each objBIOS in colBIOS


GetSerialNumber = objBIOS.SerialNumber


Next


'String cleaning - Manufacturer includes only first word, and


' the serial removes any spaces.


txtCount = InStr(GetComputerManufacturer," ") - 1


GetComputerManufacturer = Left(GetComputerManufacturer,txtCount)


GetSerialNumber = Replace(GetSerialNumber, " ", "")


'Below are two variants in building the final string. Please chose which


' you prefer. I did read but could not validate that excessive computer description


' changes can cause AD change limits to be reached.


'First one is without dates and second is with dates. Below ar examples. The


' string is also trimmed to 1024 characters as per AD schema req (just in case)


'### DESCRIPTION WITH DATE ###


'Example:


'John Doe (jdoe) - Dell Optiplex 990 - DRP421S


strDate = Now & " | "


strCompDesc = strDate & objUser.SAMAccountName & " | " & objUser.CN & " | " & GetComputerManufacturer & " " & GetComputerModel & " | " & GetSerialNumber


strCompDesc = Left(strCompDesc,1024)


'Compares AD string and generated string and skips if they are


' identical. This saves AD change count.


If strCompDesc = objComputer.description Then


wscript.Quit


Else


objComputer.Description = strCompDesc


objComputer.SetInfo


End If


End If

10、应用,确认。

image.png

11、服务器上,强制性刷新组策略(gpupdate /force

image.png

12、登陆你的计算机,做测试

image.png

13、Done,假设这个脚本,是需要哪个用户登陆了那部机子,以便更好的管理。

脚本的管理与建设都可以多样化,这个就随你啦,谢谢大家。

image.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章