如何将参数写入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
}