PowerShell - 建立文字檔案



Cmdlet

New-Item cmdlet 用於建立文字檔案和 Set-Content cmdlet 將內容放入其中。

步驟 1

在此示例中,我們建立一個名為 test.txt 的新文字檔案

在 PowerShell ISE 控制檯中輸入以下命令

New-Item D:\temp\test\test.txt

你可以在 D:\temp\test 目錄中看到建立的 test.txt。

步驟 2

在此示例中,我們向 test.txt 中新增內容。

在 PowerShell ISE 控制檯中輸入以下命令

Set-Content D:\temp\test\test.txt 'Welcome to TutorialsPoint'

步驟 3

在此示例中,我們讀取 test.txt 的內容。

get-Content D:\temp\test\test.txt

輸出

你可以在 PowerShell 控制檯中看到以下輸出。

Welcome to TutorialsPoint
powershell_files_io.htm
廣告
© . All rights reserved.