question

WinstonWillocks-9097 avatar image
0 Votes"
WinstonWillocks-9097 asked ·

Trying to Exclude DefaultUser0 from my lastlogon user script

I wrote a script to find the last logon users, I exclude public and DefaultUser0, it excluded the public, but not defaultuser0. How can I exclude the defaultuser0? below is the script

 $Computer = Get-Content -path "c:\Temp\computer.txt" 
 Invoke-Command -ComputerName $Computer -ScriptBlock {Get-ChildItem C:\Users Exclude 'Public','DefaultUser0' | Sort-Object LAstWriteTime -Descending | select-Object Name, LastWriteTime -Last 1} | Select-object -property PSComputerName, Name, LastwriteTime 



windows-server-powershell
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @WinstonWillocks-9097
Please use the "Code Sample" button or "Ctrl+K" to post your code. Thank you.

0 Votes 0 ·

1 Answer

DenisHotescu avatar image
0 Votes"
DenisHotescu answered ·

please format the script correctly
PS - you have a typo in:

 Get-ChildItem C:\Users Exclude 'Public','DefaultUser0'

You need to write -> "-Exclude"

 Get-ChildItem C:\Users -Exclude 'Public','DefaultUser0'

Other than that it shoudl work.







·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.