需要一些有关使用PowerShell Get-ChildItem创建脚本的帮助

时间:2017-09-19 08:17:22

标签: windows powershell

我有一个问题。我想用PowerShell做以下事情。将所有内容复制到新目录,但名为“56789”和“56789121”的文件夹除外。我使用GCI选项尝试-Exclude,但它无法正常工作。

您可以找到我想如何复制以下内容的直观表示:

C:\DATA
+---2
|   +---56789
|   +---Archived2001
|   |   |   66.txt
|   |   |
|   |   \---New folder
|   \---Archived2002
\---4
    |   33 - Copy.txt
    |   33.txt
    |
    +---56789121
    +---Archived2005
    \---Archived2008
            33 - Copy.txt
C:\MOVED
+---2
|   +---Archived2001
|   |   |   66.txt
|   |   |
|   |   \---New folder
|   \---Archived2002
\---4
    |   33 - Copy.txt
    |   33.txt
    |
    +---Archived2005
    \---Archived2008
            33 - Copy.txt

到现在为止,我已经有了这个,但它没有用。

$from = 'c:\data'
$to = 'c:\moved'
$exclude = 'C:\data\*\[0-9]\'
Get-ChildItem -Path $from -r | ? {
    $_.PsIsContainer -and $_.FullName -notmatch '$exclude'
} | Copy-Item -Destination $to -WhatIf

0 个答案:

没有答案