Repository navigation
Expand file tree
/
Copy pathRemove-ModuleAccessRole.ps1
More file actions
53 lines (43 loc) · 1.92 KB
/
Copy pathRemove-ModuleAccessRole.ps1
File metadata and controls
53 lines (43 loc) · 1.92 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
<#
.SYNOPSIS
Remove a persisted module access role by name
.DESCRIPTION
Deletes the role JSON file from the module `AccessRoles` folder after
sanitizing the role name into a safe filename. Reloads module access control
definitions to reflect the deletion in the current runtime.
.PARAMETER RoleName
| Name | Type | Description | Default |
|----------|---------------|-----------------------------|---------|
| RoleName | System.String | Name of the role to remove. | '' |
.OUTPUTS
System.Object -- Structured return object from Write-FunctionReturnValue when the
role name is empty; otherwise None.
.EXAMPLE
PS> Remove-ModuleAccessRole -RoleName 'admin'
Removes the persisted access role file for admin and reloads the in-memory
access control definitions.
.NOTES
Uses Remove-SecureItem to safely delete the role file and then calls
Read-ModuleAccessControl to refresh the in-memory role list for the current
session.
SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
SPDX-License-Identifier: GPL-3.0-or-later
#>
function Remove-ModuleAccessRole()
{
param (
[string]$RoleName = ''
);
# Ensure we specify a name for the role
if ([string]::IsNullOrEmpty($RoleName)) {
return (Write-FunctionReturnValue -ReturnValue 'AccessRoleNoRoleNameProvided');
};
# Remove invalid filename characters from the role name for file saving
[string]$SafeRoleName = Remove-ModuleAmbitiousCharacters -InputString $RoleName -RemoveSpaces;
[string]$AccessRoleFile = Join-Path -Path (Get-ModuleConfigDirectory) -ChildPath ([string]::Format('AccessRoles\{0}.json', $SafeRoleName.ToLower()));
# Remove the access role file
Remove-SecureItem -Path $AccessRoleFile | Out-Null;
# Reload access control definitions to include the new role for the current session
# This will not updated the current active thread's access role assignments
Read-ModuleAccessControl;
}