Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
File 如何在Powershell中查找、筛选目录和内容并将其复制到由部分查找结果指定的位置_File_Powershell_Directory_Copy - Fatal编程技术网

File 如何在Powershell中查找、筛选目录和内容并将其复制到由部分查找结果指定的位置

File 如何在Powershell中查找、筛选目录和内容并将其复制到由部分查找结果指定的位置,file,powershell,directory,copy,File,Powershell,Directory,Copy,最好使用Powershell,否则使用vbscript。perl或批处理。(无论如何,这不是手工作业) 我有一个用户配置文件列表: \\fileserver\profiles\user1\findmedirectory\dir1 \\fileserver\profiles\user2\findmedirectory\dir1 \\fileserver\profiles\user3\notfindme\dir1 我希望递归地将“findmedirectory”的所有实例复制到 \\fileser

最好使用Powershell,否则使用vbscript。perl或批处理。(无论如何,这不是手工作业)

我有一个用户配置文件列表:

\\fileserver\profiles\user1\findmedirectory\dir1
\\fileserver\profiles\user2\findmedirectory\dir1
\\fileserver\profiles\user3\notfindme\dir1
我希望递归地将“findmedirectory”的所有实例复制到

\\fileserver\newprofilesdirectory\user1\
\\fileserver\newprofilesdirectory\user2\
\\fileserver\newprofilesdirectory\user3\
例如,通过查找第一个条目:

\\fileserver\profiles\user1\appdata\findmedirectory\dir1
`$dest = \\fileserver\newprofiledirectory
$user = user1 (from result above)
$copydir = findmedirectory

$complete_dest = $dest & $user & $copydir (i.e. 
\\fileserver\newprofiledirectory\user1\findmedirectory )
`
显然,在user1、user2和user3下面的两个位置都有其他文件

到目前为止,我已经:
get childitem“\\fileserver\profiles”-filter“findmedirectory”-force-recurse | where object{$\u0.PSIsContainer}|选择object fullname

这是有效的

当我尝试通过管道获取“username”字符串时,即user1。它开始崩溃:

$files=Get-ChildItem“\\fileserver\profiles”-Filter“*findmedirectory*”-强制-递归|其中对象{$\ psicContainer}|选择对象全名
foreach($files中的文件) {get item$files.fullname).parent.name }

请帮助。

这应该可以:

$specialdirectory = "xyz"
$Destination = "zyx"

$1 = "\\fileserver\profiles\" | Get-ChildItem
$User = $1.Name | where {$_ -Match "User"}
$User | foreach {
$check = test-path -pathtype Any "\\fileserver\profiles\$_\appdata\$Specialdirectory"
If ($check -eq $true) {Copy-Item \\fileserver\profiles\$_\appdata\$specialdirectory -Destination C:\$Destination -Recurse}
        }
$oldprofiles = '\\fileserver\profiles'
$newprofiles = '\\fileserver\newprofilesdirectory'

Get-ChildItem $oldprofiles -Filter "*findmedirectory*" -Recurse -Force | ? {
  $_.PSIsContainer
} | % {
  Copy-Item $_.FullName (Join-Path $newprofile $_.Parent.Name) -Recurse -Force
}

如果我正确理解了你的问题,像这样的方法应该会奏效:

$specialdirectory = "xyz"
$Destination = "zyx"

$1 = "\\fileserver\profiles\" | Get-ChildItem
$User = $1.Name | where {$_ -Match "User"}
$User | foreach {
$check = test-path -pathtype Any "\\fileserver\profiles\$_\appdata\$Specialdirectory"
If ($check -eq $true) {Copy-Item \\fileserver\profiles\$_\appdata\$specialdirectory -Destination C:\$Destination -Recurse}
        }
$oldprofiles = '\\fileserver\profiles'
$newprofiles = '\\fileserver\newprofilesdirectory'

Get-ChildItem $oldprofiles -Filter "*findmedirectory*" -Recurse -Force | ? {
  $_.PSIsContainer
} | % {
  Copy-Item $_.FullName (Join-Path $newprofile $_.Parent.Name) -Recurse -Force
}