forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSWho.ps1
58 lines (51 loc) · 1.82 KB
/
PSWho.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
originally published at:
https://gist.github.com/jdhitsolutions/3ecc6193ab0982d907c2db3f7d2bd15d
#>
Function Get-PSWho {
[CmdletBinding()]
Param(
[switch]$AsString
)
if ($PSVersionTable.PSEdition -eq "desktop" -OR $PSVersionTable.OS -match "Windows") {
#get some basic information about the operating system
$cimos = Get-CimInstance win32_operatingsystem -Property Caption, Version,OSArchitecture
$os = "$($cimos.Caption) [$($cimos.OSArchitecture)]"
$osver = $cimos.Version
#determine the current user so we can test if the user is running in an elevated session
$current = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]$current
$Elevated = $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$user = $current.Name
$computer = $env:COMPUTERNAME
}
else {
#non-Windows values
$os = $PSVersionTable.OS
$lsb = lsb_release -d
$osver = ($lsb -split ":")[1].Trim()
$elevated = "NA"
$user = $env:USER
$computer = $env:NAME
}
#object properties will be displayed in the order they are listed here
$who = [pscustomObject]@{
User = $user
Elevated = $elevated
Computername = $computer
OperatingSystem = $os
OSVersion = $osver
PSVersion = $PSVersionTable.PSVersion.ToString()
Edition = $PSVersionTable.PSEdition
PSHost = $host.Name
WSMan = $PSVersionTable.WSManStackVersion.ToString()
ExecutionPolicy = (Get-ExecutionPolicy)
Culture = $host.CurrentCulture
}
if ($AsString) {
$who | Out-String
}
else {
$who
}
} #end Get-PSWho