PowerShell Remoting Project Home

Tuesday, January 24, 2006

A Clone of id/whoami in MSH

I would like to have something like id/whoami in linux while working with MSH. So I wrote a simple script.
##############################################
# File Name: id.msh
# Return User and Group information of current logon user
# By Tony http://mshforfun.blogspot.com
##############################################
$me=[System.Security.Principal.WindowsIdentity]::GetCurrent()
"UserSID= " + $me.User + " (" + $me.Name + ")"
"AuthenticationType= " + $me.AuthenticationType
"ImpersonationLevel= " + $me.ImpersonationLevel
"Token= " + $me.Token
"Groups= "
foreach($Group in $me.Groups)
{
"`tGroupSID= " + $Group + " (" + $Group.Translate([System.Security.Principal.NTAccount]) + ")"
}
Output looks like:
UserSID= S-1-5-21-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxx (Domain\me)
AuthenticationType= NTLM
ImpersonationLevel= None

Token= xxxx

Groups=
GroupSID= S-1-5-21-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxx (Domain\None)
GroupSID= S-1-1-0 (Everyone)
GroupSID= S-1-5-32-545 (BUILTIN\Users)
GroupSID= S-1-5-4 (NT AUTHORITY\INTERACTIVE)
GroupSID= S-1-5-11 (NT AUTHORITY\Authenticated Users)
GroupSID= S-1-2-0 (LOCAL)

Well, write a clone of who would be fun. Any volunteer?

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]

Tags:       


Comments:

Post a Comment





<< Home