Overwriting an existing file
To overwrite a file with one you have created we can still use the New-Item cmdlet, but, in this case we are going to have to use the -Force parameter for it to be successful.
Writing data into new files
It's important to remember that PowerShell is a scripting language that we can also take advantage of to enable certain functionality. In the below example we defined the variable "$content" with a string in single quotations, along the with use of a pipe "|" pushed through to the out-file cmdlet specifying what file we are adding content to.
This will create a file called textfile1.txt in the C:\Temp directory and it will contain your message.
Using the .NET framework class
The next option is to create a folder using the system.io namespace and the CreateDirectory static method in the Directory class.
The command you can use is:
Using object
The third method is to use the Object method from the Scripting.FileSystemObject. Note that this is the same method used in VBScript and the advantages are that it is fast and relatively easy to use to create a directory.
This command will return an object that contains the path and other information of the directory.