forked from mcollera/AccessControlDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessControlDsc.psm1
More file actions
67 lines (51 loc) · 1.65 KB
/
AccessControlDsc.psm1
File metadata and controls
67 lines (51 loc) · 1.65 KB
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
function Invoke-AccessControlDsc {
<#
.SYNOPSIS
Invokes the specified method on the AccessControlDsc resource.
.DESCRIPTION
This script is used to invoke methods on the AccessControlDsc resource, such as Test, Get, or Set.
.PARAMETER ResourceName
The name of the resource to invoke.
.PARAMETER Method
The method to invoke (Test, Get, or Set).
.PARAMETER Json
The JSON string containing parameters for the method invocation.
.EXAMPLE
Invoke-AccessControlDsc -ResourceName "NtfsAccessEntry" -Method "Test" -Json '{"Path": "C:\example", "IdentityReference": "DOMAIN\User", "FileSystemRights": "FullControl"}'
#>
[CmdletBinding()]
[OutputType([System.String])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet("NtfsAccessEntry")]
[String]
$ResourceName,
[Parameter(Mandatory = $true)]
[ValidateSet("Test", "Get", "Set")]
[String]
$Method,
[Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)]
[String]
$Json
)
# Import the module for the specified resource
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath "DscResources\$ResourceName\$ResourceName.psm1"
$functionName = "$Method-$ResourceName"
Set-Content -Path "C:\temp\ntfs.log" -Value "Received Json: $Json"
return
$content = $Json | ConvertFrom-Json -AsHashtable
Import-Module -Name $modulePath -Force
$result = & $functionName @content
$final = @{}
switch ($Method) {
"Test" {
$final = $content
$final."_InDesiredState" = $result
}
"Get" { $content._CurrentState = $result }
Default {}
}
# Convert the result back to JSON
return ($final | ConvertTo-Json -Depth 10)
}