title: Copy-Item and exclude folders
body: <p>I need to copy all of my <code>c:\inetpub</code> directory to a new location but exclude the following folders and their subfolders:</p>
  
  <pre><code>c:\inetpub\custerr
  c:\inetpub\history
  c:\inetpub\logs
  c:\inetpub\temp
  c:\inetpub\wwwroot
  </code></pre>
  
  <p>So far I am doing this:</p>
  
  <pre><code># Directory name is created with a format string
  $dirName = "\\servername\folder1 _ {0}\inetpub" -f (get-date).ToString("yyyy-MM-dd-hh-mm-ss")
  $dirName # Check the output
  
  # Create dir if needed
  if(-not (test-path $dirName)) {
      md $dirName | out-null
  } else {
      write-host "$dirName already exists!"
  }
  
  #Copy Backup File to Dir
  Copy-Item "\\servername\c$\inetpub\*" $dirName -recurse
  </code></pre>