Get specified user's SID and local home directory.
# Get current user's samaccountname only (without the domain prefix) by checking the username on console instead of the account #running the powershell commands.
# Get current user's samaccountname only (without the domain prefix) by checking the username on console instead of the account #running the powershell commands.
$explorerInstance = Get-WmiObject -Class Win32_Process | Where-Object -Property name -EQ -Value ‘explorer.exe’ $ownerinfo = $explorerInstance.GetOwner() $username = $ownerinfo.User $domaininfo = $ownerinfo.Domain $user = New-Object System.Security.Principal.NTAccount("$domaininfo", "$username") $sid = $user.Translate([System.Security.Principal.SecurityIdentifier]) $userprofile = Get-WmiObject -Namespace root/cimv2 -Class win32_userprofile -Filter "SID='$($sid.value)'" $USER_HOME = $userprofile.localpath
No comments:
Post a Comment