thycotic-ps / thycotic.secretserver

PowerShell module for automating with Thycotic Secret Server REST API
https://thycotic-ps.github.io/thycotic.secretserver
MIT License
68 stars 22 forks source link

Update module to work with 11.2 release #271

Closed jagger closed 2 years ago

jagger commented 2 years ago

Verified issue does not already exist?

Yes

What error did you receive

Search-TssSecret -TssSession $TssSession -verbose

VERBOSE: Command invocation: Search-TssSecret -TssSession:TssSessionObject -Verbose:True VERBOSE: Performing the operation GET https://labss02.jaggerlab.local/SecretServer/api/v1/secrets?sortBy[0].direction=asc&sortBy[0].name=Name&take=2147483647&filter.includeRestricted=true InvalidArgument: C:\Program Files\WindowsPowerShell\Modules\Thycotic.SecretServer\0.60.6\functions\secrets\Search-TssSecret.ps1:274:17 Line | 274 | … [Thycotic.PowerShell.Secrets.Summary[]]$restResponse.reco … | ~~~~~~~~~~~~~ | Cannot convert value "@{id=65; name=10.10.10.239; secretTemplateId=9; secretTemplateName=Web Password; folderId=46; siteId=1; active=True; checkedOut=False; isRestricted=False; | isOutOfSync=False; outOfSyncReason=; lastHeartBeatStatus=Disabled; lastPasswordChangeAttempt=1/1/0001 12:00:00 AM; responseCodes=; lastAccessed=4/18/2022 4:39:49 AM; extendedFields=; | checkOutEnabled=False; autoChangeEnabled=False; doubleLockEnabled=False; requiresApproval=False; requiresComment=False; inheritsPermissions=True; hidePassword=False; | createDate=9/1/2021 3:37:49 PM; daysUntilExpiration=; hasLauncher=True}" to type "Thycotic.PowerShell.Secrets.Summary". Error: "Cannot convert the "@{id=65; name=10.10.10.239; | secretTemplateId=9; secretTemplateName=Web Password; folderId=46; siteId=1; active=True; checkedOut=False; isRestricted=False; isOutOfSync=False; outOfSyncReason=; | lastHeartBeatStatus=Disabled; lastPasswordChangeAttempt=1/1/0001 12:00:00 AM; responseCodes=; lastAccessed=4/18/2022 4:39:49 AM; extendedFields=; checkOutEnabled=False; | autoChangeEnabled=False; doubleLockEnabled=False; requiresApproval=False; requiresComment=False; inheritsPermissions=True; hidePassword=False; createDate=9/1/2021 3:37:49 PM; | daysUntilExpiration=; hasLauncher=True}" value of type "System.Management.Automation.PSCustomObject" to type "Thycotic.PowerShell.Secrets.Summary"."

Please run the command using -Verbose

Search-TssSecret -TssSession $TssSession -verbose

VERBOSE: Command invocation: Search-TssSecret -TssSession:TssSessionObject -Verbose:True VERBOSE: Performing the operation GET https://labss02.jaggerlab.local/SecretServer/api/v1/secrets?sortBy[0].direction=asc&sortBy[0].name=Name&take=2147483647&filter.includeRestricted=true InvalidArgument: C:\Program Files\WindowsPowerShell\Modules\Thycotic.SecretServer\0.60.6\functions\secrets\Search-TssSecret.ps1:274:17 Line | 274 | … [Thycotic.PowerShell.Secrets.Summary[]]$restResponse.reco … | ~~~~~~~~~~~~~ | Cannot convert value "@{id=65; name=10.10.10.239; secretTemplateId=9; secretTemplateName=Web Password; folderId=46; siteId=1; active=True; checkedOut=False; isRestricted=False; | isOutOfSync=False; outOfSyncReason=; lastHeartBeatStatus=Disabled; lastPasswordChangeAttempt=1/1/0001 12:00:00 AM; responseCodes=; lastAccessed=4/18/2022 4:39:49 AM; extendedFields=; | checkOutEnabled=False; autoChangeEnabled=False; doubleLockEnabled=False; requiresApproval=False; requiresComment=False; inheritsPermissions=True; hidePassword=False; | createDate=9/1/2021 3:37:49 PM; daysUntilExpiration=; hasLauncher=True}" to type "Thycotic.PowerShell.Secrets.Summary". Error: "Cannot convert the "@{id=65; name=10.10.10.239; | secretTemplateId=9; secretTemplateName=Web Password; folderId=46; siteId=1; active=True; checkedOut=False; isRestricted=False; isOutOfSync=False; outOfSyncReason=; | lastHeartBeatStatus=Disabled; lastPasswordChangeAttempt=1/1/0001 12:00:00 AM; responseCodes=; lastAccessed=4/18/2022 4:39:49 AM; extendedFields=; checkOutEnabled=False; | autoChangeEnabled=False; doubleLockEnabled=False; requiresApproval=False; requiresComment=False; inheritsPermissions=True; hidePassword=False; createDate=9/1/2021 3:37:49 PM; | daysUntilExpiration=; hasLauncher=True}" value of type "System.Management.Automation.PSCustomObject" to type "Thycotic.PowerShell.Secrets.Summary"."

Provide a test case or steps to reproduce

search-tsssecret

Expected behavior

A list of secrets should be returned

What Edition of Secret Server?

Platinum

What version of Secret Server

EA release

What PowerShell host was used when producing this error

Windows PowerShell (powershell)

PowerShell Host Version

Name Value ---- ----- PSVersion 7.2.2 PSEdition Core GitCommitId 7.2.2 OS Microsoft Windows 10.0.19043 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

casorke commented 2 years ago

This can be resolved at least temporarily by changing both sections that output the $restResponse to parse the API properties and copy them over to a Thycotic.PowerShell.Secrets.Secret class object. One field, 'jumpboxRouteID', is not in the Thycotic.PowerShell.Secrets.Secret class, so it will throw one error in copying the date over.

Here's how I handled it:


if ($restResponse) {
    $TssSecret = [Thycotic.PowerShell.Secrets.Secret]::New()
    ($restResponse | Get-Member -MemberType NoteProperty).Name | Foreach-Object {
        Try {
            $TssSecret.$_ = $restResponse.$_
        } catch [System.Management.Automation.RuntimeException] {
            Continue
        } catch {
            Write-Warning "Issue parsing secret [$secret]"
            $err = $_
            . $ErrorHandling $err
        }
    }
    [Thycotic.PowerShell.Secrets.Secret]$TssSecret
}