-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDistribute-LatestVersionOfFile.ps1
More file actions
70 lines (64 loc) · 3.28 KB
/
Distribute-LatestVersionOfFile.ps1
File metadata and controls
70 lines (64 loc) · 3.28 KB
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
<#
.SYNOPSIS
Finds the latest version of a file and copy it over all other existing copies within the base directory you specify
.DESCRIPTION
This is a way of ensuring that the latest version of the file is updated everywhere within the directory structure
.PARAMETER BaseDirectory
The base directory of the location where the alterations can take place
.PARAMETER Filename
The name of the file that you want synchronized across the location
.EXAMPLE
Distribute-LatestVersionOfFile '<MyPathTo>Github' 'DatabaseBuildAndMigrateTasks.ps1'
Distribute-LatestVersionOfFile '<MyPathTo>Github' 'preliminary.ps1'
$AllflywayProjects=@("s:\work\Github\PubsAndFlyway","<MyPathTo>FlywayTeamwork","<MyPathTo>FlywayDevelopments")
Distribute-LatestVersionOfFile @("<MyPathTo>Github","<MyPathTo>FlywayDevelopments") 'DatabaseBuildAndMigrateTasks.ps1'
Distribute-LatestVersionOfFile @("<MyPathTo>Github","<MyPathTo>FlywayDevelopments") 'DatabaseBuildAndMigrateTasks.ps1' -verbose
Distribute-LatestVersionOfFile -BaseDirectories $AllflywayProjects 'afterMigrate__Add_Version_EP.sql' -verbose
Distribute-LatestVersionOfFile $AllflywayProjects 'preliminary.ps1' -verbose
Distribute-LatestVersionOfFile '<MyPathTo>\Github\FlywayTeamwork\' 'preliminary.ps1' -verbose
.NOTES
Additional information about the function.
#>
function Distribute-LatestVersionOfFile
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string[]]$BaseDirectories,
[Parameter(Mandatory = $true)]
[string]$Filename
)
$SortedList = @() # the complete list of the locations of the file specified
$TheListOfDirectories=@()
$TheListOfDirectories = $BaseDirectories | foreach{ "$($_)\$Filename" }
#add the filename to each of the directories you specify
$canonicalVersion = dir $TheListOfDirectories -recurse -OutVariable +SortedList |
Sort-Object -Property lastWriteTime -Descending |
select-object -first 1 #we get one of the collection with the latest date
$VersionDate = $canonicalVersion.LastWriteTime #get the date of the file
#now update every file of the same name with an earlier date
$SortedList |
where { $_.LastWriteTime -lt $VersionDate } |
foreach{
Write-Verbose "Updating $($_.FullName) to the version in $($canonicalVersion.FullName)";
Copy-Item -path $canonicalVersion -destination $_ -force
}
}
Distribute-LatestVersionOfFile 'S:\work\Git\GitStuff' 'afterMigrate__ApplyTableDescriptions.sql' -verbose
dir 'S:\work\Git\GitStuff\afterMigrate__ApplyTableDescriptions.sql' -Recurse
$SortedList = @() # the complete list of the locations of the file specified
$TheListOfDirectories=@()
$TheListOfDirectories = $BaseDirectories | foreach{ "$($_)\$Filename" }
#add the filename to each of the directories you specify
$canonicalVersion = dir $TheListOfDirectories -recurse -OutVariable +SortedList |
Sort-Object -Property lastWriteTime -Descending |
select-object -first 1 #we get one of the collection with the latest date
$VersionDate = $canonicalVersion.LastWriteTime #get the date of the file
#now update every file of the same name with an earlier date
$SortedList |
where { $_.LastWriteTime -lt $VersionDate } |
foreach{
Write-Verbose "Updating $($_.FullName) to the version in $($canonicalVersion.FullName)";
Copy-Item -path $canonicalVersion -destination $_ -force
}