forked from mmessano/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDMartSyncTRNByClient.ps1
79 lines (62 loc) · 2.05 KB
/
DMartSyncTRNByClient.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# DMartSyncTRNByClient.ps1
# copy trn files from one server\folder to another server\folder
param(
$Client = 'GTE'
, $TrnSourcePath = '\\psqlrpt24\e$\MSSQL10.MSSQLSERVER\MSSQL\TRN\'
, $TrnDestPath = '\\pcon310\Relateprod\FTP sites\'
)
#clear the console screen
cls
$a = get-date
$b = $a.AddMinutes(-15)
$ClientSrcPath = $TrnSourcePath + '\DMart_' + $Client + 'CDC_Data\'
#Write-Host "ClientPath: " $ClientPath
if (!(Test-Path -Path $ClientSrcPath)){
Write-Host "$ClientSrcPath not found!"
break;
}
ELSE {
#Write-Host "Found $ClientSrcPath."
$CopyFrom = @(Get-ChildItem -path "$ClientSrcPath*.trn" ) | Where-Object{$_.LastWriteTime -lt $b}
}
#Write-Host "CopyFrom: " $CopyFrom
Write-Host
$ClientDestPath = $TrnDestPath + $Client + 'prodrpt\'
#Write-Host "ClientDestPath: " $ClientDestPath
if (!(Test-Path -Path $ClientDestPath)) {
Write-Host "$ClientDestPath not found!"
break;
}
ELSE {
#Write-Host "Found $ClientDestPath."
$CopyTo = @(Get-ChildItem -path "$ClientDestPath*.trn")
}
#Write-Host "CopyTo: " $CopyTo
$Files2Copy = Compare-Object -ReferenceObject $CopyFrom -DifferenceObject $CopyTo -Property name, length -PassThru | Where-Object {$_.SideIndicator -eq "<="}
#$Files2Copy
if ($Files2Copy -ne $NULL)
{
foreach ($File in $Files2Copy)
{
write-host "This will copy File $($File.FullName) to $ClientDestPath$($File.Name)" -ForegroundColor "Red"
Copy-Item -Path $($File.FullName) -Destination $ClientDestPath$($File.Name) -whatif
}
}
else
{
Write-Host "No files to copy for $Client!" -foregroundcolor "blue"
}
$Files2Delete = Compare-Object -ReferenceObject $CopyFrom -DifferenceObject $CopyTo -IncludeEqual -Property name, length -PassThru | Where-Object {$_.SideIndicator -eq "=>"}
$Files2Delete
if ($Files2Delete -ne $NULL)
{
foreach ($File in $Files2Delete)
{
write-host "This will delete File $($File.FullName)" -ForegroundColor "Red"
Remove-Item -Path $($File.FullName) -whatif
}
}
else
{
Write-Host "No files to delete for $Client!" -foregroundcolor "blue"
}