Remotely query user profile information with PowerShell

The PowerShell script discussed in this article will help you in querying for information about Windows user profiles on remote computers. The script returns user name, profile type, and in-use status of Windows profiles.

I will show you how to query Windows user profile information for a remote computer using WMI and PowerShell. Since Windows Vista SP1, Microsoft has offered a WMI class named Win32_UserProfile to facilitate querying profile information for a remote computer. There are other ways to accomplish this task, such as listing the directories in the c:\users folder, but these methods are not efficient and might fail in cases where user profiles are stored in different drives or directories.

Querying using the Win32_UserProfile class will return a list of profile objects. These objects contain information such as the SID of the user to whom the profile belongs and the type of profile. Because the SID is not in a human-friendly format for identifying the user names, the script tries to convert the SID to a user name. This conversion will work for both domain and local user accounts when run locally on the computer. The SID-to-name conversion fails when you query profile information for local user accounts remotely. In such cases, you will see the SID number instead of a user name in the script output.

Another thing the script does is translate the profile type. The profile objects returned by the WMI query contain an attribute called Status. Per the Technet page, this attribute should contain values of 0, 1, 2, and 3. But what people have noticed is that the attribute stores values of 0, 1, 2, 4, and 8, where 1 = Temporary, 2 = Roaming, 4 = Mandatory, and 8 = Corrupted. The script output contains this profile type information as well.

Look at the PowerShell script below to understand how SID translation and profile type determination is done using PowerShell.

The script also gives you information such as whether the profile is in use or not and if the profile belongs to a system account such as SYSTEM. In addition, the script indicates whether the profile is in use or not.

Sample usage and output:

Query profile information on a local computer:

Query profile information for a remote computer:

Query profile information for multiple remote computers:

Get user profile information with PowerShell

Get user profile information with PowerShell

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

1+
Share
37 Comments
  1. pooja 1 month ago

    I am able to run above script for local as well as for remote machines.

    can you please tell me if i want to use same thing in .net as there is same win32_userprofile class is available but not able to find -Computer parameter in that class so not able to use on remote machine.

    0

Leave a reply to pooja Click here to cancel the reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account