小编Jak*_*son的帖子

为什么我在PowerShell中看不到脚本的参数?

我正在编写一个脚本,它将有效地花费时间和我提供的任何输入并将其吐出到现有的文本文件中.

我创建的参数是$ Input和$ logPath.$ input应该能够采用管道输入或使用"-Input",而$ logPath参数需要"-logpath".

我不确定我做错了什么,因为在ISE中使用自动完成时我看不到那些开关.如果我尝试管道输入我得到:

"Out-LogFile:输入对象不能绑定到命令的任何参数,因为命令不接受管道输入或输入及其属性与任何接受管道输入的参数都不匹配.在行:1 char: 10"

如果我试图坚持开关而不是管道输入我可以使用一个,但一旦我输入一个我不能使用第二个开关.

这是我的功能,任何帮助表示赞赏:

function Global:Out-LogFile {
    #Planned function for outputting to a specified log file.
     <#
    .SYNOPSIS
    Adds to log files.

    .DESCRIPTION
    Updates a specified log file with a new line. The log file must already exist. See: Get-help New-LogFile

    .PARAMETER logPath
    Specifies a path for your new log (including file name).

    .EXAMPLE
    Get-ChildItem C:\ | Out-LogFile
    Piped input.

    #>

    [CmdletBinding()]

    param(
        [Parameter(Mandatory=$True,
                  ValueFromPipeline=$True,
                  ValueFromPipelineByPropertyName=$True,
                  HelpMessage="input to append to logFile",
                  ParameterSetName='Input')] …
Run Code Online (Sandbox Code Playgroud)

parameters powershell function

3
推荐指数
1
解决办法
1235
查看次数

标签 统计

function ×1

parameters ×1

powershell ×1