1
- function Export-ITGlueModuleSettings {
1
+ # Locations of settings path and file
2
+ $ITGlueAPIConfPath = " $ ( $env: USERPROFILE ) \ITGlueAPI"
3
+ $ITGlueAPIConfFile = " config.psd1"
2
4
3
- $secureString = $ITGlue_API_KEY | ConvertFrom-SecureString
4
- $outputPath = " $ ( $env: USERPROFILE ) \ITGlueAPI"
5
- New-Item - ItemType Directory - Force - Path $outputPath | % {$_.Attributes = " hidden" }
5
+ function Export-ITGlueModuleSettings {
6
+ # Confirm variables exist and are not null before exporting
7
+ if ($ITGlue_Base_URI -and $ITGlue_API_Key -and $ITGlue_JSON_Conversion_Depth ) {
8
+ $secureString = $ITGlue_API_KEY | ConvertFrom-SecureString
9
+ New-Item - ItemType Directory - Force - Path $ITGlueAPIConfPath | ForEach-Object {$_.Attributes = " hidden" }
6
10
@"
7
11
@{
8
12
ITGlue_Base_URI = '$ITGlue_Base_URI '
9
13
ITGlue_API_Key = '$secureString '
10
14
ITGlue_JSON_Conversion_Depth = '$ITGlue_JSON_Conversion_Depth '
11
15
}
12
- "@ | Out-File - FilePath ($outputPath + " \config.psd1" ) - Force
13
-
14
-
16
+ "@ | Out-File - FilePath ($ITGlueAPIConfPath + " \" + $ITGlueAPIConfFile ) - Force
17
+ }
18
+ else {
19
+ Write-Host " Failed export ITGlue Module settings to $ITGlueAPIConfPath \$ITGlueAPIConfFile "
20
+ }
15
21
}
16
22
17
-
18
-
19
23
function Import-ITGlueModuleSettings {
20
24
21
- # PLEASE ADD ERROR CHECKING
25
+ # PLEASE ADD ERROR CHECKING SUCH AS TESTING FOR VALID VARIABLES?
22
26
23
- if (test-path " $ ( $ env: USERPROFILE ) \ITGlueAPI " ) {
24
- $tmp_config = Import-LocalizedData - BaseDirectory " $ ( $ env: USERPROFILE ) \ITGlueAPI " - FileName " config.psd1 "
27
+ if (test-path ( $ITGlueAPIConfPath + " \ " + $ITGlueAPIConfFile ) ) {
28
+ $tmp_config = Import-LocalizedData - BaseDirectory $ITGlueAPIConfPath - FileName $ITGlueAPIConfFile
25
29
26
30
# Send to function to strip potentially superflous slash (/)
27
31
Add-ITGlueBaseURI $tmp_config.ITGlue_Base_URI
@@ -34,19 +38,19 @@ function Import-ITGlueModuleSettings {
34
38
Set-Variable - Name " ITGlue_JSON_Conversion_Depth" - Value $tmp_config.ITGlue_JSON_Conversion_Depth `
35
39
- Scope global - Force
36
40
41
+ Write-Host " ITGlueAPI Module configuration loaded successfully from $ITGlueAPIConfPath \$ITGlueAPIConfFile !" - ForegroundColor Green
42
+
37
43
# Clean things up
38
44
Remove-Variable " tmp_config"
39
-
40
- Write-Host " Module configuration loaded successfully!" - ForegroundColor Green
41
45
}
42
46
else {
43
- Write-Host " No configuration file was found." - ForegroundColor Red
47
+ Write-Host " No configuration file was found at $ITGlueAPIConfPath \ $ITGlueAPIConfFile ." - ForegroundColor Red
44
48
45
- Set-Variable - Name " ITGlue_Base_URI" - Value " https://api.itglue.com" - Option ReadOnly - Scope global - Force
49
+ Set-Variable - Name " ITGlue_Base_URI" - Value " https://api.itglue.com" - Option ReadOnly - Scope global - Force
46
50
47
51
Write-Host " Using https://api.itglue.com as Base URI. Run Add-ITGlueBaseURI to modify."
48
52
Write-Host " Please run Add-ITGlueAPIKey to get started." - ForegroundColor Red
49
53
50
- Set-Variable - Name " ITGlue_JSON_Conversion_Depth" - Value 100 - Scope global - Force
54
+ Set-Variable - Name " ITGlue_JSON_Conversion_Depth" - Value 100 - Scope global - Force
51
55
}
52
56
}
0 commit comments