-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.ps1
90 lines (72 loc) · 2.87 KB
/
Main.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
79
80
81
82
83
84
85
86
87
88
89
90
# Get the source directory from command line argument or use default "src"
param(
[string]$SourceDir = "src"
)
Write-Host "Current directory: $(pwd)"
Write-Host "Using source directory: $SourceDir"
# Read name of the folders under the specified source directory into an array
$CurrentWorkingDir = Get-Location
$folders = Get-ChildItem -Path "$CurrentWorkingDir/$SourceDir" -Directory | Select-Object -ExpandProperty Name
Write-Host "Folders in ${SourceDir}: $folders"
# Check if the folders array is empty
if ($folders.Count -eq 0) {
Write-Host "No folders found in ${SourceDir}. Exiting script."
exit 1
}
$officeApps = @()
function Get-OfficeApp {
param (
[Parameter(Mandatory=$true)]
[string]$FileExtension
)
switch -Regex ($FileExtension.ToLower()) {
'^(xlsb|xlsm||xltm|xlam)$' { return "Excel" }
'^(docm|dotm)$' { return "Word" }
'^(pptm|potm)$' { return "PowerPoint" }
'^(accdb|accda)$' { return "Access" }
default { return $null }
}
}
# Create a list of Office applications that are needed based on the file extensions of the folders
foreach ($folder in $folders) {
$FileExtension = $folder.Substring($folder.LastIndexOf('.') + 1)
$app = Get-OfficeApp -FileExtension $FileExtension
if ($app) {
if ($officeApps -notcontains $app) {
$officeApps += $app
}
} else {
Write-Host "Unknown file extension: $FileExtension. Skipping..."
continue
}
}
# We need to open and close the Office applications before we can enable VBOM
Write-Host "Open and close Office applications"
. "$PSScriptRoot/scripts/Open-Close-Office.ps1" $officeApps
Write-Host "========================="
# Enable VBOM for each Office application
foreach ($app in $officeApps) {
Write-Host "Enabling VBOM for $app"
. "$PSScriptRoot/scripts/Enable-VBOM.ps1" $app
Write-Host "========================="
}
# To get better screenshots we need to minimize the "Administrator" CMD window
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$scriptPath/scripts/utils/Minimize.ps1"
Minimize-Window "Administrator: C:\actions"
Write-Host "========================="
foreach ($folder in $folders) {
$app = Get-OfficeApp -FileExtension $folder.Substring($folder.LastIndexOf('.') + 1)
if ($app -eq "Access") {
Write-Host "Access is not supported at the moment. Skipping..."
continue
}
$ext = "zip"
Write-Host "Create Zip file and rename it to Office document target"
. "$PSScriptRoot/scripts/Zip-It.ps1" "${SourceDir}/${folder}"
Write-Host "Copy and rename the file to the correct name"
. "$PSScriptRoot/scripts/Rename-It.ps1" "${SourceDir}/${folder}" "$ext"
Write-Host "Importing VBA code into Office document"
. "$PSScriptRoot/scripts/Build-VBA.ps1" "${SourceDir}/${folder}" "$app"
Write-Host "========================="
}