-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"help" command triggers an error #16880
Comments
what is
|
It's not an alias, it's a built in function. So that code must be internal to the function. From the error, it looks like you're running in constrained language mode. You'll probably need to use |
That message normally means you have put PowerShell into a restricted language mode. How are you starting PowerShell. If you just run pwsh -noProfile do you get the same error ? And what does |
I've always been sure that this is an alias. Very similar to the proxy function for Get-Help:
|
This is what I have by default for Expand for code<#
.FORWARDHELPTARGETNAME Get-Help
.FORWARDHELPCATEGORY Cmdlet
#>
[CmdletBinding(DefaultParameterSetName='AllUsersView', HelpUri='https://go.microsoft.com/fwlink/?LinkID=113316')]
param(
[Parameter(Position=0, ValueFromPipelineByPropertyName=$true)]
[string]
${Name},
[string]
${Path},
[ValidateSet('Alias','Cmdlet','Provider','General','FAQ','Glossary','HelpFile','ScriptCommand','Function','Filter','ExternalScript','All','DefaultHelp','DscResource','Class','Configuration')]
[string[]]
${Category},
[Parameter(ParameterSetName='DetailedView', Mandatory=$true)]
[switch]
${Detailed},
[Parameter(ParameterSetName='AllUsersView')]
[switch]
${Full},
[Parameter(ParameterSetName='Examples', Mandatory=$true)]
[switch]
${Examples},
[Parameter(ParameterSetName='Parameters', Mandatory=$true)]
[string[]]
${Parameter},
[string[]]
${Component},
[string[]]
${Functionality},
[string[]]
${Role},
[Parameter(ParameterSetName='Online', Mandatory=$true)]
[switch]
${Online},
[Parameter(ParameterSetName='ShowWindow', Mandatory=$true)]
[switch]
${ShowWindow})
# Display the full help topic by default but only for the AllUsersView parameter set.
if (($psCmdlet.ParameterSetName -eq 'AllUsersView') -and !$Full) {
$PSBoundParameters['Full'] = $true
}
# Nano needs to use Unicode, but Windows and Linux need the default
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) {
[System.Text.Encoding]::Unicode
} else {
[System.Console]::OutputEncoding
}
$help = Get-Help @PSBoundParameters
# If a list of help is returned or AliasHelpInfo (because it is small), don't pipe to more
$psTypeNames = ($help | Select-Object -First 1).PSTypeNames
if ($psTypeNames -Contains 'HelpInfoShort' -Or $psTypeNames -Contains 'AliasHelpInfo')
{
$help
}
elseif ($help -ne $null)
{
# By default use more on Windows and less on Linux.
if ($IsWindows) {
$pagerCommand = 'more.com'
$pagerArgs = $null
}
else {
$pagerCommand = 'less'
# PSNativeCommandArgumentPassing arguments should be constructed differently.
if ($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') {
$pagerArgs = '-s','-P','Page %db?B of %D:.\. Press h for help or q to quit\.'
}
else {
$pagerArgs = '-Ps"Page %db?B of %D:.\. Press h for help or q to quit\.$"'
}
}
# Respect PAGER environment variable which allows user to specify a custom pager.
# Ignore a pure whitespace PAGER value as that would cause the tokenizer to return 0 tokens.
if (![string]::IsNullOrWhitespace($env:PAGER)) {
if (Get-Command $env:PAGER -ErrorAction Ignore) {
# Entire PAGER value corresponds to a single command.
$pagerCommand = $env:PAGER
$pagerArgs = $null
}
else {
# PAGER value is not a valid command, check if PAGER command and arguments have been specified.
# Tokenize the specified $env:PAGER value. Ignore tokenizing errors since any errors may be valid
# argument syntax for the paging utility.
$errs = $null
$tokens = [System.Management.Automation.PSParser]::Tokenize($env:PAGER, [ref]$errs)
$customPagerCommand = $tokens[0].Content
if (!(Get-Command $customPagerCommand -ErrorAction Ignore)) {
# Custom pager command is invalid, issue a warning.
Write-Warning "Custom-paging utility command not found. Ignoring command specified in `$env:PAGER: $env:PAGER"
}
else {
# This approach will preserve all the pagers args.
$pagerCommand = $customPagerCommand
$pagerArgs = if ($tokens.Count -gt 1) {$env:PAGER.Substring($tokens[1].Start)} else {$null}
}
}
}
$pagerCommandInfo = Get-Command -Name $pagerCommand -ErrorAction Ignore
if ($pagerCommandInfo -eq $null) {
$help
}
elseif ($pagerCommandInfo.CommandType -eq 'Application') {
# If the pager is an application, format the output width before sending to the app.
$consoleWidth = [System.Math]::Max([System.Console]::WindowWidth, 20)
if ($pagerArgs) {
# Start the pager arguments directly if the PSNativeCommandArgumentPassing feature is enabled.
# Otherwise, supply pager arguments to an application without any PowerShell parsing of the arguments.
# Leave environment variable to help user debug arguments supplied in $env:PAGER.
if ($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') {
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand $pagerArgs
}
else {
$env:__PSPAGER_ARGS = $pagerArgs
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand --% %__PSPAGER_ARGS%
}
}
else {
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand
}
}
else {
# The pager command is a PowerShell function, script or alias, so pipe directly into it.
$help | & $pagerCommand $pagerArgs
}
} |
I have so. I did not paste full output. I can't figure out what is causing the error in:
|
"Core type" just means "it's not one of the pre-approved types defined by the Restricted Language mode". Offhand I'm not sure what they are, but it's likely just PSObject and a scant handful of others. Restricted Language mode is pretty much by design useless. |
Hi,
I tried get-help and it works correctly. The "help" command, however, shows
the error message.
|
|
The Engine WG reviewed this today. We agree that this function should either work the same in CLM or at the very least emit a better error message. We're marking this as up for grabs. |
I tested this issue in Powershell 7.2.7 Both commands worked correctly, no errors |
@iSazonov Looks like this can be closed |
This issue does not occur anymore. I searched endlessly and cannot find a way to close it. Why can't the issue creator close it? |
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically. Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original. |
Prerequisites
Steps to reproduce
In Powershell Core 7.2.1 on Windows 10, type "help" command and press enter.
Expected behavior
The "help" command should display information about how to use Powershell.
Actual behavior
Error details
No response
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: