-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Fetch - Run.ps1
69 lines (52 loc) · 1.81 KB
/
Fetch - Run.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
param(
[string]$configFilePath = ".\Config.json"
,
[array]$scriptsToRun = @(
".\Fetch - Activity.ps1"
".\Fetch - Catalog.ps1"
".\Fetch - Graph.ps1"
#".\Fetch - DataSetRefresh.ps1"
)
)
$ErrorActionPreference = "Stop"
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
Import-Module "$currentPath\Fetch - Utils.psm1" -Force
Write-Host "Current Path: $currentPath"
Write-Host "Config Path: $configFilePath"
if (Test-Path $configFilePath) {
$config = Get-Content $configFilePath | ConvertFrom-Json
# Default Values
if (!$config.OutputPath) {
$config | Add-Member -NotePropertyName "OutputPath" -NotePropertyValue ".\\Data" -Force
}
if ($config.ServicePrincipal -and !$config.ServicePrincipal.Environment) {
$config.ServicePrincipal | Add-Member -NotePropertyName "Environment" -NotePropertyValue "Public" -Force
}
}
else {
throw "Cannot find config file '$configFilePath'"
}
# Ensure Folders for PBI Report
@("$($config.OutputPath)\Activity", "$($config.OutputPath)\Catalog", "$($config.OutputPath)\Graph") | ForEach-Object {
New-Item -ItemType Directory -Path $_ -ErrorAction SilentlyContinue | Out-Null
}
try {
foreach ($scriptToRun in $scriptsToRun)
{
try {
Write-Host "Running '$scriptToRun'"
& $scriptToRun -config $config
}
catch {
Write-Error "Error on '$scriptToRun' - $($_.Exception.ToString())" -ErrorAction Continue
}
}
}
catch {
$ex = $_.Exception
if ($ex.ToString().Contains("429 (Too Many Requests)")) {
Write-Host "429 Throthling Error - Need to wait before making another request..." -ForegroundColor Yellow
}
Resolve-PowerBIError -Last
throw
}