无法将函数输出写入文件(Can't write function output to file)
我目前一直在寻找关于如何轻松将函数结果输出到文件的信息。
$Balls = 5 $Plays = 1..26 function PowerBall { foreach ($Trys in $Plays) { $random = Get-Random -Input @(1..69) -Count $Balls Write-Host $random -NoNewline Write-Host " $Trys" -ForegroundColor Red } } PowerBall | Out-File C:\Windows\Temp\numbers2.txtI'm currently stuck on finding information on how to easily output the function results to a file.
$Balls = 5 $Plays = 1..26 function PowerBall { foreach ($Trys in $Plays) { $random = Get-Random -Input @(1..69) -Count $Balls Write-Host $random -NoNewline Write-Host " $Trys" -ForegroundColor Red } } PowerBall | Out-File C:\Windows\Temp\numbers2.txt最满意答案
你的函数没有返回任何东西,因为最后一行是Write-Host命令。 改变你的功能:
function PowerBall { Foreach($Trys in $Plays) { $random = get-random -input @(1..69) -count $Balls Write-Host $random -nonewline write-host " $Trys" -ForegroundColor Red "$random $Trys" } }另外如果你想输出为文本文件,那么你应该使用Set-Content而不是Export-Csv。
Your function is not returning anything because the last line is a Write-Host command. Change your function to this:
function PowerBall { Foreach($Trys in $Plays) { $random = get-random -input @(1..69) -count $Balls Write-Host $random -nonewline write-host " $Trys" -ForegroundColor Red "$random $Trys" } }Also if you want to output as a text file then you should use Set-Content instead of Export-Csv.
更多推荐
发布评论