-
Notifications
You must be signed in to change notification settings - Fork 50
/
Lability.psm1
71 lines (63 loc) · 3.29 KB
/
Lability.psm1
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
#Requires -RunAsAdministrator
## Set the global defaults
$labDefaults = @{
ModuleRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent;
ModuleName = 'Lability';
ConfigurationData = 'Config';
HostConfigFilename = 'HostDefaults.json';
VmConfigFilename = 'VmDefaults.json';
MediaConfigFilename = 'Media.json';
CustomMediaConfigFilename = 'CustomMedia.json';
LegacyMediaPath = 'LegacyMedia';
DscResourceDirectory = 'DSCResources';
RepositoryUri = 'https://www.powershellgallery.com/api/v2/package';
DismVersion = $null;
}
#region LocalizedData
$culture = 'en-us'
if (Test-Path -Path (Join-Path -Path $labDefaults.ModuleRoot -ChildPath $PSUICulture)) {
$culture = $PSUICulture
}
$importLocalizedDataParams = @{
BindingVariable = 'localized';
Filename = 'Lability.Resources.psd1';
BaseDirectory = $moduleRoot;
UICulture = $culture;
}
Import-LocalizedData @importLocalizedDataParams;
#endregion LocalizedData
## Import the \Src files. This permits loading of the module's functions for unit testing, without having to unload/load the module.
$moduleRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent;
$moduleSrcPath = Join-Path -Path $moduleRoot -ChildPath 'Src';
Get-ChildItem -Path $moduleSrcPath -Include *.ps1 -Exclude '*.Tests.ps1' -Recurse |
ForEach-Object {
Write-Verbose -Message ('Importing library\source file ''{0}''.' -f $_.FullName);
# https://becomelotr.wordpress.com/2017/02/13/expensive-dot-sourcing/
. ([System.Management.Automation.ScriptBlock]::Create(
[System.IO.File]::ReadAllText($_.FullName)
));
}
## Deploy builtin certificates to %ALLUSERSPROFILE%\PSLab
$moduleConfigPath = Join-Path -Path $moduleRoot -ChildPath 'Config';
$allUsersConfigPath = Join-Path -Path $env:AllUsersProfile -ChildPath "$($labDefaults.ModuleName)\Certificates\";
[ref] $null = New-Directory -Path $allUsersConfigPath;
Get-ChildItem -Path $moduleConfigPath -Include *.cer, *.pfx -Recurse | ForEach-Object {
if (-not (Test-Path -Path (Join-Path -Path $allUsersConfigPath -ChildPath $_.Name))) {
Write-Verbose -Message ('Updating certificate ''{0}''.' -f $_.FullName);
Copy-Item -Path $_ -Destination $allUsersConfigPath;
}
}
## Create the credential check scriptblock
$credentialCheckScriptBlock = {
## Only prompt if -Password is not specified. This works around the credential pop-up regardless of the ParameterSet!
if ($PSCmdlet.ParameterSetName -eq 'PSCredential') {
Get-Credential -Message $localized.EnterLocalAdministratorPassword -UserName 'LocalAdministrator';
}
}
## Store the BitLocker full drive encryption status (used bu Disable-BitLockerFDV and Assert-BitLockerFDV functions)
$fdvDenyWriteAccessPath = 'HKLM:\SYSTEM\CurrentControlSet\Policies\Microsoft\FVE'
$fdvDenyWriteAccess = (Get-ItemProperty -Path $fdvDenyWriteAccessPath -Name 'FDVDenyWriteAccess' -ErrorAction SilentlyContinue).FDVDenyWriteAccess -as [System.Boolean]
## Load the call stack logging setting referenced by Write-Verbose
$labDefaults['CallStackLogging'] = (Get-LabHostDefault).EnableCallStackLogging -eq $true;
## Ensure we load the required DISM module version
Import-DismModule;