Create a new file with powershell
You can create a new file with PowerShell using the New-Item
cmdlet. Here are a few examples:
Create a new text file:
New-Item -Path "C:\Path\To\NewFile.txt" -ItemType File
This will create a new text file named NewFile.txt
in the specified path.
Create a new file with a specific content:
New-Item -Path "C:\Path\To\NewFile.txt" -ItemType File -Value "Hello World!"
This will create a new text file named NewFile.txt
in the specified path with the content "Hello World!".
Create a new file with a specific extension:
New-Item -Path "C:\Path\To\NewFile.log" -ItemType File -Force
This will create a new file named NewFile.log
in the specified path with a .log
extension. The -Force
parameter is used to overwrite the file if it already exists.
Create a new file in the current directory:
New-Item -Path ".\NewFile.txt" -ItemType File
This will create a new text file named NewFile.txt
in the current directory.
Note: You can also use the Set-Content
cmdlet to create a new file and write content to it in a single step:
Set-Content -Path "C:\Path\To\NewFile.txt" -Value "Hello World!"
This will create a new text file named NewFile.txt
in the specified path with the content "Hello World!".