
Here is what the help on that looks like. Basic redirection with Out-FilePowerShell was introduced with Out-File as the way to save data to files. I do this to keep the samples cleaner and it better reflects how you would use them in a script. Saving and reading dataNow that we have all those helper CmdLets out of the way, we can talk about the options we have for saving and reading data.I use the $Path and $Data variables to represent your file path and your data in these examples. I find it as an easy way to add wildcard support to parameters. Resolve-Path -Path 'c:users.documents'Path-C:userskevin.marquetteDocumentsC:usersPublicDocumentsThat will enumerate all the local users document folders.I commonly use this on any path value that I get as user input into my functions that accept multiple files. You will get an array of values if there are more than one matche. The important thing is that it will expand wildcard lookups for you.
#Write to text file using streamwriter c full#
Resolve-PathResolve-Path will give you the full path to a location. If your variables both have backslashes in them, it sorts that out too.
#Write to text file using streamwriter c how to#
You don’t have to worry about how to handle the backslash becuse this takes care of it for you. PS: Join-Path -Path $env:temp -ChildPath testingC:Userskevin.marqueteAppDataLocalTemptestingI use this anytime that I am joining locations that are stored in variables. It allows you to test for a folder or a file before you try to use it. Test-PathTest-Path is one of the more well known commands when you start working with files. Index.Working with file pathsWe are going to start this off by showing you the commands for working with file paths. Let’s start with the basics and work into the more advanced options.

There may be more options than you realize. Saving data to files is a very common task when working with PowerShell.
