PowerShell script exchange
Post Reply
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

powershell script and user rights

Post by Andy611 »

Hi

I have powershell script for VeeamZip backup:

Code: Select all

Add-PSSnapin VeeamPSSnapIn
$myRepository = "path to share folder"
$VM = Get-VBRServer -name "name of vcenter server" | Find-VBRViEntity -name "name of VM to backup" 
Start-VBRZip -folder $myRepository -Entity $VM 
exit
Shared folder is secured with domain user, I have problem with access denied error, but I dont know where to instert username and password in script. Server running VeeamBackup is on same domain.

Thank you very much

A.
Vitaliy S.
VP, Product Management
Posts: 27055
Liked: 2710 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell script and user rights

Post by Vitaliy S. »

Have you added the target repository to the backup console or you're trying to use a UNC path in your script?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

You should first map your Shared folder to PowerShell session by the means of New-PSDrive cmdlet:

Code: Select all

Add-PSSnapin VeeamPSSnapIn
New-PSDrive –Name myShare -PSProvider FileSystem -Root "Name of your share" -Credential domain\user
$Folder = “myShare:\”
$VM = Get-VBRServer -name "name of vcenter server" | Find-VBRViEntity -name "name of VM to backup" 
Start-VBRZip -folder $Folder  -Entity $VM
Note: Under -credential parameter you should specify a user account that has permission to perform this action. Type a user name, such as "Domain\User". When you do it, you will be prompted for a password.

Hope this helps.
Thanks.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Backup repository is stored in Backup Infrastructure\Backup Ropositories with username and password, over GUI everything is ok (Type CIFS). In script ther is network path of repository. I dont know how to set password for this in script.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

If you’ve already added your shared folder as backup repository to VB&R console, then you can utilize a modified version of your original script:

Code: Select all

Add-PSSnapin VeeamPSSnapIn
$myRepository = Get-VBRBackupRepository -name "Name of your repository"
$VM = Get-VBRServer -name "name of vcenter server" | Find-VBRViEntity -name "name of VM to backup" 
Start-VBRZip -BackupRepository $myRepository -Entity $VM 
Anyway, either of proposed scripts are likely to meet your expectations.

Hope this helps.
Thanks.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Very good, this works :-) Thank you very much for your help.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Hi again :-)

Its possible to set backup folder located in repository ? I mean I have repository but in this repositry is more folders that I want to use. For example there is more jobs and I want sort this backup files in folders. Everything with VeeamZip.

Thank you
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

For doing it you have to use the first version of the script.

Let’s say, that your share is accessible under “192.168.0.1\share$” UNC path, and it has subfolder “Backup Job 1” to which you’re willing to veeamzip given VM, then, the aforesaid script should look like this:

Code: Select all

Add-PSSnapin VeeamPSSnapIn
New-PSDrive –Name myShare -PSProvider FileSystem -Root "192.168.0.1\share$" -Credential domain\user
$Folder = “myShare:\Backup Job 1”
$VM = Get-VBRServer -name "name of vcenter server" | Find-VBRViEntity -name "name of VM to backup" 
Start-VBRZip -folder $Folder -Entity $VM
Hope this helps.
Thanks.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Hi

1. Error: The provider does not support the use of credentials. Perform the operation again without spec. credentials.

2. I need this without asking for password, this will be scheduled tasks.

Thx a lot for your help.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

First of all, it seems that you’re using an obsolete version of Powershell, where passing credentials to New-PSdrive wasn’t possible. Thus, please double check that you’re on the latest 3.0 version.

So, something like this should work fine:

Code: Select all

asnp VeeamPSSnapin
$username = "Your user’s name"
$PlainPassword = "Your user’s password"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force 
$Path = "Path to your share" # For instance, \\192.168.0.1
$cred = new-object System.Management.Automation.PSCredential -argumentlist $username, $SecurePassword
New-PSDrive –Name myShare -PSProvider FileSystem -Root $Path -Credential $Cred
$Folder = “myShare:\subfolder” # For instance, myShare:\Backup Job 1
$VM = Get-VBRServer -name "name of vcenter server" | Find-VBRViEntity -name "name of VM to backup" 
Start-VBRZip -folder $Folder -Entity $VM
Hope this helps.
Thanks.
Martin9700
Influencer
Posts: 17
Liked: 3 times
Joined: Nov 10, 2010 2:18 pm
Full Name: Martin Pugh
Location: Massachusetts
Contact:

Re: powershell script and user rights

Post by Martin9700 »

If you don't want to store the password in plain text I have a function you can put into your script to save it in an encrypted file.

http://thesurlyadmin.com/2012/10/03/sec ... -function/
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Script:

Code: Select all

