0% found this document useful (0 votes)
66 views2 pages

PowerShell File Writing Techniques

This document outlines several options for writing data to files in PowerShell, including using the > redirection operator to output command results to a new file, using New-Item to create an empty file, overwriting a file's contents with Set-Content or appending new data to an existing file with Add-Content, piping command output to Out-File to write it to a file, and reading the contents of a file with Get-Content.

Uploaded by

roderinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views2 pages

PowerShell File Writing Techniques

This document outlines several options for writing data to files in PowerShell, including using the > redirection operator to output command results to a new file, using New-Item to create an empty file, overwriting a file's contents with Set-Content or appending new data to an existing file with Add-Content, piping command output to Out-File to write it to a file, and reading the contents of a file with Get-Content.

Uploaded by

roderinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

There are a few options for writing data to

files:
By using the > redirection operator:
get-childitem > c:\[Link]

By using the New-Item cmdlet to create an


empty file:
new-item c:\[Link] -type file

The Set-Content cmdlet will overwrite and


replace data already in the file:

Set-Content C:\[Link] "It was the worst of


times...
Set-Content C:\[Link] "It was the best of
times...
The Add-Content cmdlet will append data to a file:
Add-Content C:\[Link] "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:\[Link]

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


Get-Content C:\[Link]

You might also like