- <#
- .SYNOPSIS
- This example shows how to create a new directory and
- subdirectory, and then delete only the subdirectory.
- .DESCRIPTION
- This sample is a re-write of an MSDN Sample,
- but in PowerShell. The sample firsts creates then removes
- a folder then looks to see what is left. The target
- folder is removed, but intermediate folders remain.
- .NOTES
- File Name : Show-FolderCreation.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/62t64db3.aspx
- .EXAMPLE
- Psh> Show-FolderCreation.ps1
- Created: C:\NewDirectory\NewSubDirectory
- Deleted: C:\NewDirectory\NewSubDirectory
- Top-level directory exists: True
- Sub-directory exists : False
- #>
- [CmdletBinding()]
- Param (
- $Path = "C:\NewDirectory\NewSubDirectory"
- )
- Try
- {
- # Create then remove directory
- $result = [System.IO.Directory]::CreateDirectory($Path)
- "Created: $path"
- [System.IO.Directory]::Delete($Path)
- "Deleted: $path"
- # Check existance for top and sub dirs then display results
- $directoryExists = [System.Io.Directory]::Exists("C:\NewDirectory")
- $subDirectoryExists = [System.Io.Directory]::Exists($Path)
- "Top-level directory exists: $directoryExists"
- "Sub-directory exists : $subDirectoryExists"
- }
- Catch
- {
- "The process failed: {0}" -f $($error[0].Message)
- }
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 1 October 2012
Show-FolderCreation.ps1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment