-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-WEMIniFileOperation.ps1
115 lines (91 loc) · 3.85 KB
/
New-WEMIniFileOperation.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<#
.Synopsis
Create a new Ini File Operation Action object in the WEM Database.
.Description
Create a new Ini File Operation Action object in the WEM Database.
.Link
https://msfreaks.wordpress.com
.Parameter IdSite
..
.Parameter Name
..
.Parameter Description
..
.Parameter State
..
.Parameter ActionType
..
.Parameter TargetPath
..
.Parameter TargetSectionName
..
.Parameter TargetValueName
..
.Parameter TargetValue
..
.Parameter RunOnce
..
.Parameter Connection
..
.Example
.Notes
Author: Arjan Mensch
#>
function New-WEMIniFileOperation {
[CmdletBinding()]
param (
[Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$True, ValueFromPipeline=$True)]
[int]$IdSite,
[Parameter(Mandatory=$True)]
[string]$Name,
[Parameter(Mandatory=$False)]
[string]$Description = "",
[Parameter(Mandatory=$False)][ValidateSet("Enabled","Disabled")]
[string]$State = "Enabled",
[Parameter(Mandatory=$False)][ValidateSet("Write Ini File Value")]
[string]$ActionType = "Write Ini File Value",
[Parameter(Mandatory=$True)]
[string]$TargetPath,
[Parameter(Mandatory=$True)]
[string]$TargetSectionName,
[Parameter(Mandatory=$True)]
[string]$TargetValueName,
[Parameter(Mandatory=$False)]
[string]$TargetValue,
[Parameter(Mandatory=$False)]
[bool]$RunOnce = $true,
[Parameter(Mandatory=$True)]
[System.Data.SqlClient.SqlConnection]$Connection
)
process {
Write-Verbose "Working with database version $($script:databaseVersion)"
# escape possible query breakers
$Name = ConvertTo-StringEscaped $Name
$Description = ConvertTo-StringEscaped $Description
$TargetSectionName = ConvertTo-StringEscaped $TargetSectionName
$TargetValueName = ConvertTo-StringEscaped $TargetValueName
$TargetValue = ConvertTo-StringEscaped $TargetValue
# name is unique if it's not yet used in the same Action Type in the site
$SQLQuery = "SELECT COUNT(*) AS ObjectCount FROM VUEMIniFilesOps WHERE Name LIKE '$($Name)' AND IdSite = $($IdSite)"
$result = Invoke-SQL -Connection $Connection -Query $SQLQuery
if ($result.Tables.Rows.ObjectCount) {
# name must be unique
Write-Error "There's already a Ini File Operation object named '$($Name)' in the Configuration"
Break
}
Write-Verbose "Name is unique: Continue"
# build the query to update the action
$SQLQuery = "INSERT INTO VUEMIniFilesOps (IdSite,Name,Description,State,ActionType,TargetPath,TargetSectionName,TargetValueName,TargetValue,RunOnce,RevisionId,Reserved01) VALUES ($($IdSite),'$($Name)','$($Description)',$($tableVUEMState[$State]),$($tableVUEMIniFileOpActionType[$ActionType]),'$($TargetPath)','$($TargetSectionName)','$($TargetValueName)','$($TargetValueName)',$([int]$RunOnce),1,NULL)"
$null = Invoke-SQL -Connection $Connection -Query $SQLQuery
# grab the new action
$SQLQuery = "SELECT * FROM VUEMIniFilesOps WHERE IdSite = $($IdSite) AND Name = '$($Name)'"
$result = Invoke-SQL -Connection $Connection -Query $SQLQuery
# Updating the ChangeLog
$IdObject = $result.Tables.Rows.IdIniFileOp
New-ChangesLogEntry -Connection $Connection -IdSite $IdSite -IdElement $IdObject -ChangeType "Create" -ObjectName $Name -ObjectType "Actions\Ini File Operation" -NewValue "N/A" -ChangeDescription $null -Reserved01 $null
# Return the new object
return New-VUEMIniFileOpObject -DataRow $result.Tables.Rows
#Get-WEMIniFileOperation -Connection $Connection -IdAction $IdObject
}
}
New-Alias -Name New-IniFilesOp -Value New-WEMIniFileOperation