SecretManagement.PleasantPasswordServer.Extension/Private/Get-Children.ps1
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 |
function Get-Children { <# .SYNOPSIS Lists all Folders an their credentials recursive. .DESCRIPTION Lists all Folders an their credentials recursive. .PARAMETER Folder The current folder in the folderstructure .EXAMPLE PS C:\> Get-Children -Folder $f Lists all Folders an their credentials recursive. .INPUTS System.Object .OUTPUTS System.Management.Automation.PSCustomObject[] .NOTES Author: Constantin Hager Date: 2021-03-17 #> param ( [Parameter(Mandatory)] [System.Object] $Folder ) if ($null -ne $Folder) { $returnList = New-object 'System.Collections.Generic.List[System.Object]' if ($Folder.Name -eq "Root") { # Root Folder + Credentials $row = [PSCustomObject]@{ Folder = $Folder.Name FolderID = $Folder.Id Credentials = $Folder.Credentials } $returnlist.add($row) } foreach ($subfolder in $Folder.Children) { # Subfolders + Credentials $row = [PSCustomObject]@{ Folder = [string]::Concat($Folder.Name, '/', $subfolder.Name) FolderID = $subfolder.Id Credentials = $subfolder.Credentials } $returnlist.add($row) foreach ($f in $subfolder) { Get-Children -Folder $f } } } return $returnlist } |