-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathprepare_Everything.ps1
54 lines (38 loc) · 1.21 KB
/
prepare_Everything.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
$myPath = Split-Path $script:MyInvocation.MyCommand.Path
$scriptsInOrder = Get-ChildItem ($myPath) -Directory | ForEach-Object { Get-ChildItem (($_.FullName) + "\*.ps1") -Recurse } | Where-Object {!$_.Name.StartsWith("~")} | Sort-Object
$outFile = ".\Everything.ps1"
$dateTime = [DateTime]::UtcNow
$header = @"
## Created: $dateTime
`$jobs = @{}
"@
$footer = @"
#Process All Jobs
Write-Progress -Activity "Processing Jobs" -Status "Starting..."
`$i = 0
`$jobs.Keys | % {
`$key = `$_
`$i++
Write-Progress -Activity "Processing Jobs" -Status `$key -PercentComplete (`$i / `$jobs.Count * 100)
Invoke-Command -ScriptBlock `$jobs[`$key] -ErrorAction Stop
}
Write-Progress -Activity "Processing Jobs" -Status "Completed" -Completed
"@
$header | Set-Content -Path $outFile
$scriptsInOrder | % {
$shortname = $_.Name.Replace(".ps1","")
$longname = $_.FullName.Replace($pwd, "")
$scriptBlock = Get-Content -Path $_ -Raw
if ($shortname.StartsWith("_")) {
$scriptBlock | Add-Content -Path $outFile
} else {
$jobBody = @"
## Job: $shortname, $_
`$jobs.Add("$longname", {
$scriptBlock
})
"@
$jobBody | Add-Content -Path $outFile
}
}
$footer | Add-Content -Path $outFile