Extracting the User Name from a Computer

This question was asked in the Microsoft TechEd forum, “How do I get the user name from the PC name when the PC name has two different formats (XX-XX-XXX-XXXXXXX-X and XX-XX-XXX-XXXXXXX)?”

In this particular case an extra character was added to certain PCs to indicate that they were rebuilt in order to avoid duplicate PC names in AD.

Given that in this example the UserID is always 7 characters long you can use this substring command SUBSTRING(XX-XX-XXX-XXXXXXX,11,7).

This is what the query would look like:





       v_r_system R

By using this query it will provide you with the user name from the computer name.

For another day, I will explain why PC names should never be based on an office location or a UserID.

Extracting the User Name from the Computer

Leave a Comment

Share via
Copy link
Powered by Social Snap