Last logon user script, need to exclude some admin users

I created a last logon user script to use NTUser.dat file to tell me,who was the last user that logged on the computer, I need to know how to exclude some admin user in the script, please if someone could help? the script is below.

$compuers = Get-Content -path ‘C:\Users\Public\latlogon\computer.txt’

Write-Verbose “working on $computers” -Verbose

Invoke-Command -ComputerName $computers -ScriptBlock {Get-ChildItem “C:\Users*\AppData\Local\Microsoft\Windows\UsrClass.dat” -force |

Select-Object Directory, Lastwritetime -last 2} |

Select -property PSComputerName, Directory. Lastwritetime |

Export-CSV -Path C:\Users\Public\latlogon\LastLogon-Use.csv -NoTypeInformation

It is a little unclear what you’re actually after. Do you want to the last logged on user of the computer or do you want to have the times all users of a computer logged on last? :wink:

Here are a few links that might be helpful:

To exclude certain folders when listing folders with Get-ChildItem you can use the parameter -Exclude like this:

Get-ChildItem -Path "C:\Users\*\AppData\Local\Microsoft\Windows\UsrClass.dat" -Force -Exclude Administrator,User01,User3251

Regardless of all that - when you post code or error messages please format it as code using the preformatted text button ( </> ). Simply place the cursor on an empty line, click the button and paste your code.

Thanks in advance.