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

Converting the FileSystemObject's Delete Method

Windows PowerShell

Definition: Deletes a specified file or folder.


Use the Remove-Item cmdlet to remove a file or folder. This example removes the C:\scripts\temp2\test.txt file:

Remove-Item C:\scripts\temp2\test.txt

This example removes the temp2 folder:

Remove-Item C:\scripts\temp2

If the C:\scripts\temp2 folder contains files or subfolders, you’ll be asked to confirm that you want to delete this folder. Unless, of course, you use the -recurse parameter:

Remove-Item C:\scripts\temp2 -recurse

The FileSystemObject’s Delete method allows you to specify whether you want to delete read-only files. To delete read-only files in PowerShell, use the -force parameter:

Remove-Item C:\scripts\temp2\test.txt -force

The built-in aliases del and rmdir also allow you to delete files and folders:

del C:\scripts\temp2\test.txt
del C:\scripts\temp2
rmdir temp2

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft