简体   繁体   中英

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. 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

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 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM