Check if cmdlet requires run as admin

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of SuperSysAdmin SuperSysAdmin 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39473
    Profile photo of SuperSysAdmin
    SuperSysAdmin
    Participant

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

    #39476
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of SuperSysAdmin
    SuperSysAdmin
    Participant

    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 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.