powershell script and user rights

PowerShell script exchange

powershell script and user rights

Veeam Logoby Andy611 » Tue Apr 09, 2013 10:05 am

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.
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby Vitaliy S. » Tue Apr 09, 2013 10:49 am

Have you added the target repository to the backup console or you're trying to use a UNC path in your script?
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: powershell script and user rights

Veeam Logoby v.Eremin » Tue Apr 09, 2013 10:53 am

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: powershell script and user rights

Veeam Logoby Andy611 » Tue Apr 09, 2013 11:03 am

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.
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby v.Eremin » Tue Apr 09, 2013 11:04 am

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: powershell script and user rights

Veeam Logoby Andy611 » Tue Apr 09, 2013 11:58 am

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

Re: powershell script and user rights

Veeam Logoby Andy611 » Thu Apr 11, 2013 5:37 am

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
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby v.Eremin » Thu Apr 11, 2013 1:42 pm

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: powershell script and user rights

Veeam Logoby Andy611 » Fri Apr 12, 2013 8:44 am

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.
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby v.Eremin » Fri Apr 12, 2013 10:33 am

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: powershell script and user rights

Veeam Logoby Martin9700 » Fri Apr 12, 2013 11:49 am

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
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: powershell script and user rights

Veeam Logoby Andy611 » Fri Apr 12, 2013 1:19 pm

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 :-)
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby v.Eremin » Fri Apr 12, 2013 1:25 pm

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: powershell script and user rights

Veeam Logoby Andy611 » Mon Apr 15, 2013 9:39 am

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.
Andy611
Influencer
 
Posts: 14
Liked: never
Joined: Tue Apr 09, 2013 9:46 am
Full Name: Andrej Hlubocky

Re: powershell script and user rights

Veeam Logoby v.Eremin » Mon Apr 15, 2013 11:59 am 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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests