admin管理员组

文章数量:1287913

Is there a way to use reflection to programmatically inspect and determine if a given compiled cmdlet requires elevation?

Notes:

  • This question concerns compiled cmdlets, not script (text) files.

  • Simply running the command in an unelevated console to see if an error is generated is one way to discover if a cmdlet requires elevation, but this question is geared towards a more programmatic and automated solution.

  • "Elevation Required"-type exceptions will vary between cmdlets - for example:

    Unelevated Command Exception HResult (Message)
    Get-WindowsCapability -Online System.Runtime.InteropServices.COMException 0x800702E4 (The requested operation requires elevation)
    Update-Help System.Exception 0x80131500 (Unknown error)
    Get-Process -IncludeUserName System.InvalidOperationException 0x80131509 (Unknown error)

    本文标签: