New-Item cmdlet will create new files or folders in PowerShell. Amend the
-ItemType parameter to File or Directory and include a Name for the file or folder.
This blog post will walk through the process of creating a new file and a new folder using PowerShell. I add an extra tip at the end on adding text to a file with PowerShell too.
For more examples and up-to-date information on creating files with New-Item, we can refer to Microsoft Documentation. They have PowerShell New-Item command examples for creating PowerShell profiles and symbolic links.
To create a new folder in PowerShell, run
New-Item -ItemType Directory -Name dirName, amending the name as desired.
This will create a folder in the directory you are currently navigated to within the PowerShell Terminal. So for the example below, the new folder is being created in
# PowerShell create new folder New-Item -ItemType Directory -Name Test_Stuff
To make a new file in PowerShell, run
New-Item -ItemType File -Name testFile amending the name as desired. This creates a file within your current working terminal directory.
This is the same command we ran above to create a folder, but this time changing the ItemType parameter.
# PowerShell new file New-Item -ItemType File -Name Test_File.txt
Now for a bonus PowerShell tip that you did not search or ask for. How to add text to a file in PowerShell.
# PowerShell add text to file Add-Content .\Test_File.txt -Value 'Hi hi!... just a wee message here.' # PowerShell show file content Get-Content .\Test_File.txt