-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add-TssDirectoryServiceGroup - new command
Add a Domain Group to Directory Service for sync
- Loading branch information
Showing
3 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
docs/commands/directory-services/Add-TssDirectoryServiceGroup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Add-TssDirectoryServiceGroup | ||
|
||
## SYNOPSIS | ||
Add or link a Directory Service Group to synchronize | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Add-TssDirectoryServiceGroup [-TssSession] <Session> -DomainId <Int32> -GroupName <String> | ||
[-DomainIdentifier <Guid>] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Add or link a Directory Service Group to synchronize | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Add-TssDirectoryServiceGroup -TssSession $session -DomainId 4 -DomainIdentifier 'd87ac1d5-8f28-4910-b08a-5128af003626' -Name 'Secret User Group 1' | ||
``` | ||
|
||
Add a domain group named "Secret User Group 1" to be synchronized with under Directory Services ID 4 | ||
|
||
### EXAMPLE 2 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 4 -SearchText 'Secret*' | Add-TssDirectoryServiceGroup -TssSession $session -DomainId 4 | ||
Search-TssGroup -TssSession $session -DomainId 4 | ||
``` | ||
|
||
Add all Directory Groups found starign with "Secret" for Domain ID 4, then run a group search to show they are added | ||
|
||
## PARAMETERS | ||
|
||
### -TssSession | ||
TssSession object created by New-TssSession for authentication | ||
|
||
```yaml | ||
Type: Session | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -DomainId | ||
Domain ID | ||
```yaml | ||
Type: Int32 | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: 0 | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### -GroupName | ||
Group Name | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: Name | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### -DomainIdentifier | ||
Unique directory/domain identifier (e.g. | ||
AD GUID from Active Directory of that object) | ||
```yaml | ||
Type: Guid | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
## INPUTS | ||
## OUTPUTS | ||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
## RELATED LINKS | ||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Add-TssDirectoryServiceGroup](https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Add-TssDirectoryServiceGroup) | ||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Add-TssDirectoryServiceGroup.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Add-TssDirectoryServiceGroup.ps1) | ||
91 changes: 91 additions & 0 deletions
91
src/functions/directory-services/Add-TssDirectoryServiceGroup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
function Add-TssDirectoryServiceGroup { | ||
<# | ||
.SYNOPSIS | ||
Add or link a Directory Service Group to synchronize | ||
.DESCRIPTION | ||
Add or link a Directory Service Group to synchronize | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Add-TssDirectoryServiceGroup -TssSession $session -DomainId 4 -DomainIdentifier 'd87ac1d5-8f28-4910-b08a-5128af003626' -Name 'Secret User Group 1' | ||
Add a domain group named "Secret User Group 1" to be synchronized with under Directory Services ID 4 | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 4 -SearchText 'Secret*' | Add-TssDirectoryServiceGroup -TssSession $session -DomainId 4 | ||
Search-TssGroup -TssSession $session -DomainId 4 | ||
Add all Directory Groups found starign with "Secret" for Domain ID 4, then run a group search to show they are added | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Add-TssDirectoryServiceGroup | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Add-TssDirectoryServiceGroup.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param ( | ||
# TssSession object created by New-TssSession for authentication | ||
[Parameter(Mandatory, ValueFromPipeline, Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession, | ||
|
||
# Domain ID | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
[int] | ||
$DomainId, | ||
|
||
# Group Name | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
[Alias('Name')] | ||
[string] | ||
$GroupName, | ||
|
||
# Unique directory/domain identifier (e.g. AD GUID from Active Directory of that object) | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[guid] | ||
$DomainIdentifier | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeApiParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation | ||
$uri = $TssSession.ApiUrl, 'directory-services', 'domains', $DomainId, 'group' -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'POST' | ||
|
||
$addGroupBody = @{ data = @{} } | ||
switch ($tssParams.Keys) { | ||
'GroupName' {$addGroupBody.data.Add('name',$GroupName)} | ||
'DomainIdentifier' {$addGroupBody.data.Add('domainIdentifier',$DomainIdentifier)} | ||
} | ||
$invokeParams.Body = $addGroupBody | ConvertTo-Json -Depth 100 | ||
if ($PSCmdlet.ShouldProcess("description: $", "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)")) { | ||
Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)" | ||
try { | ||
$apiResponse = Invoke-TssApi @invokeParams | ||
$restResponse = . $ProcessResponse $apiResponse | ||
} catch { | ||
Write-Warning "Issue adding Group [$GroupName] to Domain [$DomainId]" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse) { | ||
Write-Verbose "Group [$GroupName] successfully added to Domain [$DomainId]" | ||
} | ||
} | ||
} else { | ||
Write-Warning 'No valid session found' | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/directory-services/Add-TssDirectoryServiceGroup.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'DomainId', 'GroupName', 'DomainIdentifier' | ||
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys | ||
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') | ||
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru | ||
} | ||
Context "Verify parameters" -Foreach @{currentParams = $currentParams } { | ||
It "$commandName should contain <_> parameter" -TestCases $knownParameters { | ||
$_ -in $currentParams | Should -Be $true | ||
} | ||
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { | ||
$_ | Should -BeNullOrEmpty | ||
} | ||
} | ||
} |