I need to check logged-in users and if they are in the Administrators group, or maybe "if they have administrator rights"? I have managed to write some code, but if I run this script as an administrator I get my current logged-in user is admin (true), and other user that I added and logged in is also admin (true) but he is not in administrator group.
I'm not sure how to find it the right way. I found some scripts over the Internet but they seems too hard for me to understand.
$procesai = (Get-WmiObject Win32_Process | where {$_.ProcessName -eq 'explorer.exe'})
if ($procesai.Count -eq 0) {
Write-Host "Siuo metu nera prisijungusiu vartotoju"
} else {
foreach ($i in $procesai) {
$user = $i.GetOwner().User
$domen = $i.GetOwner().Domain
$admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
$domen + "\" + $user + " yra prisijunges ir jo administratoriaus statusas = $admin"
}
}