Please feel free to provide feedback or file bugs here.

Script won't display help docs with -? if it uses #requires -RunAsAdministator

Votes from Connect: 5

Original Date Submitted: 4/27/2015 6:22:00 AM

Description:
********Contact Information********
Handle: Keith Hill MVP
Site Name: PowerShell
Feedback ID: 1281101
***************************************

Frequency: PowerShell
Regression: Run the script (call it test.ps1) from the Description above from a non-admin PowerShell prompt like so:

PS> .\test.ps1 -?

You will get this result:

.\test.ps1 : The script 'test.ps1' cannot be run because it contains a "#requires" statement for running as
Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by
using the Run as Administrator option, and then try running the script again.
At line:1 char:1
+ .\test.ps1 -?
+ ~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (test.ps1:String) [], ScriptRequiresException
+ FullyQualifiedErrorId : ScriptRequiresElevation

Problem Description:
If I run the following script with the -? param from a non-admin console it fails telling me I need to be admin to run the script:

#requires -RunAsAdministrator

<#
.SYNOPSIS
Testing, testing. Is this thing on?
#>
[CmdletBinding()]
param()

end {
"Testing"
}

Product Studio item created by Connect Synchronizer due to creation of feedback ID 1281101 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1281101).

Repro Steps:
Run the script (call it test.ps1) from the Description above from a non-admin PowerShell prompt like so:

PS> .\test.ps1 -?

You will get this result:

.\test.ps1 : The script 'test.ps1' cannot be run because it contains a "#requires" statement for running as
Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by
using the Run as Administrator option, and then try running the script again.
At line:1 char:1
+ .\test.ps1 -?
+ ~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (test.ps1:String) [], ScriptRequiresException
+ FullyQualifiedErrorId : ScriptRequiresElevation

Expected Results:
I expect to get the same result in a non-admin console that I get if I man the script e.g.:

PS> man .\test.ps1 -full

NAME
C:\Users\Keith\test.ps1

SYNOPSIS
Testing, testing. Is this thing on?
....

I shouldn't have to be running admin in order to see the help on a topic even when I'm using .\ScriptName.ps1 -?.

Internal BugId: 14411

1 vote
Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)

We’ll send you updates on this idea

AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: Facebook Google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base