-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEdit-Config.ps1
87 lines (83 loc) · 2.69 KB
/
Edit-Config.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
82
83
84
85
86
87
<#
.SYNOPSIS
Edit-Config
Created By: Dana Meli-Wischman
Created Date: December, 2019
Last Modified Date: March 21, 2021
.DESCRIPTION
This script is designed to read and edit json configuration files for all PowerShell scripts.
Also used as the settings manager for the json configuration files.
.EXAMPLE
Edit-Config -Confile [string] -Count [string] -Read [string] -Write [string] -Section [string] -SValue [string] -BValue [bool]
.NOTES
Still under development.
But it has beeb awhile.
#>
[CmdLetBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Confile,
[Parameter(Mandatory = $false)]
[AllowEmptyString()]
[string]$Count,
[Parameter(Mandatory = $false)]
[string]$Read,
[Parameter(Mandatory = $false)]
[string]$Write,
[Parameter(Mandatory = $false)]
[string]$Section,
[Parameter(Mandatory = $false)]
[string]$SValue,
[Parameter(Mandatory = $false)]
[bool]$BValue,
[Parameter(Mandatory = $false)]
[string]$Sub
)
$FileVersion = "0.0.6"
$Script:ConfigFile = $Confile
try { $Script:Config = Get-Content $Configfile -Raw | ConvertFrom-Json }
catch { Say -ForeGroundColor RED "Edit-Config $FileVersion - The file $Confile is missing!"; break }
if (($Count)) { $Feedback = ($Config.$Count).count }
if (($Read)) {
if (($Sub)) { $Feedback = ($Config.$Read)[$Section].$Sub }
else {
#use [double] for dec nums (1.5)
if ($section -is [int]) { $Feedback = ($Config.$Read)[$Section] }
else { $Feedback = ($Config.$Read.$Section) }
}
}
if (($Write)) {
if (($SValue)) {
if (($Sub)) {
($Config.$Write)[$Section].$Sub = [string]$SValue
$Config | ConvertTo-Json | Set-Content $ConfigFile
$Read = $Write
$Feedback = ($Config.$Read)[$Section].$Sub
}
else {
$Config.$Write.$Section = [string]$SValue
$Config | ConvertTo-Json | Set-Content $ConfigFile
$Read = $Write
$Feedback = ($Config.$Read.$Section)
}
}
#
# WORKING COMMAND FOR FINISH
# Edit-Config -Conf 'D:\bin\Test.json' -Write AddItems -Section 0 -Sub Command -SValue "C:\Windows\Regedit.exe"
#
#if ($true -eq $BValue -or $false -eq $BValue) {
#if (($Sub)) {
# ($Config.$Write)[$Section].$Sub = [bool]$BValue
# $Config | ConvertTo-Json | Set-Content $ConfigFile
# $Read = $Write
# $Feedback = ($Config.$Read)[$Section].$Sub
#}
#else {
#$Config.$Write.$Section = [bool]$BValue
#$Config | ConvertTo-Json | Set-Content $ConfigFile
#$Read = $Write
#$Feedback = ($Config.$Read.$Section)
#}
#}
}
return $Feedback