-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoshEnvironment.ps1
81 lines (70 loc) · 2.46 KB
/
PoshEnvironment.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
function Get-BinPath
{
$scriptDirectory = Split-Path $PSCommandPath -Parent
return Join-Path $scriptDirectory "bin"
}
function Get-CustomizationsPath
{
$scriptDirectory = Split-Path $PSCommandPath -Parent
return Join-Path $scriptDirectory "customizations"
}
function Get-SamplesPath
{
$scriptDirectory = Split-Path $PSCommandPath -Parent
return Join-Path $scriptDirectory "samples"
}
function Add-SampleConfiguration
{
$computerName = $env:COMPUTERNAME.ToLower()
$configPath = Get-BinPath
$configFilePath = Join-Path $configPath "$computerName.json"
if (-not (Test-Path $configFilePath))
{
$samplesPath = Get-SamplesPath
$sampleFilePath = Join-Path $samplesPath "SampleConfig.json"
Write-Host -ForegroundColor Green "Creating sample config file at ""$configFilePath""."
New-Item $configFilePath -Force -Type File -ErrorAction Stop | Out-Null
Copy-Item $sampleFilePath $configFilePath -Force -ErrorAction Stop | Out-Null
}
return $configFilePath
}
function Initialize-Customization($customization)
{
Write-Host -NoNewline "Loading customization: $($customization.Name)... "
$scriptPath = $customization.Script
if (-not (Test-Path $scriptPath))
{
$customizationsPath = Get-CustomizationsPath
$scriptPath = Join-Path $customizationsPath $customization.Script
if (-not (Test-Path $scriptPath))
{
Write-Host -ForegroundColor Red "FAILURE -- Could not find script at ""$scriptPath"""
return
}
}
$result = . $scriptPath $customization.Settings
if ($result[0])
{
Write-Host -ForegroundColor Green "DONE"
}
else
{
Write-Host -ForegroundColor Red "FAILURE -- $($result[1])"
}
}
function Initialize-Profile($configJsonPath)
{
if ([String]::IsNullOrEmpty($configJsonPath) -or -not (Test-Path($configJsonPath)))
{
Write-Error "Initialize-Profile requires path to config json. $configJsonPath is not a valid path."
return
}
Write-Host -NoNewline "Reading JSON configuration... "
$config = (Get-Content $configJsonPath) -join "`n" | ConvertFrom-Json -ErrorAction Stop
Write-Host -ForegroundColor Green "DONE"
foreach ($customization in $config.Customizations | where { $_.Enabled -eq $true })
{
Initialize-Customization($customization)
}
Write-Host ""
}