Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将参数写入powershell中从命令行传递的文本文件中?_Powershell - Fatal编程技术网

如何将参数写入powershell中从命令行传递的文本文件中?

如何将参数写入powershell中从命令行传递的文本文件中?,powershell,Powershell,如何将参数写入从命令行传递的文本文件 Param ( [Parameter(Mandatory=$True)] [ValidateNotNull()] [int]$Var1, [Parameter(Mandatory=$True)] [ValidateNotNull()] [int]$Var2 ) $Var1> 'C:\output.txt' $Var1 | Set-Content 'C:\output.txt' CommandLine:Powershell.exe -executi

如何将参数写入从命令行传递的文本文件

Param (
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[int]$Var1,
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[int]$Var2
)
$Var1> 'C:\output.txt'
$Var1 | Set-Content 'C:\output.txt'



CommandLine:Powershell.exe -executionpolicy remotesigned -File  Parameters.ps1 -Var1 1 -Var2 2
我想将从命令行传递的这些参数打印到文本文件中

foreach ($key in $MyInvocation.BoundParameters.keys)
{
    $value = (get-variable $key).Value 
    "$key -> $value" | Out-File -Append params.txt
}