Trying to Exclude DefaultUser0 from my lastlogon user script

Winston Willocks 1 Reputation point

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Denis Hotescu 1 Reputation point

    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.

    0 comments No comments