比较\使用PowerShell创建和复制从2个位置到第3个文件的文件

时间:2018-04-04 18:56:39

标签: powershell

我有一个Citrix 6.5服务器场和一个VDI视图6环境,每个环境都有自己独立的配置文件位置。   我现在已经设置了Horizo​​n view 7环境,想要比较来自citrix和HV6的桌面和收藏夹文件夹,然后在文件夹中创建一个新的中心位置,并将比较中的最新文件复制到中心位置......我仍然相当新的动力shell所以我将列出我到目前为止当我运行它时,它就像它正在运行,但什么也没做。我需要一些帮助。 `#Current Citrix用户文件夹配置文件名称     $ name = Get-ChildItem“\ usolt-isln.smcusa.com \ ctxprofiles \” - 目录-Recurse

#Citrix profile location
$Folder1Path = "\\usolt- 
isln.smcusa.com\ctxprofiles\$name\UPM_Profile\Desktop"
#HV6 profile location
$Folder2Path = "\\usind-vdifs-01\ViewProfiles\$name.V2\Desktop"
#HV7 Location
$Folder3Path = "\\USIND-corpfs-01\Users\$name\vPCDocuments\Desktop"

#Creates final destination path if it doesn't exist
$path = "$Folder3path"
If(!(test-path $path))
{
      New-Item -ItemType Directory -Force -Path $path
}


$Folder1Files = Get-ChildItem -Path $Folder1Path
$Folder2Files = Get-ChildItem -Path $Folder2Path

$FileDiffs = Compare-Object -Reference Object $Folder1Files -Difference 
Object $Folder2Files

$FileDiffs | foreach { 
     $copyParams = @{
       'Path' = $_.InputObject.fullname
       }
       if ($_.sideIndicator -eq "<=")
       {
           $CopyParams.Destination = $Folder2Path 
        }
        else
       {   $CopyParams.Destination = $Folder1Path 
       }
       Copy-Item @CopyParams -Force


   $copyParams2 = @{
       'Path' = $_.InputObject.fullname
       }
       if ($_.sideIndicator -eq "<=")
       {
           $CopyParams2.Destination = $Folder3Path
        }
        else
       {   $CopyParams2.Destination = $Folder2Path
       }
       Copy-Item @CopyParams2
       }`

0 个答案:

没有答案