Reading and Writing Examples

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 2

There are a few options for writing data to

files:
By using the > redirection operator:
get-childitem > c:\testGCI.txt

By using the New-Item cmdlet to create an


empty file:
new-item c:\newitemtest.txt -type file

The Set-Content cmdlet will overwrite and


replace data already in the file:

Set-Content C:\newitemtest.txt "It was the worst of


times...
Set-Content C:\newitemtest.txt "It was the best of
times...
The Add-Content cmdlet will append data to a file:
Add-Content C:\newitemtest.txt "It was the worst of
times...
We can pipe data to the Out-File cmdlet (this will
overwrite an existing file):
gci | Out-File c:\mltest.txt

Use Get-Content cmdlet to read data from a file:


Get-Content C:\MLtest.ext

You might also like