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_Deployment_Scripting - Fatal编程技术网

与Powershell进行远程目录比较的最佳方法

与Powershell进行远程目录比较的最佳方法,powershell,deployment,scripting,Powershell,Deployment,Scripting,我有两个文件夹: $srcPath = \\stagingserver $destPath = \\productionserver 我想比较这两者,以确定$src文件夹中有哪些更改尚未推送到生产环境中。该项目有约4000个文件,超过100个目录,总计约80mb。我目前正在进行哈希比较,如下所示: $src = Get-ChildItem $srcPath -Recurse $dest = Get-ChildItem $destPath -Recurse $same = Compare-Ob

我有两个文件夹:

$srcPath = \\stagingserver
$destPath = \\productionserver
我想比较这两者,以确定$src文件夹中有哪些更改尚未推送到生产环境中。该项目有约4000个文件,超过100个目录,总计约80mb。我目前正在进行哈希比较,如下所示:

$src = Get-ChildItem $srcPath -Recurse
$dest = Get-ChildItem $destPath -Recurse 
$same = Compare-Object $src $dest -Property Name, Length, LastWriteTime -passthru -includeequal -excludeDifferent

$srcTree = Get-ChildItem $src -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash
$destTree = Get-ChildItem $dest -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash  

$diff = Compare-Object -ReferenceObject $srcTree -differenceObject $destTree | ? {$_.SideIndicator -eq "<=" } | % {$_.InputObject.Path}
$src=Get ChildItem$srcPath-Recurse
$dest=获取子项$destPath-递归
$same=比较对象$src$dest-属性名称、长度、LastWriteTime-passthru-includeequal-excludeDifferent
$srcTree=Get ChildItem$src-Recurse-exclude$same | Where Object{!$\uu0.psiscontainer}| Get hash
$destTree=Get ChildItem$dest-Recurse-exclude$same | Where Object{!$\uuu.psiscontainer}| Get hash

$diff=比较对象-引用对象$srcTree-差异对象$destTree |?{$\侧指示器-等式“您可以使用
robocopy
将暂存共享内容同步到生产共享中,而不是比较文件。
/MIR
标志可用于镜像,即从目标中删除不存在的文件。robocopy使用时间戳确定是否需要复制文件,因此有一些警告

如果需要散列,您可以在远程服务器上创建一个脚本,将文件散列存储在CSV文件中。之后,导入CSV文件并将本地散列与文件内容进行比较应该很容易