简体   繁体   English

PowerShell脚本无法从out文件中获取文本

[英]PowerShell script doesn't get the text from the out file

The following code doesn't put text into the out file when I run it. 当我运行它时,以下代码不会将文本放入out文件中。 How do I correctly add the out file so that all the text from the shell gets copied to the out file? 如何正确添加out文件,以便将外壳程序中的所有文本复制到out文件中?

$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun -MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs -WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec -ServiceName $serviceName -PartitionKindSingleton
Pause | out-file c:\temp\results.txt

If you want the Output of Invoke-SeviceFabricFailoverTestScenario in your results.txt , you're breaking the Pipeline-Data by using pause . 如果您要在results.txt输出Invoke-SeviceFabricFailoverTestScenario的输出,则可以通过使用pause中断管道数据。

If your really need pause then try something like: 如果您确实需要pause尝试以下操作:

$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
$data = Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun -MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs -WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec -ServiceName $serviceName -PartitionKindSingleton 

 Pause 

 $data | out-file c:\temp\results.txt
$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun `
    -MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs `
    -WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec `
    -ServiceName $serviceName `
    -PartitionKindSingleton | out-file c:\temp\results.txt

The pipeline needs to be on the same line as the command, otherwise it's interpreting it as a new command. 管道必须与命令在同一行,否则它将解释为新命令。

Additionally you can use backticks to tell the line to continue on the next line for neater code. 另外,您可以使用反引号来告诉该行继续进行下一行以获得更整洁的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从批处理脚本运行 Powershell 命令时,PowerShell 用文本文件中的另一行替换行无法正常工作 - PowerShell replace line with another line in text file doesn't work as expected when attemtping to run Powershell commands from Batch script 变量未在 PowerShell 脚本中传递 - variable doesn't get passed in PowerShell script Powershell:在另一个脚本中从foreach调用脚本无法获得预期的效果 - Powershell: Calling a script from foreach in another script doesn't get the desired effect Powershell 脚本比较来自文本文件的进程 - Powershell script to compare processes from text file 从Powershell / WMI脚本输出到文本文件 - Output to text file from a powershell/WMI script 从WPF应用程序调用Powershell脚本不执行脚本 - Calling powershell script from WPF application doesn't execute script 应用程序不会被 Powershell 脚本触发,当在 Do… 中调用时 - Application doesn't get triggered from Powershell script, when invoking inside Do…Until Powershell脚本卡住,从批处理文件调用时不会退出 - Powershell script gets stuck, doesn't exit when called from batch file 从任务计划程序运行时,PowerShell 脚本将文件上传到 SharePoint 不起作用 - PowerShell Script uploading file to SharePoint doesn't work when run from Task Scheduler Powershell Out-File对CSV不起作用 - Powershell Out-File Doesn't Work For CSV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM