Powershell Not detecting Administrator as Administrator

This topic contains 3 replies, has 2 voices, and was last updated by  Olaf Soyk 3 weeks, 2 days ago.

  • Author
    Posts
  • #75478

    StevieB
    Participant

    When I run this on several laptops logged in as local admin the value comes back true. I have one laptop that when I am logged in as local admin the value comes back false. Can anyone give me ideas on where to begin to troubleshoot his issue.

    $Identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()
    $Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
    $Principal.IsInRole([System.Security.Prinicipal.WindowsBuiltInRole]::Administrator)
  • #75490

    Olaf Soyk
    Participant

    You have a typo in your code. It should not work anywhere actually ... 😉
    In line 3 it should be [System.Security.Principal.WindowsBuiltInRole] instead of [System.Security.Prin_i_cipal.WindowsBuiltInRole]

  • #75655

    StevieB
    Participant

    Apologies on the typo. But what I am trying to understand is how come when I am logged in as local admin and I run this code the result comes back as false. Is there a way to check if user is a member of local admin and run with elevated privledges.

    $Identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()
    $Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
    $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)

  • #75722

    Olaf Soyk
    Participant

    It seems to me that your problem is not related with Powershell scripting.

You must be logged in to reply to this topic.