/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Different ways to do things in Monad, and some lin... "," 2006 Winter Scripting Games "," Check spelling with MSN Search from MSH (Part 3) "," Search with MSNSearch Web API from MSH (Part 2) "," Search with MSNSearch Web API from MSH (Part 1) "," about_Switch Documentation "," Switch -regEx "," Dir, Dir and more Dir in MSH "," Simple Show-Image function for Monad "," MSH out-zip Function "," ")

Wednesday, February 08, 2006

 


Get current user in Monad



as anwer to my question in last post,
how many ways can you find to get the current user from MSH,

I came up with this list : *Edit* - repost WITH pipelines

# environment variable

$env:username

gc env:username

ls env:\username

gci env: -inc username

# registry

(gp "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\").'Logon User Name'

gp "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\" | fl 'Logon User Name'

gi "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\" | gp | select 'Logon User Name'

# .NET

[environment]::username

[System.Security.Principal.WindowsIdentity]::GetCurrent().name

([system.threading.thread]::getdomain()).SetPrincipalPolicy([System.Security.Principal.PrincipalPolicy]::WindowsPrincipal)

     [system.threading.thread]::currentPrincipal.Identity.name

     ([system.threading.thread]::currentPrincipal.identity.get_user()).Translate([system.security.principal.ntaccount])

# COM

(new -com WScript.NetWork).username

(new -com WScript.Shell).Environment('process').item('username')

(new -com WScript.Shell).ExpandEnvironmentStrings("%username%")

# WMI

get-wmiobject Win32_ComputerSystem | fl UserName

(get-wmiobject Win32_ComputerSystem).UserName




feel free to add more :-)

gr /\/\o\/\/
Tags :


Comments:
Blogger /\/\o\/\/
# VB namespace

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
([system.threading.thread]::getdomain()).SetPrincipalPolicy([System.Security.Principal.PrincipalPolicy]::WindowsPrincipal)
(new-object Microsoft.VisualBasic.ApplicationServices.User).name
 
Post a Comment

Links to this post:

Create a Link



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?