asnp VeeamPSSnapin
$username = "domain\user"
$PlainPassword = "password"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force 
$Path = "\\1.2.3.4\backup" # For instance, \\1.2.3.4\backup
$cred = new-object System.Management.Automation.PSCredential -argumentlist $username, $SecurePassword
New-PSDrive –Name myShare -PSProvider FileSystem -Root $Path -Credential $Cred
$Folder = “myShare:\blspitest0001” # For instance, myShare\:blspitest0001
$VM = Get-VBRServer -name "vcenterserver" | Find-VBRViEntity -name "nameofvm" 
Start-VBRZip -folder $Folder -Entity $VM
shared folder is \\1.2.3.4\backup\blspitest0001

Error:

Backup repository is not accessible. [BLSPIBACKUP01] Failed to create directory 'myShare:\blspitest0001' The filename, directory name, or volume label syntax is incorrect. Cannot create folder. Folder path: [myShare:\blspitest0001]. --tr:FC: Failed to create directory. Directory path: [myShare:\blspitest0001]. --tr:Failed to call DoRpc. CmdName: [FcCreateDir] inParam: [<InputArguments><DirName value="myShare:\blspitest0001" /></InputArguments>].

Thank you and have a nice day for all :-)
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

You need to be sure that necessary read/write permissions are granted to the user account being used.

In order to check it, connect to the corresponding share manually, using specified user credentials, try to create a folder on it and see whether you will be allowed to do it.

Thanks.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

Hi

I can manualy write into this folder same as delete so I think there is problem in script, also tried with local user without domain.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin » 1 person likes this post

In fact, I’d tested abovementioned script prior to posting and everything seemed to work properly. Furthermore, I got the same error regarding backup repository being inaccessible when necessary permissions were not granted to corresponding user.

So, it’s hard to say why it doesn’t work in your case.

As a potential workaround you can try to use the following variant based on utilization of “net use”:

Code: Select all

Asnp VeeamPSSnapin
$password = "Your user’s password"
net use w: “Path to your share” /user:domain\user $password
$VM = Get-VBRServer -name "Name of your VC" | Find-VBRViEntity -name "Name of your VM"
$Folder = "w:\subfolder"
Start-VBRZip -folder $Folder -Entity $VM
net use w: /d


Hope this helps.
Thanks.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

Additionally, can you grant necessary permissions to the account under which Veeam Services are run and see whether the provided scripts work?

Thanks.
Andy611
Influencer
Posts: 14
Liked: never
Joined: Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky
Contact:

Re: powershell script and user rights

Post by Andy611 »

This is for sure problem with rights, but I dont know why, becouse if I manualy copy to share folder everything is ok, service is running under the same admin as its setup for shared folder. Another solution is to setup more local repositories for example D:\backup\vmserver01, D:\backup\vmserver02 and run backup with working script without shared folder.
nshurupova
Lurker
Posts: 1
Liked: never
Joined: Sep 09, 2016 3:20 pm
Full Name: Nataliya
Contact:

Re: powershell script and user rights

Post by nshurupova »

No matter what I tried, I couldn't get the script to write to the share. My workaround is - in the loop for each VM

1) write backup locally
2) move to the share
3) remove backup from local destination.

Works great this way under the scheduled task - no issues with permissions.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

Some of the solutions such as granting sufficient permissions to computer account, etc. have been discussed in the adjacent thread; might be worth reviewing. Thanks.
sbp
Lurker
Posts: 1
Liked: never
Joined: Dec 21, 2016 8:56 am
Full Name: Søren Bo Petersen
Contact:

Re: powershell script and user rights

Post by sbp »

I've tried everything in this thread and a lot more - without succes. Trying to save backup to a share.

Even creating a network share on the same server I'm running the backup from with full rights - nothing works.
Only backing up to c:\ works - that is really strange.

Of course the solution nshurupova suggests will work, but it is not very elegant, and will take up a lot of space.

I using Windows 2012 R2 servers and Veeam Free 9.5. From the console everything works fine - only powershell is the problem.

Do you have any new suggestions, about how to solve this?

The script I'm currently using.
Add-PSSnapin VeeamPSSnapIn

$username = "domain\username"
$PlainPassword = "password"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
$Path = "\\hyperv04\veeamtest"
$cred = new-object System.Management.Automation.PSCredential -argumentlist $username, $SecurePassword
New-PSDrive –Name B -PSProvider FileSystem -Root $Path -Credential $Cred
$Folder = “B:\”

$VM = Find-VBRHvEntity -Name VM -Server localhost
Start-VBRZip -folder $Folder -Entity $VM
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: powershell script and user rights

Post by veremin »

Honestly, I'm not aware of any other solutions besides providing sufficient privileges for both backup service and computer accounts. Thanks.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests