Keeper-Security / keeper-sdk-dotnet

.Net and PowerShell version of Keeper Commander, a CLI and SDK interface for the Keeper Security platform.
https://docs.keeper.io/secrets-manager/commander-cli/using-commander/dotnet-powershell
MIT License
29 stars 20 forks source link

[Feature] Add support to PowerShell Cmdlets to Download FileRecords #115

Closed as-slonneman closed 5 months ago

as-slonneman commented 5 months ago

The PowerShell Module is currently unable to download FIleRecords. This would be useful in scenarios where a user may use certificate based authentication and they store the certificate as an attachment to a Login Record. Implementation of this is as simple as a FileCommands.ps1 file with the code that would return a MemoryStream:

`function Get-FileRecord { param( [string] $recordUid )

[KeeperSecurity.Vault.VaultOnline]$vault = getVault if ($recordUid) { [KeeperSecurity.Vault.FileRecord] $record = $null if ($vault.TryGetKeeperRecord($recordUid, [ref]$record)) { $fileStream = [System.IO.MemoryStream]::new() $vault.DownloadFile($record, $fileStream).GetAwaiter().GetResults() | Out-Null return $fileStream }} }`

sk-keeper commented 5 months ago

PowerCommander v0.9.8 adds Copy-KeeperFileAttachment cmdlet.

Downloads filename.txt file attachment from all records into 'OutFolder' folder

Copy-KeeperFileAttachment -Folder \ -Recursive -Name 'filename.txt' 'OutFolder'

Downloads all file attachments for a record

Copy-KeeperFileAttachment -Record <RECORD_UID>
as-slonneman commented 5 months ago

Is it possible to also add the ability to return the file as a MemoryStream so that users of the function don't have to write a file to the system? This would allow users to directly use the file in memory so they don't have to write the file to the system then read it back in a again?

sk-keeper commented 5 months ago

Copy-KeeperFileAttachmentToStream cmdlet is added.

$stream = New-Object System.IO.MemoryStream
Copy-KeeperFileAttachmentToStream -Record <RECORD_UID> -AttachmentName <OPTIONAL_ATTACHMENT_NAME> $stream
$stream.Seek(0, 0)