PowerShell script exchange
Post Reply
mschouren
Service Provider
Posts: 4
Liked: never
Joined: Jul 24, 2013 10:56 am
Full Name: Maarten Schouren
Location: Netherlands
Contact:

Add-VBRCredentials: Credentials already exist

Post by mschouren »

With the move to Veeam B&R V7 I am updating the PowerShell script I use to make use of the Credential system. Running into a problem however. I'd like to stick with credentials per job. These credentials may or may not be unique with regards to both username and password. When adding the credential through PowerShell I receive the following error: "Credentials with the same username and password already exist.".

Code: Select all

PS C:\Scripts\VeeamJobProvision> Add-VBRCredentials -User a -Password a
IsLocalProtect    : True
Name              : a
CurrentUser       : False
UserName          : a
UserNameOnly      : a
DomainName        : .
EncryptedPassword : AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAArEFXDblbk+eTuYB/KQR7gQAAAACAAAAAAADZgAAwAAA
                    ABAAAAB4o3u4urhMvW8eGYhJD67pAAAAAASAAACgAAAAEAAAAOAX+/+Jv0e1w27hvnVwx10IAAAA
                    HlK+zpjA3+wUAAAAfH/brMUWNZSjC1Y2B1ogj8Rs0MU=
Description       : Created by Powershell at 10/14/2013 4:37:27 PM.
IsEmpty           : False

Code: Select all

PS C:\Scripts\VeeamJobProvision> Add-VBRCredentials -User a -Password a
Add-VBRCredentials : Credentials with the same username and password already exist.
At line:1 char:1
+ Add-VBRCredentials -User a -Password a
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-VBRCredentials], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Veeam.Backup.PowerShell.Command.AddVBRCr 
   edentials
If I manually do the same thing via the GUI it all works fine. So basically: how can I add duplicate credentials in an automated fashion?
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Add-VBRCredentials: Credentials already exist

Post by veremin »

Quick tests suggest that it’s not possible to create identical credentials second time. However, what is the reason to create several identical credentials, when you can re-use already created ones? Thanks.
mschouren
Service Provider
Posts: 4
Liked: never
Joined: Jul 24, 2013 10:56 am
Full Name: Maarten Schouren
Location: Netherlands
Contact:

Re: Add-VBRCredentials: Credentials already exist

Post by mschouren »

A few reasons:
- This way I do not have to keep track of the relation between existing credentials and existing jobs. These credentials may or may not match other credentials. So in short there is a 1:1 relation between a job and a credential, like it was in V6, where I could set a user/pass on the Job or JobObject without having to bother with overlapping credential entries.
- Another thing is that I have no way to check check if an existing credential is the same as the one that I am trying to add. If try adding it, it just tells me that there is another one with the same user/pass. It would be really helpful if it returned some reference to the actual credential entry it doubles with (so I can opt to use that one instead).

Furthermore, is there any technical reason to actively block it through PowerShell, as it is currently, but allow it via the GUI?
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Add-VBRCredentials: Credentials already exist

Post by veremin »

Another thing is that I have no way to check check if an existing credential is the same as the one that I am trying to add. If try adding it, it just tells me that there is another one with the same user/pass. It would be really helpful if it returned some reference to the actual credential entry it doubles with (so I can opt to use that one instead).
Actually, you can check whether or not the credentials exist:

Code: Select all

asnp veeampssnapin
$User = “User”
$Password = “Password”
$Credentials = Add-VBRCredentials -User $User -Password $Password
If ($Credentials -ne $Null)
{
Write-Output "Credentials don't exist"
}
Furthermore, is there any technical reason to actively block it through PowerShell, as it is currently, but allow it via the GUI?
I believe this is just the way it currently works. And this way doesn’t appear illogical, since there is a little sense to multiply identical credentials.

Thanks.
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Add-VBRCredentials: Credentials already exist

Post by tsightler » 2 people like this post

I agree that this is a somewhat frustrating limitation as there can be several cases where a credential might be the same now, but might change in the future (for example two servers that currently have the same local admin password, but one changes in the future). Having to detect duplicates and then split credentials in the future when they are no longer duplicates complicates what should be simple, especially since the GUI actually allows this.

So, in the interim, I've come up with the following workaround that creates the credential with a random password and then sets the password using the SetPassword. This will allow you to create duplicate credentials all you want. You will likely need to use the description field to uniquely identify the credential you want (in the case perhaps using the job name in the description to match the correct credential) so something like this:

Code: Select all

$user = "UserA"
$pass = "PassA"
$desc = "CredA"
$cred = Add-VBRCredentials -User $user -Password (Get-Random) -Description $desc
$cred.SetPassword("$pass")
Now, to find that specific credential you can use:

Code: Select all

$cred = Get-VBRCredentials -Name $user | ?{$_.Description -eq $desc}
So as long use the username and description are unique you can easily select any specific credential even if the username and password is a duplicate.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests