[Solved] Having trouble getting a list of users profiles [closed]


You’ll want to query WMI for Win32_UserProfile instances – each profile will be linked to the security identifier of the user owning the profile, which can in turn be translated to an account object with the user name:

Get-CimInstance win32_userprofile |ForEach-Object {
  # Convert SID string to SecurityIdentifier object
  $SID = $_.SID -as [System.Security.Principal.SecurityIdentifier]

  try {
    # Now we can resolve the actual account
    $SID.Translate([System.Security.Principal.NTAccount]).Value
  }
  catch {
    Write-Warning "Unable to translate SID '$($_.SID)' for profile at '$($_.LocalPath)' to account name"
  }
}

Which on my machine (with just one local account) lists:

COMPUTER-NAME\mathias
NT AUTHORITY\NETWORK SERVICE
NT AUTHORITY\LOCAL SERVICE
NT AUTHORITY\SYSTEM

6

solved Having trouble getting a list of users profiles [closed]