-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISTAdminAPI.psm1
67 lines (61 loc) · 2.51 KB
/
ISTAdminAPI.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
$ModuleRoot = $PSScriptRoot
$Script:ISTAdminCheckSettingsFilePath = "$env:ProgramData\ISTAdminAPI\ISTAdminCheck-$($env:USERNAME)_$($env:COMPUTERNAME).checkfile"
$SettingsFileExists = $false
try {
Get-Variable -Name ISTSettings -Scope Global -ErrorAction Stop
# Write-Host "Settings funnen!" -ForegroundColor Green
$SettingsExist = $true
}
catch {
$SettingsExist = $false
# Write-Host "ISTSettings återfanns inte!" -ForegroundColor Red
}
$Private = @(Get-ChildItem -Path $ModuleRoot\Private\*.ps1 -ErrorAction SilentlyContinue)
$Public = @(Get-ChildItem -Path $ModuleRoot\Public\*.ps1 -ErrorAction SilentlyContinue)
$Nested = @(Get-ChildItem -Path $ModuleRoot\Resources\SecretClixml\Public\*.ps1 -ErrorAction SilentlyContinue)
foreach ($Import in @($Private + $Public + $Nested)) {
try {
. $Import.FullName
}
catch {
Write-Error -Message "Failed to import function $($Import.FullName): $_"
}
}
if (-not (Test-Path $ISTAdminCheckSettingsFilePath)) {
if (-not (Test-Path $($ISTAdminCheckSettingsFilePath | Split-Path))) {
try {
New-Item -Path $($ISTAdminCheckSettingsFilePath | Split-Path) -ItemType Directory
}
catch {
Write-Warning $_.Exception.Message
}
}
Write-Warning -Message "No settings file found. Please configure the module by running Initialize-SettingsFile provided with your information."
Export-ModuleMember -Function New-Secret, Get-Secret, Initialize-SettingsFile
}
elseif (-not (Test-Path -Path $(Get-Content -Path $ISTAdminCheckSettingsFilePath))) {
Write-Warning -Message "No settings file found. Please configure the module by running Initialize-SettingsFile provided with your information."
Export-ModuleMember -Function New-Secret, Get-Secret, Initialize-SettingsFile
}
else {
if (-not ($SettingsExist)) {
$CSV = Import-Csv -Path (Get-Content -Path $ISTAdminCheckSettingsFilePath)
New-Variable -Name ISTSettings -Value $CSV -Scope Global -Force
}
$SettingsFileExists = $true
Export-ModuleMember -Function $Public.Basename
# Export-ModuleMember -Function $Private.Basename
Export-ModuleMember -Function $Nested.Basename
}
switch ($SettingsFileExists) {
True {
if (-not ($SettingsExist)) {
Export-ModuleMember -Variable ISTSettings
}
else {
Write-Host "Reusing existing Settings variable." -ForegroundColor Green
}
}
False {Export-ModuleMember -Variable ISTAdminCheckSettingsFilePath}
Default {}
}