我在PowerShell中编写了以下函数并从Powershell ISE运行它 我期待的是运行提供内联参数并进行一些基本验证并将其打印回来。
function Set-Version
{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')]
[Alias()]
[OutputType([int])]
Param
(
# The path to the source directory. Default $Env:BUILD_SOURCESDIRECTORY is set by TFS.
[Parameter(Mandatory=$false, Position=0)]
[ValidateNotNullOrEmpty()]
[string]$Path = "C:\",
[Parameter(Mandatory=$false, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$Number = "2.0.0.2",
[Parameter(Mandatory=$false, Position=2)]
[ValidateNotNullOrEmpty()]
[string]$Format = "\d+\.\d+\.\d+\.\d+"
)
if (-not (Test-Path $Path)) {
Write-Output "Path does not exist."
}
}
Write-Output $Path
Write-Output $Number
Write-Output $Version
Set-Version -Path $Path -Number $Number -Version $Version
要运行:我使用以下语法,
PS C:\> .\Set-Version.ps1
PS C:\> .\Set-Version -Path "C:\" -Number "10" -Version "2v"
然而,屏幕上没有显示任何内容。
我错过了一些基本的东西吗?