Skip to content

Commit

Permalink
Search-TssDirectoryServiceGroup - new command
Browse files Browse the repository at this point in the history
Return groups that can be added for sync in a Directory Service
  • Loading branch information
wsmelton committed Sep 13, 2021
1 parent 947e2b3 commit 48c0935
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
@@ -0,0 +1,98 @@
# Search-TssDirectoryServiceGroup

## SYNOPSIS
Search the Directory Service for the groups assigned

## SYNTAX

```
Search-TssDirectoryServiceGroup [-TssSession] <Session> -DomainId <Int32> [-SearchText <String>]
[<CommonParameters>]
```

## DESCRIPTION
Search the Directory Service for the groups assigned

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 2 -SearchText Admin*
```

Return list of Groups assigned to Domain ID 2 that start with Admin

### EXAMPLE 2
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 1
```

Return list of all Groups accessible in Domain ID 1

## 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: False
Accept wildcard characters: False
```

### -SearchText
Search Text, supports wildcard usage (e.g.
*Admin*, Admin*)

```yaml
Type: String
Parameter Sets: (All)
Aliases:

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

### Thycotic.PowerShell.DirectoryServices.Group
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Search-TssDirectoryServiceGroup](https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Search-TssDirectoryServiceGroup)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Search-TssDirectoryServiceGroup.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Search-TssDirectoryServiceGroup.ps1)

26 changes: 26 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -3245,5 +3245,31 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.DirectoryServices.Group -->
<View>
<Name>DirectoryServices.Group</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.DirectoryServices.Group</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DomainIdentifier</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
9 changes: 9 additions & 0 deletions src/Thycotic.SecretServer.Types.ps1xml
Expand Up @@ -295,4 +295,13 @@
</AliasProperty>
</Members>
</Type>
<Type>
<Name>Thycotic.PowerShell.DirectoryServices.Group</Name>
<Members>
<AliasProperty>
<Name>DomainIdentifier</Name>
<ReferencedMemberName>DsGuid</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>
</Types>
13 changes: 13 additions & 0 deletions src/Thycotic.SecretServer/classes/directory-services/Group.cs
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.DirectoryServices
{
public class Group
{
public string Name { get; set; }
public Guid DsGuid { get; set; }
}
}
@@ -0,0 +1,81 @@
function Search-TssDirectoryServiceGroup {
<#
.SYNOPSIS
Search the Directory Service for the groups assigned
.DESCRIPTION
Search the Directory Service for the groups assigned
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/directory-services/Search-TssDirectoryServiceGroup
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/directory-services/Search-TssDirectoryServiceGroup.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 2 -SearchText Admin*
Return list of Groups assigned to Domain ID 2 that start with Admin
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssDirectoryServiceGroup -TssSession $session -DomainId 1
Return list of all Groups accessible in Domain ID 1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.DirectoryServices.Group')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Domain ID
[Parameter(Mandatory)]
[int]
$DomainId,

# Search Text, supports wildcard usage (e.g. *Admin*, Admin*)
[Parameter()]
[string]
$SearchText
)
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, 'groups', 'search-directory' -join '/'
$uri = $uri, "searchText=$SearchText" -join '?'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue on search request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.groups.Count -le 0 -and $restResponse.groups.Length -eq 0) {
Write-Warning "No Directory Service Group found"
}
if ($restResponse.groups) {
[Thycotic.PowerShell.DirectoryServices.Group[]]$restResponse.groups
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/directory-services/Search-TssDirectoryServiceGroup.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'DomainId', 'SearchText'
[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
}
}
Context "Command specific details" {
It "$commandName should set OutputType to Thycotic.PowerShell.DirectoryServices.Group" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.DirectoryServices.Group'
}
}
}

0 comments on commit 48c0935

Please sign in to comment.