Files
Another area where you should become very confident is working with files, as you will need to work with them very frequently. First, we will take a look at the basics of working with files by retrieving and writing files and the content of the files. This can be achieved with the Get-Content
and Set-Content
/Out-File
cmdlets.
First of all, we will take a dedicated look at how you can export content to a file:
#Storing working location $exportedProcessesPath ='C:\temp\exportedProcesses.txt' #Write processes table to file and show the result in Terminal with the -PassThru flag Get-Process | Set-Content -Path $exportedProcessesPath #Open file to verify psedit $exportedProcessesPath #retrieving processes and exporting them to file Get-Process | Out-File $exportedProcessesPath #Open file to verify psedit $exportedProcessesPath #or use notepad to open file #retrieving processes and exporting them to file with Out-String Get-Process | Out-String | Set-Content $exportedProcessesPath ...