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


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