
我正在尋找一種查詢 Active Directory 或 SMS 或其他內容的方法,以便獲得已登入多個伺服器的 Windows 伺服器的使用者清單。這就像檢查 Linux 上的 Lastlog 檔案一樣。除了用戶名之外,我不需要時間或其他任何東西。
輸出就像這樣簡單: SERVERNAME: shatnerw, nimoyl, kelleyd,
對此的任何意見都會很棒。即使是「在VB腳本中使用這個函數」。
謝謝,黑帽子
編輯:到目前為止,我發現該資訊位於登錄中的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList 中。它有很好的指南。現在我需要找到遠端查詢的方法。
答案1
如果您只想要設定檔列表,PowerShell 可能是您的最佳選擇。
$Server = 'RemoteServer'
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
這會將 $reg 實例化為 HKLM 中遠端登錄物件的持有者。要獲得您想要的部分:
$ProfileList = $Reg.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList')
這將使用設定檔本身的子項填入 $ProfileList。然後提取用戶列表:
Write-Host "`n$Server: " -nonewline
ForEach ($SID in $ProfileList.GetValueNames()) {
$ProfileKey = $ProfileList.OpenSubKey($SID)
# Get the ProfileImagePath key
$ProfileKey.GetValue("ProfileImagePath")
# Break the path up into an array, using \ as the delimiter
$PathBits = $ProfileKey.Split("\")
# The last element of the array is our user, find the last element
$LastIndex = $PathBits.Count - 1
# Dump the last element to something useful
$User = $PathBits[$LastIndex]
# Output the user
write-host " $User" -nonewline
}
或類似的東西。它超出了我的想像。
答案2
建立適用於要監視的伺服器的GPO,並在「電腦設定」>「策略」>「Windows 設定」>「安全性設定」>「本機原則」>「審核原則」下,根據您的要求在成功和/或失敗時啟用「審核登入事件」。
如果您監控的伺服器是 DC,請勿啟用審核帳戶登入事件。當有人使用其網域使用者帳戶登入時,網域控制站上會產生帳戶登入事件,因此您會看到太多事件。
簡而言之,當使用者登入電腦時會建立“登入事件”,當使用者使用其網域使用者帳戶登入但他們登入的電腦時,會在網域控制站上建立“帳戶登入事件”也以互動方式產生帳戶登入事件。這就是您想要監控的內容。與事件轉發(對於您有能力的伺服器)結合使用,您可以監控自己的事件日誌或使用 SNMP 陷阱來捕獲事件evntwin.exe
並將其轉發到 SNMP 監控/警報系統。
在使用者工作站上,我實際上使用 VBScript 來開啟一個隱藏的 IE 進程到安裝了 PHP/MySQL 的內部伺服器,它只是將使用者名稱轉儲到資料庫中,僅此而已。 VB 腳本:
Set oIE = CreateObject("InternetExplorer.Application")
Set oNet = CreateObject("WScript.Network")
sComputerName = oNet.ComputerName
sUsername = oNet.UserName
oIE.Navigate "http://intranet/logon/logon.php?un=" & Trim(sUsername) & "&ma=" & Trim(sComputerName)
Do While oIE.Busy = True
WScript.Sleep 500
Loop
oIE.Quit
Set oIE = Nothing
WScript.Quit
顯然,您需要 Web 伺服器、PHP 和 MySQL 資料庫來配合此操作,因此如果您對此感興趣,請告訴我,我也會挖掘這些內容。您也可以使用 GPO 應用此功能,但需要注意的是,它只能在 GPO 的「使用者設定」部分下運作。
所以,有兩個選擇供您選擇。 HTH。
編輯:這是上面提到的 PHP 腳本。真的很容易。
mysql_connect('mysqlserver', 'username', 'password');
mysql_select_db('database');
$un = trim(addslashes($_GET['un']));
$ma = trim(addslashes($_GET['ma']));
mysql_query("INSERT INTO userlist (user_logon_name, machine_name, logon_time) VALUES ('$un', '$ma', now())");
echo "User ". $_GET['un']. " logged on.";
乾杯