Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell移动不在列表中的项目_Powershell - Fatal编程技术网

Powershell移动不在列表中的项目

Powershell移动不在列表中的项目,powershell,Powershell,我有一个文件夹列表,这些文件夹是我想要保留的。我想移动列表中没有的所有其他文件夹 这将移动列表中的文件 $file_list = "Folder-A", "Folder-B", "Folder-C" $source_folder = "C:\Move-Folders-Test\Shop-Test" $destination_folder = "C:\Move-Folders-Test\Archive-Test" foreach ($file in $file_list) { Move-

我有一个文件夹列表,这些文件夹是我想要保留的。我想移动列表中没有的所有其他文件夹

这将移动列表中的文件

$file_list = "Folder-A", "Folder-B", "Folder-C" 
$source_folder = "C:\Move-Folders-Test\Shop-Test"
$destination_folder = "C:\Move-Folders-Test\Archive-Test"

foreach ($file in $file_list) {
   Move-Item $source_folder\$file $destination_folder
}
如何移动不在列表中的项?

使用
Exclude
参数将执行您想要的操作:

$file_list = "Folder-A", "Folder-B", "Folder-C" 
$source_folder = "C:\Move-Folders-Test\Shop-Test"
$destination_folder = "C:\Move-Folders-Test\Archive-Test"

Get-ChildItem $source_folder -Exclude $file_list -Directory | Move-Item -Destination $destination_folder -WhatIf
使用
Exclude
param将执行您想要的操作:

$file_list = "Folder-A", "Folder-B", "Folder-C" 
$source_folder = "C:\Move-Folders-Test\Shop-Test"
$destination_folder = "C:\Move-Folders-Test\Archive-Test"

Get-ChildItem $source_folder -Exclude $file_list -Directory | Move-Item -Destination $destination_folder -WhatIf

谢谢,詹姆斯C.我应该自己找到的。谢谢,詹姆斯C.我应该自己找到的。