我有以下兩個函數,我希望在比較函數中使用ROBOCOPY函數的源和目標。任何人都可以告訴我如何做到這一點。謝謝。使用函數中的值並將其傳遞給另一個函數
Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host "Pre-Staging Script for DFSR Server" -ForegroundColor Magenta -BackgroundColor White
Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host ""
Function GetHot-Fix
{
Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host "Checking Service Installation" -ForegroundColor Magenta -BackgroundColor White
Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host ""
write-host "This will check if Hotfix KB979808 is installed." -ForegroundColor Black -BackgroundColor Cyan
write-host "This is required for Windows Server 2008 R2 Robocopying" -ForegroundColor Black -BackgroundColor Cyan
Write-Host ""
Get-HotFix -id KB979808 -ErrorAction SilentlyContinue
}
Function Start-MyRobocopy($source,$Target)
{
Write-Host "=============" -ForegroundColor Magenta -BackgroundColor White
Write-Host "Robocopy Data" -ForegroundColor Magenta -BackgroundColor White
Write-Host "=============" -ForegroundColor Magenta -BackgroundColor White
Write-Host ""
$Source = Read-Host "Please enter path of SOURCE"
If ($Source -and (Test-Path -Path $Source -PathType Container))
{
$Target = Read-Host "Please enter path of TARGET"
}
Else
{
Write-Host "Please enter a directory"
}
If ($Target -and (Test-Path -Path $Target -PathType Container))
{
$Output = Read-Host "Please enter where to place output file eg c:\temp\COPY.log"
}
Else
{
Write-Host "Please enter a directory"
}
robocopy.exe $Source $Target /b /e /copyall /r:1 /xd dfsrprivate /log:$Output /tee
}
Function Comparision
{
Write-Host ""
Write-Host ""
Write-Host "===============================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host "Checking Directory Count and Folder comparision" -ErrorAction SilentlyContinue -ForegroundColor Magenta -BackgroundColor White
Write-Host "===============================================" -ForegroundColor Magenta -BackgroundColor White
Write-Host ""
#$Source = Read-Host "Please enter Source directory to check"
#$Target = Read-Host "Please enter Target directory to check"
Write-Host ""
If($source -and (Test-Path -Path $source -PathType Container))
{
"There are $(@(Get-ChildItem $Source).Count) items in the '$Source' directory"
}
Else
{
Write-Host "Please enter a directory"
}
If($source -and (Test-Path -Path $Target -PathType Container))
{
"There are $(@(Get-ChildItem $Target).Count) items in the '$Target' directory"
}
Else
{
Write-Host "Please enter a directory"
}
Write-Host ""
$child1 = Get-ChildItem -Path $Source -Recurse -Force
$child2 = Get-ChildItem -Path $Target -Recurse -Force
Compare-Object $child1 -DifferenceObject $child2 -Property Name
Write-Host ""
Write-Host "NOTE:" -BackgroundColor Cyan -ForegroundColor Black
Write-Host "Any symbols with '=>' mean that the file Does NOT exist in SOURCE but is in the Target" -BackgroundColor Cyan -ForegroundColor Black
Write-Host "Any symbols with '<=' mean that the file Does NOT exist in TARGET but is in the Source" -BackgroundColor Cyan -ForegroundColor Black
}
$hotfix = GetHot-Fix
If ($hotfix) {
Write-Host "Hotfix installed" -BackgroundColor Green -ForegroundColor Black
Write-Host ""
Write-Host "Proceeding with Robocopy...."
Write-Host "............................"
Write-Host ""
Start-MyRobocopy
}
else {
Write-Host "Hotfix is NOT installed - Please ensure you install this hotfix BEFORE" -ForegroundColor "red"
Write-host "Copying any data" -foregroundcolor "red"
Write-Host ""
return
}
Comparision
比較如何調用?它是與robocopy分離還是會從robocopy中調用? – SirPentor
嗨 - 我已經更新了整個腳本,你可以看到它是如何運行的。 – lara400
有完整源代碼的最終解決方案? – Kiquenet