PowerShell script exchange
Post Reply
matteu
Veeam Legend
Posts: 823
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Add new credentials

Post by matteu »

Hello,

I don't know how to do to add new credential to veeam with read-host.

I try this but it doesn't work :

Code: Select all

$Mailaccount = "xxxxx@gmail.com"
$MailPassword = Read-host "mail password" -AsSecureString
$MailDescription = "Mail account"

Add-VBRCredentials -User $Mailaccount -Password (ConvertFrom-SecureString -SecureString $Password) -Description $MailDescription -Type Windows 
What Am I missing ?

The account is created but it doesn't work. If I manually change the password on veeam credential manager, it works.
Egor Yakovlev
Product Manager
Posts: 2581
Liked: 708 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: Add new credentials

Post by Egor Yakovlev »

In Add-VBRCredentials you are converting secure string $Password, but your actual password secure string is in the variable $MailPassword?
In your case $Password is $null.
/Cheers!
matteu
Veeam Legend
Posts: 823
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Add new credentials

Post by matteu »

Oh sorry, I just fail on my copy / paste

Code: Select all

$Mailaccount = "proxmox31@gmail.com"
$MailPassword = Read-Host "Mail password :" -AsSecureString | convertfrom-securestring
$MailDescription = "Mail account"


Add-VBRCredentials -User $Mailaccount -Password (ConvertFrom-SecureString -SecureString $MailPassword) -Description $MailDescription -Type Windows 
It works if I do :

Code: Select all

$credentials = get-credentials
$credentials | Add-VBRCredentials -Description $MailDescription -Type Windows
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Add new credentials

Post by oleg.feoktistov »

Hi matteu,

It fails because you are converting it from a secure string twice. Once in the pipeline from Read-Host cmdlet and twice when passing the value to Add-VBRCredentials. Try this:

Code: Select all

$Mailaccount = "proxmox31@gmail.com"
$MailPassword = Read-Host "Mail password :" -AsSecureString | convertfrom-securestring
$MailDescription = "Mail account"

Add-VBRCredentials -User $Mailaccount -Password $MailPassword -Description $MailDescription -Type Windows 
Thanks,
Oleg
matteu
Veeam Legend
Posts: 823
Liked: 128 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Add new credentials

Post by matteu »

Hello,

I'im tired today...

I tried both and when I copy paste here I copy paste my both try...

This doesn't work :

Code: Select all

$Mailaccount = "proxmox31@gmail.com"
$MailPassword = Read-Host "Mail password :" -AsSecureString | convertfrom-securestring
$MailDescription = "Mail account"

Add-VBRCredentials -User $Mailaccount -Password $MailPassword -Description $MailDescription -Type Windows 
and this doesn't work

Code: Select all

$Mailaccount = "proxmox31@gmail.com"
$MailPassword = Read-Host "Mail password :" -AsSecureString 
$MailDescription = "Mail account"

Add-VBRCredentials -User $Mailaccount -Password (convertfrom-securestring $MailPassword) -Description $MailDescription -Type Windows 
Egor Yakovlev
Product Manager
Posts: 2581
Liked: 708 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: Add new credentials

Post by Egor Yakovlev »

I would go with Get-Credentials as they are in SecureString by defaut.

That code does the trick:

Code: Select all

$MailCredentials = Get-Credential -UserName YourEmail@gmail.com -Message 'Enter Password'
$MailDescription = "Mail account"
Add-VBRCredentials -User $MailCredentials.UserName -Password ([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($MailCredentials.Password))) -Description $MailDescription -Type Windows
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests