如何跟踪用户登录和注销 [英] How to track users logon and log off

查看:63
本文介绍了如何跟踪用户登录和注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在这个链接上找到了以下代码 https://4sysops.com/archives/track-user-logons-with-a-powershell-script/ [ ^ ]

代码:

hello,
I found the following code on this link https://4sysops.com/archives/track-user-logons-with-a-powershell-script/[^]
Code:

<#
Set-UserStatus.ps1
****************************************************************
* DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
* THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF    *
* YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
* DO NOT USE IT OUTSIDE OF A SECURE, TEST ENVIRONMENT.         *
****************************************************************
#>
 
Param(
[Parameter(Position=0)]
[ValidateSet("Logon","Logoff","Unknown")]
[string]$Status="Unknown"
)
 
#no spaces in the filter
[adsisearcher]$searcher="samaccountname=$env:username"
#find the current user
$find = $searcher.FindOne()
#get the user object
[adsi]$user = $find.Path
#define a string to indicate status
$note = "{0} {1} to {2}" -f (Get-Date),$status.ToUpper(),$env:computername
#update the Info user property
$user.Info=$note
#commit the change
$user.SetInfo()



我正在用我当前的AD帐户测试它但是不起作用。我创建了该策略,但我的计算机/用户也没有获得该策略。你能帮我个忙吗?感谢您的帮助。


I am testing it with my current AD account but does not work. I created the policy but my computer/user is not getting the policy neither. Can you guys give me a hand ? Thanks for your help.

推荐答案

Status =Unknown


#no过滤器中的空格
[adsisearcher]
Status="Unknown" ) #no spaces in the filter [adsisearcher]


searcher =samaccountname =
searcher="samaccountname=


env:username
#find当前用户
env:username" #find the current user


这篇关于如何跟踪用户登录和注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