- <#
- .SYNOPSIS
- This script Creates then removes a folder using methods in
- System.IO.Directory.
- .DESCRIPTION
- This script checks to see if a staticly named folder exists.
- if not, it creates then removes the folder. The creation/deletion
- logic in enclosed within a try/catch block to capture errors.
- .NOTES
- File Name : New-Folder.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/54a0at6s.aspx
- .EXAMPLE
- PSH [C:\foo]: .\New-Folder.ps1'
- The directory was created successfully at 10/7/2009 12:00:35 PM.
- The directory was deleted successfully.
- #>
- # Specify the directory to manipulate
- $path = "c:\fooxx"
- # try to see if the dirctory exists (It should not!)
- try {
- if ([System.Io.Directory]::Exists($path)) {
- "That path exists already."
- return
- }
- # Try to create the directory
- $di = [System.Io.Directory]::CreateDirectory($path)
- # Get creattion time and display results
- $dit = [System.Io.Directory]::GetCreationTime($path)
- "The directory was created successfully at {0}." -f $dit
- # Delete the directory.
- $di.Delete()
- "The directory was deleted successfully."
- }
- catch {
- "The process failed"
- }
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Wednesday, 7 October 2009
New-Folder.ps1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment