简体   繁体   English

如何在PowerShell中使用参数路径将输出写入文件?

[英]How do I write an output to a file with parameter path in PowerShell?

I want to write an output of FB to a file, but I want to use parameter for the path, I dont want to use the path like this (C:\\User\\Log.txt) to write a file. 我想将FB的输出写入文件,但是我想使用参数作为路径,我不想使用这样的路径(C:\\User\\Log.txt)来写入文件。 I tried this way, but It still fail. 我尝试过这种方式,但仍然失败。

Param(
  [parameter(mandatory=$true)][string]$i, $k
)

$Get_Path = $k
$Get_Path
---------- #
$FB = Get-Content $i
$FBSg = $FB.Substring(0, $FB.Length-3)
$FB = $FB -split '(..)' -join '|'

$Log = $FB Out-File $Get_Path "Log.txt"

You can write content to a file using this function: Add-Content $Get_Path $FB 您可以使用以下功能将内容写入文件: Add-Content $Get_Path $FB

This function will create a new file for you, if the file doesn't exist. 如果该文件不存在,此功能将为您创建一个新文件。 When you want to make sure that the file get's resetted before writing the content, simply delete the file: if ([System.IO.File]::Exists($path)) { Remove-Item –path $Get_Path } 如果要确保在写入内容之前重置文件,只需删除文件即可: if ([System.IO.File]::Exists($path)) { Remove-Item –path $Get_Path }

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

相关问题 Powershell - 如何列出文件并将其路径写入输出文件? - Powershell - how do I list files and write their path into an output file? 如何编写接受相对路径的 Powershell 文件参数 - How to write a Powershell file parameter that accepts a relative path 如何在 CSV 文件中重复将 powershell output 写入特定列? - How do I write powershell output into specific columns repeatedly in a CSV file? 如何将powershell输出写入文件? [Python] - How to write powershell output to file? [Python] 如何使用Powershell将Set-Content写入文件? - How do I write Set-Content to a file using Powershell? 如何将数组参数传递给powershell -file? - How do I pass an array parameter to powershell -file? 如何在PowerShell中获取没有扩展名的文件路径? - How do I get a file path without extension in PowerShell? 如何将命令 output 保存到变量中,以及如何将该变量用作 Powershell 中的命令参数? - How do I save a command output to a variable, and how do I use that variable as command parameter in Powershell? 带有交换功能的Powershell-如何将所有详细输出附加到文件 - Powershell with exchange— How do I append all verbose output to a file 如何使用 powershell 将此文本文件 output 转换为表格格式? - How do I output this Text file into a table format using powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM