-
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.
Move-TssFolder - new command to use for moving child folder
- Loading branch information
Showing
3 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
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,158 @@ | ||
# Move-TssFolder | ||
|
||
## SYNOPSIS | ||
Move a folder in Secret Server | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Move-TssFolder [-TssSession] <Session> [-Id] <Int32[]> [-ParentFolderId] <Int32> [-DisableInheritPermissions] | ||
[-DisableInheritSecretPolicy] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Move a folder in Secret Server | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Move-TssFolder -TssSession $session -Id 45 -ParentFolderId 98 | ||
``` | ||
|
||
Moves folder 45 to parent folder 98, defaulting permissions and Secret Policy to inheritting from Folder 98 | ||
|
||
### EXAMPLE 2 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Move-TssFolder -TssSession $session -Id 1092 -ParentFolderId 5409 -DisableInheritPermission | ||
``` | ||
|
||
Moves folder 1092 to parent folder 5409, disabling inherit permissions and enabling inherit Secret Policy from folder 5409 | ||
|
||
## 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 | ||
``` | ||
### -Id | ||
Folder ID that will be moved | ||
```yaml | ||
Type: Int32[] | ||
Parameter Sets: (All) | ||
Aliases: FolderId | ||
|
||
Required: True | ||
Position: 2 | ||
Default value: None | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
### -ParentFolderId | ||
Parent Folder ID to move the folder to | ||
```yaml | ||
Type: Int32 | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 3 | ||
Default value: 0 | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -DisableInheritPermissions | ||
Do not inherit permissions from parent folder | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: False | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -DisableInheritSecretPolicy | ||
Do not inherit Secret Policy from parent folder | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: False | ||
Accept pipeline input: False | ||
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 | ||
### Thycotic.PowerShell.Folders.Folder | ||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
## RELATED LINKS | ||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/folders/Move-TssFolder](https://thycotic-ps.github.io/thycotic.secretserver/commands/folders/Move-TssFolder) | ||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folders/Move-TssFolder.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folders/Move-TssFolder.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,100 @@ | ||
function Move-TssFolder { | ||
<# | ||
.SYNOPSIS | ||
Move a folder in Secret Server | ||
.DESCRIPTION | ||
Move a folder in Secret Server | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Move-TssFolder -TssSession $session -Id 45 -ParentFolderId 98 | ||
Moves folder 45 to parent folder 98, defaulting permissions and Secret Policy to inheritting from Folder 98 | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Move-TssFolder -TssSession $session -Id 1092 -ParentFolderId 5409 -DisableInheritPermission | ||
Moves folder 1092 to parent folder 5409, disabling inherit permissions and enabling inherit Secret Policy from folder 5409 | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/folders/Move-TssFolder | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/folders/Move-TssFolder.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "Update-TssFolder call requires the attribute", Scope="Function", Target="*")] | ||
[CmdletBinding(SupportsShouldProcess)] | ||
[OutputType('Thycotic.PowerShell.Folders.Folder')] | ||
param ( | ||
# TssSession object created by New-TssSession for authentication | ||
[Parameter(Mandatory, ValueFromPipeline, Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession, | ||
|
||
# Folder ID that will be moved | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 1)] | ||
[Alias('FolderId')] | ||
[int[]] | ||
$Id, | ||
|
||
# Parent Folder ID to move the folder to | ||
[Parameter(Mandatory, Position = 2)] | ||
[int] | ||
$ParentFolderId, | ||
|
||
# Do not inherit permissions from parent folder | ||
[switch] | ||
$DisableInheritPermissions, | ||
|
||
# Do not inherit Secret Policy from parent folder | ||
[switch] | ||
$DisableInheritSecretPolicy | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
} | ||
process { | ||
Get-TssInvocation $PSCmdlet.MyInvocation | ||
foreach ($folder in $Id) { | ||
$getFolderParams = @{ | ||
TssSession = $TssSession | ||
Id = $folder | ||
} | ||
$cFolder = Get-TssFolder @getFolderParams -ErrorAction Stop | ||
if ($cFolder) { | ||
$parentFolderParams = @{ | ||
TssSession = $TssSession | ||
Id = $ParentFolderId | ||
} | ||
$parentFolderState = Get-TssFolder @parentFolderParams -ErrorAction Stop | ||
|
||
if ($parentFolderState) { | ||
$cFolder.ParentFolderId = $ParentFolderId | ||
if ($tssParams.ContainsKey('DisableInheritPermission')) { | ||
$cFolder.InheritPermissions = $false | ||
} | ||
if ($tssParams.ContainsKey('DisableInheritSecretPolicy')) { | ||
$cFolder.InheritSecretPolicy = $false | ||
} | ||
$updateFolderParams = @{ | ||
TssSession = $TssSession | ||
Folder = $cFolder | ||
} | ||
try { | ||
Update-TssFolder @updateFolderParams -ErrorAction Stop | ||
} catch { | ||
Write-Warning "Issue updating folder [$folder]" | ||
Write-Error $_ | ||
} | ||
} else { | ||
Write-Warning "Parent folder [$ParentFolderId] could not be found" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,24 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'Id', 'ParentFolderId', 'DisableInheritPermissions', 'DisableInheritSecretPolicy' | ||
[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.Folders.Folder" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Folders.Folder' | ||
} | ||
} | ||
} |