Powershell New-HubEntry - How to use it?

Powershell New-HubEntry - How to use it?

avatar

Hi,

I am trying to add credentials (username/password) after creating a new folder using Powershell. I am not getting which object to use for this purpose?
Like first create a folder, then create credentials under this folder.

Any pointers or idea on how can I achieve this?

All Comments (6)

avatar

Hi mytmpmaza

I'll check for some documentation/tips to help you use the command "New-HubEntry" in the best way possible.

Have a good day!

avatar

Hi Nathan,

Wondering if you got any update on this.

Hi mytmpmaza

I'll check for some documentation/tips to help you use the command "New-HubEntry" in the best way possible.

Have a good day!
avatar

Hi mytmpmaza,

Thanks for your patience. We are actually working on some bugs with this command. I'll keep you updated when the fix will be released.

Thank you for your comprehension.

avatar

Hi mytmpmaza,

Thanks again for your patience. The fix is finally released with this new version 2021.12.13.

To answer your question, the object for this purpose is the same for a folder and an entry: PSDecryptedEntry. The difference between them is the type you'll set in it. So in your case, you'll need to create 2 PSDecryptedEntry(1 of type folder and the other of type credential) and add them to your vault.

So below, here's an example on how to create/add a folder and create/add a credential in your newly created folder:

- Connect to your Hub with the PowerShell module
- Add a folder
- Set a variable with the "folder object". Ex:
$newFolder = [Devolutions.Hub.PowerShell.Entities.Hub.PSDecryptedEntry]@{ PsMetadata = [Devolutions.Hub.PowerShell.Entities.Hub.PSMetadata]@{ Name = "Folder"; ConnectionType = [Devolutions.Generated.Enums.ConnectionType]::Group }; Connection = [Devolutions.Generated.Models.Connection]@{ } }
- Add your folder to your vault. Ex:
$folderAdded = New-HubEntry -VaultId 9ac943e3-0e81-4257-8ff1-bac4490fdb37 -PSDecryptedEntry $newFolder
- Add a credential in your folder
- Set a variable with a "credential object" and use the newly added folder Id in "ParentId". Ex:
$newCredential = [Devolutions.Hub.PowerShell.Entities.Hub.PSDecryptedEntry]@{ PsMetadata = [Devolutions.Hub.PowerShell.Entities.Hub.PSMetadata]@{ Name = "Credential"; ParentId = $folderAdded.Connection.ID; ConnectionType = [Devolutions.Generated.Enums.ConnectionType]::Credential }; Connection = [Devolutions.Generated.Models.Connection]@{ Credentials = [Devolutions.Generated.Models.CredentialsConnection]@{ CredentialType = [Devolutions.Generated.Enums.CredentialResolverConnectionType]::Default; Password = "Password" } } }
- Finally, add your credential to your vault. Ex:
New-HubEntry -VaultId 9ac943e3-0e81-4257-8ff1-bac4490fdb37 -PSDecryptedEntry $newCredential

Hope this will help you. Don't hesitate if you have any other questions.

Have a good day and a happy new year!

avatar

Hi Nathan,

Thanks a lot for your reply.
I am unable to find documentation on somethings which I want to achieve.

  1. How to create credential under existing folder?
  2. How to retrieve password? I see we can pass EntryID for this. But I am unable to understand how to find EntryID which I can pass to cmdlet.


Also, I tried above mentioned steps by you which worked perfectly. It created new folder and new credential under it. But when I ran the same cmdlets again, it was able to create the folder with same name again. Ideally it should throw an error. Correct?

Thanks and looking forward to your assistance here.

avatar

Hi mytmpmaza

We've got documentation about PowerShell module with some examples with commands here. But before I answer your questions. PSDecryptedEntry(Wrapper for connection) is a complex object. So we don't have, for now, documentation/examples for all possible cases/types to create/edit an entry. So in my previous post, I gave you an example of how to create a folder, a credential, and also how to "add it under" a new folder. That been said:

  1. To add a new credential or entry to an existing folder, you just need to get its Id first, and after you can set it in the New-HubEntry flow ("ParentId" property).
    1. Example of where to set the folder id of your existing folder (Search for REPLACE_THIS_WITH_FOLDER_ID_HERE): $newCredential = [Devolutions.Hub.PowerShell.Entities.Hub.PSDecryptedEntry]@{ PsMetadata = [Devolutions.Hub.PowerShell.Entities.Hub.PSMetadata]@{ Name = "Credential"; ParentId = REPLACE_THIS_WITH_FOLDER_ID_HERE; ConnectionType = [Devolutions.Generated.Enums.ConnectionType]::Credential }; Connection = [Devolutions.Generated.Models.Connection]@{ Credentials = [Devolutions.Generated.Models.CredentialsConnection]@{ CredentialType = [Devolutions.Generated.Enums.CredentialResolverConnectionType]::Default; Password = "Password" } } }
  2. Like I said above, the entry object is complex and each type is not handled the same way. So the password can be set in different places depending on the type. For your particular case, the password is set under "Connection.Credentials.Password".
    1. Example to retrieve password of a credential entry:
      1. $credential = Get-HubEntry -VaultId 9ac943e3-0e81-4257-8ff1-bac4490fdb37 -EntryId303edc75-6bf5-451f-af80-4ec8e6893edd
      2. $credential.Connection.Credentials.Password
  3. In my previous post example, if the values are not changed, it's normal it will do the same. Also, it's not an error if the folder has a duplicated name.


I hope my examples and explanation are clear and will help you. If not or you have more questions, don't hesitate.