Wednesday, July 14, 2010

Home /PowerShell /SamAccountName /script /Windows /Windows 2008 R2 /Windows 7 / Last Logged-On User / DefaultUserName – PowerShell Script

Last Logged-On User / DefaultUserName – PowerShell Script

This script generates Last Logged-On User / DefaultUserName information from an input file (input.csv) which contains computer names.

image

Input file (input.csv) contains all computer names.  “ComputerName” header is a requirement. 

image

Output file

UserInfo.csv – contains computer names and corresponding SamAccountNames

image

FailedCompuers.csv – Script verifies admin$ access. If the access fails, it will be added to the FailedComptuers.csv file.

This script also displays the output on the screen.

image

You can download the script from the following location:

Last Logged-On User.PS1

SS

Santhosh Sivarajan

Microsoft MVP · Identity & Cybersecurity Architect

Santhosh has 30+ years of hands-on enterprise experience in Identity and Access Management, Microsoft Entra ID, Active Directory, Microsoft 365 and Zero Trust architecture. He is the author of two books on Windows Server and security, and leads consulting, assessments and training at SAG Business Group.

9 comments:

This is not generating a list of failed computers.

Something wrong with your input file or the script. Post the input file and script here.

can you post a sample input file...i have tried many times with no success and I am sure the error is with the input file

This is how the input file should look like;
(the very first line should be ComputerName)

ComputerName
PCName1
PCName2
PCName3

justin,
Sorry. Somehow I missed your comment. I have updated the blog with a sample input file.

Karloz GtR,
Thanks for providing information. Please let me know if you are interested in becoming a moderator in the SS Technology forum - http://www.sivarajan.com/forum/

It works perfectly for WindowsXP computers... but if fails for Windows 7... any idea?

What is the error message? Please post the error message here.

Karloz GtR,

I can verify that Windows 7 & Windows 2008 Server R2 have changed the path to the data to be:

[Subkey Path]
SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI

[Value Name]
LastLoggedOnUser

Post a Comment

Popular Posts
Workstation Trust Relationship Issue Issue: You receive the following error message, when you try to login to the domain.  The security database on the server does not have ... ADMT Service Account - Permission and Configuration The ADMT service account needs to have proper permission in source and target domains.  You don’t need to use 2 separate accounts.  You can ... My First Peek into Microsoft Exchange 2010 By Santhosh Sivarajan Before I really dive into Exchange 2010, I thought I would install and play with it first. I took some screen shots and notes during the ins... ObjectSID and Active Directory What is an objectSID in Active Directory? When a new object is created in Active Directory, Domain Controller assigns a unique value used ... AD Group Report - List Group Members in Active Directory–PowerShell Script Updated Script - http://portal.sivarajan.com/2011/10/search-ad-collect-local-admin-group.html Script #1 This script... Add Users to a Group–PowerShell Script Purpose – Add users to a group from an input file – PowerShell V2 Script.  Input file – Input file (Users.csv) contains samAccountName in... User Account Migration and Merging – Part I (ADMT) Part I - User Account Migration and Merging Using ADMT Part II - User Account Migration and Merging Using QMM pre-creating user account ... User Account Migration and Merging – Part II (Quest Migration Manager) Part I - User Account Migration and Merging Using ADMT Part II - User Account Migration and Merging Using QMM Pre-creating user account in... Delete Stale or Inactive Computer Accounts from Active Directory Here is an easy way to identify and delete inactive or stale computers in an Active Directory environment.  Using the dsquery command you c... Converting PowerShell (PS1) to EXE / Standalone Application As we know, there many applications available to convert a PowerShell file to a standalone executable file.  Based on my experience, PowerSh...