相关疑难解决方法(0)

无法处理参数转换

受这篇文章的启发,我在下面创建了脚本DOSCommands.ps1

Function Invoke-DOSCommands {
    Param(
        [Parameter(Position=0,Mandatory=$true)]
        [String]$cmd,
        [String]$tmpname = $(([string](Get-Random -Minimum 10000 -Maximum 99999999)) + ".cmd"),
        [switch]$tmpdir = $true)
    if ($tmpdir) {
        $cmdpath = $(Join-Path -Path $env:TEMP -ChildPath $tmpname);
    }
    else {
        $cmdpath = ".\" + $tmpname
    }
    Write-Debug "tmpfile: " + $cmdpath
    Write-Debug "cmd: " + $cmd
    echo $cmd | Out-File -FilePath $cmdpath -Encoding ascii;
    & cmd.exe /c $cmdpath | Out-Null
}

Invoke-DOSCommands "Echo ""Hello World""", -tmpdir $false
Run Code Online (Sandbox Code Playgroud)

但是,在执行时会返回此错误:

Invoke-DOSCommands : Cannot process argument transformation on …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1

powershell-2.0 ×1