Check if cmdlet requires run as admin

Welcome Forums General PowerShell Q&A Check if cmdlet requires run as admin

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

2 years, 9 months ago.

  • Author
  • #39473

    Points: 0
    Rank: Member

    Is there a way to check if a cmdlet needs to be run as an administrator? Obviously without trial and error 🙂

  • #39476

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Usually not. A script or function can use the #REQUIRES statement to indicate this, but few people do, and within a cmdlet there's not an equivalent that's usually used.

    And that's because very few cmdlets explicitly need to be run "as Administrator." Usually, the cmdlet only requires that you have permission to do whatever the cmdlet is doing. While Administrator usually has those permissions, it's (A) possible for an Admin to not have those permissions, and (B) possible for other accounts to have those permissions.

  • #39480

    Points: 0
    Rank: Member

    Yes I know about the #requires in scripts but I thought there might be a parameter we could query on builtin cmdlets.

    The other day I ran into something really stupid where a domain admin needed to open an elevated PowerShell session to be able to create a user. If the same user opens ADUC no UAC prompt appears and he can do anything. If the builtin Domain Admin (aka original Administrator) opens a PowerShell session, it's always "as Administrator".

    Not very consistent 🙂

The topic ‘Check if cmdlet requires run as admin’ is closed to new replies.

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