Avatar of String :-)
String :-)
Flag for Australia

asked on 

Powershell learning exercise - trying to output a true or false

Hi Experts,
This is learning exercise for me.. 
I am trying work out how to check for local admin rights on a server and result a true or false.

My idea was to check if I can read the Security log, but my attempt at this approach always provides a True, regardless of result of Get-WinEvent. 

$eventcheck = Get-WinEvent -FilterHashtable @{logname='security'} -MaxEvents 1
    if (!($eventcheck)) {
    $Adminrights = $false }
    else {
    $Adminrights = $true }
    return $Adminrights

Any tips much appreciated.

Open in new window


Avatar of undefined
Last Comment
String :-)

8/22/2022 - Mon