PoshCode Archive  Artifact Content

Artifact ebf3bd187dc443a7954e552018f719cc9e675ccce49fd4ca6bd244a430da4c71:

  • File whoami.ps1 — part of check-in [8f0ea49b2f] at 2018-06-10 13:33:54 on branch trunk — Extended version of benae’s script at http://poshcode.org/3979 (user: greg zakharov size: 1153)

# encoding: ascii
# api: powershell
# title: whoami
# description: Extended version of benae’s script at http://poshcode.org/3979
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-UserStatus
# x-poshcode-id: 3981
# x-archived: 2013-02-27T06:04:51
# x-published: 2013-02-21T13:51:00
#
#
function Get-UserStatus {
  <#
    .Synopsis
        Get extended information about local user.
    .Description
        There is no input arguments, just specify Get-UserStatus or his alias whoami.
    .Link
        http://msdn.microsoft.com/en-us/library/system.security.principal.aspx
        http://poshcode.org/3979
  #>
  $usr = [Security.Principal.WindowsIdentity]::GetCurrent()
  $res = (New-Object Security.Principal.WindowsPrincipal $usr).IsInRole(
    [Security.Principal.WindowsBuiltInRole]::Administrator
  )

  "{0, 9}: {1}" -f "User", $usr.Name
  "{0, 9}: {1}" -f "SID", $usr.Owner.Value
  "{0, 9}: {1}" -f "IsAdmin", $res
  "{0, 9}:" -f "Groups"
  $usr.Groups | % {"`t   " + $_.Translate([Security.Principal.NTAccount]).Value} | sort
  ""
}

Set-Alias whoami Get-UserStatus