Powershell Not detecting Administrator as Administrator

Welcome Forums General PowerShell Q&A Powershell Not detecting Administrator as Administrator

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #75478

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 740
    Helping Hand
    Rank: Major Contributor

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 740
    Helping Hand
    Rank: Major Contributor

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

The topic ‘Powershell Not detecting Administrator as Administrator’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort