From 45032107b7b67cb1c4691b271d57c2cc70f5c1ac Mon Sep 17 00:00:00 2001 From: benpturner Date: Mon, 7 Jan 2019 14:28:15 +0000 Subject: [PATCH] Updated get-userinfo --- Modules/Get-UserInfo.ps1 | 87 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/Modules/Get-UserInfo.ps1 b/Modules/Get-UserInfo.ps1 index 6fca640..861d934 100644 --- a/Modules/Get-UserInfo.ps1 +++ b/Modules/Get-UserInfo.ps1 @@ -1,43 +1,48 @@ -function Get-UserInfo -{ - Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} - $arr = @() - $Users = Get-WmiObject -Query "Select * from Win32_UserAccount Where LocalAccount = True" - echo "" - echo "======================" - echo "Local Users" - echo "======================" - $Users.Name - $GroupNames = Get-WmiObject -Query "SELECT * FROM Win32_Group Where LocalAccount = True" - echo "" - echo "======================" - echo "Local Groups" - echo "======================" - $GroupNames.Name +function Get-UserInfo +{ + Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} + $arr = @() + $Users = Get-WmiObject -Query "Select * from Win32_UserAccount Where LocalAccount = True" + echo "" + echo "======================" + echo "Local Users" + echo "======================" + foreach ($usr in $Users) { + $usr.Name + } + $GroupNames = Get-WmiObject -Query "SELECT * FROM Win32_Group Where LocalAccount = True" + echo "" + echo "======================" + echo "Local Groups" + echo "======================" + foreach ($grp in $GroupNames) { + $grp.Name + } - $hostname = (Get-WmiObject -Class Win32_ComputerSystem).Name - echo "" - echo "======================" - echo "Members of Local Groups" - echo "======================" - foreach ($Group in $GroupNames) { - $GroupName = $Group.Name - $wmi = Get-WmiObject -Query "SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$Hostname',Name='$GroupName'`"" - - if ($wmi -ne $null) - { - foreach ($item in $wmi) - { - $data = $item.PartComponent -split "\," - $domain = ($data[0] -split "=")[1] - $name = ($data[1] -split "=")[1] - $arr += ("$domain\$name").Replace("""","") - [Array]::Sort($arr) - } - } - echo "" - echo $GroupName - echo "======================" - echo $arr - } + $hostname = (Get-WmiObject -Class Win32_ComputerSystem).Name + echo "" + echo "======================" + echo "Members of Local Groups" + echo "======================" + + foreach ($Group in $GroupNames) { + $GroupName = $Group.Name + $wmi = Get-WmiObject -Query "SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$Hostname',Name='$GroupName'`"" + + if ($wmi -ne $null) + { + foreach ($item in $wmi) + { + $data = $item.PartComponent -split "\," + $domain = ($data[0] -split "=")[1] + $name = ($data[1] -split "=")[1] + $arr += ("$domain\$name").Replace("""","") + [Array]::Sort($arr) + } + } + echo "" + echo $GroupName + echo "======================" + echo $arr + } }