Can I somehow check which user/samaccountname was last logged on a list of PCs, if I have the PC names from AD?
I tried:
$TargetName = “W7XXXXXXXXXX”
$RC = Get-WinEvent -Computer
$TargetName -FilterHashtable @{ Logname = ‘Security’; ID = 4672 } -MaxEvents 1 | Select @{ N = ‘User’; E = { $_.Properties[1].Value } }, TimeCreated$RC.Username$RC.TimeCreated
Error is Unexpected token -FilterHashtable
This needs to be on one Line:
$RC = Get-WinEvent -ComputerName $TargetName -FilterHashtable @{ Logname = ‘Security’; ID = 4672 } -MaxEvents 1 | Select @{ N = ‘User’; E = { $_.Properties[1].Value } }, TimeCreated$RC.Username$RC.TimeCreated
or add " ` "
$TargetName = "qa-man01-vm"
$RC = Get-WinEvent -ComputerName `
$TargetName -FilterHashtable @{ Logname = ‘Security’; ID = 4672 } -MaxEvents 1 | Select @{ N = ‘User’; E = { $_.Properties[1].Value } }, TimeCreated$RC.Username$RC.TimeCreated
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.