Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting the FileSystemObject's CreateFolder Method

Windows PowerShell

Definition: Creates a new folder.


You can create a folder with the New-Item cmdlet. This example creates a new folder named temp2 as a subfolder of the C:\Scripts folder.

New-Item -path c:\scripts\ -name temp2 -type directory

Notice we specified the -type parameter with a value of directory. This tells New-Item we’re creating a folder and not a file.

If the folder already exists you’ll receive an error. To create the folder even if it already exists, use the -force parameter:

New-Item -path c:\scripts\ -name temp2 -type directory -force

You can also use the mkdir alias, but if the folder exists you’ll receive an error message, with no way to override that:

mkdir c:\scripts\temp2

See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

© 2016 Microsoft