3. File System Management Tasks - Powershell
3.2 Creating Files and Folders
Creating a file
New-Item -Path C:\temp\test.txt -ItemType File
this will create an empty file in the C:\temp
directory named test.txt.
Write content to a file
Set-Content -Path test.txt -Value "Hello World"
Add-Content -Path test.txt -Value "Hello World"
$text = 'Hello World!' | Out-File $text -FilePath test.txt
To overwrite an existing file, use the -Force switch parameter.
Alternatively, you can create files using the Export-CSV cmdlet, which exports the output to a csv file that can be opened in Excel:
Get-ADUser -Filter * -Properties * | Export-CSV -Path ADusers.csv