Is there a way to check if a cmdlet needs to be run as an administrator? Obviously without trial and error
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.
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