Creating new file through Windows Powershell

I'm guessing you're trying to create a text file?

New-Item c:\scripts\new_file.txt -type file

Where "C:\scripts\new_file.txt" is the fully qualified path including the file name and extension.

Taken from TechNet article


To create file using echo

echo some-text  > filename.txt

Example:

C:\>echo This is a sample text file > sample.txt
C:\>type sample.txt
This is a sample text file
C:\>

To create file using fsutil

fsutil file createnew filename number_of_bytes

Example:

fsutil file createnew sample2.txt 2000
File C:\sample2.txt is created
C:\data>dir
01/23/2016  09:34 PM     2,000 sample2.txt
C:\data>

Limitations

Fsutil can be used only by administrators. For non-admin users it throws up below error.

c:\>fsutil file /?

The FSUTIL utility requires that you have administrative privileges. c:>

Hope this helps!


street smart (quick, dirty but works): (might change the file and add an invisible character which might cause the compiler to fail)

$null > file.txt
$null > file.html

Textbook method:

New-Item -path <path to the destination file> -type file

example:

New-Item -path "c:\" -type file -name "somefile.txt"

OR

ni file.xt -type file

absence of -path parameter means it creates it in the current working directory