How to save CurrentUser as String

by the_hutch at 2012-12-07 11:26:19

When I use the command, “Get-CurrentUser” it outputs the username for the person running the script. The output looks like this:

AuthenticationType : Kerberos
ImpersonationLevel : None
IsAuthenticated : True
IsGuest : False
IsSystem : False
IsAnonymous : False
Name : domainname\username
Owner : --------
User : -------
Groups : --------
Token : -------

I wanted to assign this entire output to a string. Was trying this:

[string]$User = Get-CurrentUser

The value of $User becomes “System.Security.Principal.WindowsIdentity” instead of a string of the output above. Does anyone know how I can save the output from Get-CurrentUser to a string variable?
by RichardSiddaway at 2012-12-07 11:34:14
$user = Get-CurrentUser | Out-String
by the_hutch at 2012-12-07 11:43:42
Thanks Richard. Appreciate the quick reply.
by RichardSiddaway at 2012-12-09 02:37:51
You’re very welcome