PowerShell script exchange
Post Reply
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Thx for trying and i am happy that it worked for you...so it can be only my environment...will try your changes if there are any...
Thx...and i will check the powershell version as well...
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I mentioned PS version deliberately, because up to that moment I've seen various strange issues related to usage of PowerShell 2.0, such as missing properties, unavailable methods, obscure errors, etc.

Thus, I always recommend using PowerShell 4.0 at least.

Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Hmmm..just checked...i have version 4.0
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Wow...a lot of changes...very interesting
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I just commented everything not applying either to my infrastructure (usage of PowerCLI) or to my test (sending email), but it shouldn't have affected the result property value anyhow. Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Something must be different to your system setup...
Your example does not stop baking up one and the same machine over and over again...
So very strange...and of course no result variable value
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

As I've illustrated, everything works in my environment, so, it's hard to tell what might be wrong with the script.

The simplest test would be to assign result of Start-VBRZIP commandlet to a variable and check whether it contains non nullable object. Something like:

Code: Select all

$bk_result = Start-VBRZip -Entity (Find-VBRViEntity -Name "Name of your VM" -Server (Get-VBRServer -Name "Name of your host/VC")) -Folder "Name of destination folder" 
$bk_result.result
Thanks.
Stef_TS
Lurker
Posts: 1
Liked: never
Joined: Aug 25, 2016 2:52 pm
Full Name: Stefano
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Stef_TS »

I've been trying to implement the script to run scheduled backups of my Hyper-V VM with the Free Edition.

When I try to run it in PS, the backup process diaglog opens for a about 20 seconds:

Image

Then it just closes without doing anything. No error code, nothing.

What could that be?

Stef
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

Hi All,
I'm trying to get this to work, but cant: https://www.veeam.com/blog/veeam-backup ... shell.html

I keep getting this, can anyone help?

Code: Select all

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS H:\> C:\VeeamZIP.ps1
Get-VBRServer : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is denied.
At C:\VeeamZIP.ps1:71 char:11
+ $Server = Get-VBRServer -name $HostName
+           ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Find-VBRHvEntity : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is
denied.
At C:\VeeamZIP.ps1:76 char:9
+   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Start-VBRZip : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is denied.
At C:\VeeamZIP.ps1:86 char:19
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+                   ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

You cannot call a method on a null-valued expression.
At C:\VeeamZIP.ps1:91 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

New-Object : Exception calling ".ctor" with "2" argument(s): "The parameter 'from' cannot be an empty string.
Parameter name: from"
At C:\VeeamZIP.ps1:108 char:12
+ $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'Subject' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:109 char:1
+ $Message.Subject = $EmailSubject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'IsBodyHTML' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:110 char:1
+ $Message.IsBodyHTML = $True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'Body' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:111 char:1
+ $message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\VeeamZIP.ps1:113 char:1
+ $SMTP.Send($Message)
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

Jeff.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

What could that be?
Have you tried to check the backup console? May be something is reported there?
I keep getting this, can anyone help?
Run a script under Administrator account.

Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

I tried running it from an admin account, still no good
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Are you positive you've run the script as Administrator (right-click - Run As Administrator)? Also, you can try to change the permissions of the following registry key:

Code: Select all

 \\HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication\ -> Users full control
Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Check if your setup does a regular backup from the free version GUI...looks to me, that there is either a backup target rights issue or some other part in the route not right...
So if the backup of you vm works with Veeam free gui and you are using the same targets and vm's...let us know
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

The registry key has the administrators group on the domain with full control, and I'm running this as me and I'm a domain admin.
I can run the backup from the GUI and it does write the file to the target with no problem.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

I changed the registry key to add domain admin with full control and it seemed to work, but now I get this:

Code: Select all

New-Object : Exception calling ".ctor" with "2" argument(s): "The parameter 'from' cannot be an empty string.
Parameter name: from"
At C:\VeeamZIP.ps1:108 char:12
+ $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'Subject' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:109 char:1
+ $Message.Subject = $EmailSubject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'IsBodyHTML' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:110 char:1
+ $Message.IsBodyHTML = $True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'Body' cannot be found on this object. Verify that the property exists and can be set.
At C:\VeeamZIP.ps1:111 char:1
+ $message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\VeeamZIP.ps1:113 char:1
+ $SMTP.Send($Message)
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException


JB
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

You appear to have provided empty strings as email notification settings (from, to). Either specify proper values or disable notification. Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

I edited all the email fields, but the email provider we use (MS Office365) will mostly want authentication and it doesnt have any fields for that.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Have you tried the approach recommended here? Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

Hello All, I think adding permissions to that registry key solved my problem. Thank you!!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I understood that by tweaking the said regkey you were able to make script finally work, but I was actually answering your last question (how authenticate against O365 mailbox) and giving the links to how it can be done. Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

I couldn't get the email portion working, not sure if anyone else out there got it working, but I would like to know how.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Have you checked the link that I provided previously, it describes exactly that? Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

I didn't see that link, can you please post it again
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

email still doesnt work
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Could you elaborate on that? What exactly error did you get? Have you adapted the example provided in the given article ("Sending Email from PowerShell via Office 365")? May be a snippet of your current script would be helpful. Thanks.
LGPC
Influencer
Posts: 13
Liked: never
Joined: Aug 26, 2016 2:32 am
Full Name: Jeff-LGPC
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by LGPC »

Hi, the job ran and the backup completed, but no email. This is what I have:

Code: Select all

##################################################################
#                   Notification Settings
##################################################################

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = 'smtp.office365.com'

$SmtpUser = 'jbadre@southhackensacknj.org'

$smtpPassword = ''P@ssw0rd1'

# Email TO
$MailTo = 'jeff@letsgetpersonalcomputing.com'

# Email FROM
$MailFrom = 'jbadre@southhackensacknj.org' 

# Email subject
$MailSubject = "Test using $SmtpServer"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force) 
Send-MailMessage -To "$MailtTo" -from "$MailFrom" -Subject $MailSubject -SmtpServer $SmtpServer -UseSsl -Credential $Credentials

##################################################################
#                   Email formatting 
##################################################################

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

##################################################################
#                   End User Defined Variables
##################################################################

#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin

$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRHvEntity -Name $VMName -Server $Server
  
  If ($EnableEncryption)
  {
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
  }
  
  Else 
  {
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
  }
  
  If ($EnableNotification) 
  {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
  
  if ($FailedSessions -ne $Null)
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
  }
   
  Else
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
  }
  
  }   
}
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

How about setting a breakpoint at the mail sending event and see if all variables contain the values you think they should have...
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

It might be even worth splitting the script (since backup portion works well) and testing o365 email generation part separately. Thanks.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I've split the discussion. Kindly, continue conversation regarding Office 365 notifications in this thread. Thanks.
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 13 guests