Managing folders

In this recipe, we will explore different cmdlets that support folder management.

How to do it...

Let's take a look at different cmdlets that can be used for folders:

  1. Open PowerShell ISE as an administrator.
  2. Add the following script and run it:
    #list folders ordered by name descending
    $path = "C:\Temp" 
    
    #get directories only
    Get-Childitem $path | 
    Where-Object PSIsContainer
    
    #create folder
    $newFolder = "C:\Temp\NewFolder"
    New-Item -Path $newFolder -ItemType Directory -Force
    
    #check if folder exists 
    Test-Path $newFolder
    
    #copy folder
    $anotherFolder = "C:\Temp\NewFolder2"
    Copy-Item $newFolder $anotherFolder -Force
    
    #move folder
    Move-Item $anotherFolder $newFolder
    
    #delete folder
    Remove-Item $newFolder -Force -Recurse

How it works...

Here are ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.