0

I'm attempting to look up the SID for a specific user account in a PowerShell script. Prior research suggests that this can be done using the Get-CimInstance command, like so:

# This doesn't work for me
Get-CimInstance -ClassName Win32_UserAccount -filter "Name='this_is_a_long_username'" | Format-List -Property *

In my case however, this doesn't work. This is because the username of the account I need to look up is especially long, longer that what Windows versions older than Windows 2000 can support. Despite the fact that it is currently 2022, not 2000, that means my code above is actually broken. Indeed, if I instead use a shorter version of the account's username, what Microsoft's Active Directory Users and Computers tool refers to as the account's "User logon name (pre-Windows 2000)", then the above code works fine:

# This works
Get-CimInstance -ClassName Win32_UserAccount -filter "Name='this_is_a_long_usern'" | Format-List -Property *

However, my script doesn't have a way to retrieve the account's "pre-Windows 2000" name; it only has the account's real (post Windows 2000) username, which may not have any relation at all to the account's pre-Windows 2000 name, since those two values can apparently be set independently in Active Directory. How can I get the SID of a user (and other Win32_UserAccount properties) given only that account's full (post Windows 2000) username?

Ajedi32
  • 167
  • 11

0 Answers0