forked from AymericM78/PowerDataOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerDataOps.psm1
More file actions
50 lines (44 loc) · 2.29 KB
/
PowerDataOps.psm1
File metadata and controls
50 lines (44 loc) · 2.29 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
# Discover and load function scripts
$scriptFiles = @(Get-ChildItem -Path "$PSScriptRoot\src\" -Include "*.ps1" -Recurse);
foreach ($scriptFile in $scriptFiles) {
$scriptPath = $scriptFile.FullName;
Write-Verbose " > Loading function file '$scriptPath'";
try {
. $scriptPath;
Write-Verbose " > Loading function file '$scriptPath' => OK !";
}
catch {
$errorMessage = $_.Exception.Message;
Write-Verbose " > Loading function file '$scriptPath' => KO ! Reason = '$errorMessage'";
}
}
# Install and Import required modules
$requiredModules = @("Microsoft.Xrm.Tooling.CrmConnector.PowerShell", "Microsoft.PowerApps.Administration.PowerShell")
foreach ($module in $requiredModules) {
if (-not(Get-Module -ListAvailable -Name $module)) {
Write-Verbose "$module does not exist";
Install-Module -Name $module -Scope CurrentUser -SkipPublisherCheck -Force -Confirm:$false -AllowClobber;
}
else {
# TODO : Update Module only if a newer version exist
#Update-Module -Name $module -Scope CurrentUser -SkipPublisherCheck -Force -Confirm:$false -AllowClobber;
}
Import-Module -Name $module -DisableNameChecking;
Write-Verbose " > Loading module : '$module' => OK !";
}
# Loading assemblies
$binFolderPath = "$PSScriptRoot\src\Solutions\bin";
$assemblies = @("$binFolderPath\Microsoft.Xrm.Sdk.dll", "$binFolderPath\Microsoft.Crm.Sdk.Proxy.dll", "$binFolderPath\Microsoft.Xrm.Tooling.Connector.dll");
foreach ($assemblyPath in $assemblies) {
Add-Type -Path $assemblyPath;
Write-Verbose " > Loading assembly file '$assemblyPath' => OK !";
}
# Provision dedicate appdata folder
$Global:PowerDataOpsModuleFolderPath = [System.IO.Path]::Combine($env:APPDATA, "PowerDataOps");
New-Item -ItemType Directory -Path $Global:PowerDataOpsModuleFolderPath -Force | Out-Null;
Write-Verbose " > Initialize module folder '$($Global:PowerDataOpsModuleFolderPath)' => OK !";
# Initialize tracing file
$timestamp = Get-date -format "yyyy-MM-dd -- HH-mm-ss";
New-Item -ItemType Directory -Path $Global:PowerDataOpsModuleFolderPath -Name "Logs" -Force | Out-Null;
$Global:LogFolderPath = [System.IO.Path]::Combine($Global:PowerDataOpsModuleFolderPath, "Logs");
$Global:LogFilePath = [System.IO.Path]::Combine($Global:LogFolderPath, "$timestamp.log");