PowerShell script exchange
Post Reply
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Nothing happens when I execute the veeam powershell script?

Post by daystrom »

I have veeam 9.5 free, and would like to schedule a zip backup every day. I used the VeeamZIP (HV).ps1 script as a starting point. It seems straightforward - changed the vm name, the host name, set a valid destination path, turned off encryption and turned off EnableQuiescence. When I run the script via task manager (windows 2012 server) with highest privileges, it says "running" but nothing seems to happen. I terminate the task after about an hour - the backup should take 20 minutes. I don't see veeam using cpu or memory. No backup files are created.

How can I tell what is wrong? I haven't used powershell very much. I did update to ps 4 from 3, hoping that might help, but the test result was the same.
Shestakov
Veteran
Posts: 7328
Liked: 781 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Shestakov »

Hello and welcome to the community!
It`s hard to say neither seeing the script nor the logs. Could you provide the script you are using?
Thanks!
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by nielsengelen »

Also if you manually run the Powershell scripts does it work then?
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

Right...manually running, I'd forgotten that I tested that. It pops up a yes/no asking if I want to change the execution policy. I've never told it to change the policy. I guess this is a barrier to malware or something. And it probably explains why it just does nothing via task manager. I will allow the change and try it again. Did that - ps window stayed open for a few seconds and then closed. It's been five minutes and I don't see any new vbk files. The sql server instanced that is used by veeam is somewhat active, but none of the other veeam services are. Not sure what it adds up to?

Not knowing ps - should I expect to see the ps window stay open as long as the script that was executed is in play? But maybe the script is over almost immediately, and now veeam should be doing it's thing according to the parameters?
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by nielsengelen »

Do you see a running job in the Veeam GUI and if so what is the status saying?
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

I don't see a job running.
I wonder if the issue is the host name? I have entered the name of the server that veeam is running on and which is also the host of the vms.

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "AMA-VH01"

But I noticed that the connection when I log on to veeam is simply localhost. It should mean the same thing. The dialog that veeam presents which specifies the connection to localhost was not there in the older version of veeam I was using before (8.0)
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by nielsengelen »

Can you ping that hostname from the server you are running the script? You need to use the hypervisor hostname or IP (if you can't resolve it).
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

It's the same server. Very simple setup, one physical box, AMA-VH01, which has veeam installed, and hosts the two vms I want to back up with veeam.
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

here is the script; guess I have to post it here in the msg.

Code: Select all

# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/member31097.html
# 

# 20170408 modified from VeeamZIP (HV).ps1
 
##################################################################
#                   User Defined Variables
##################################################################

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = "AMA-DC1"

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "AMA-VH01"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "G:\ama vm images"

# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme) 
$CompressionLevel = "5"

# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $False

# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False

# Encryption Key (Optional; path to a secure string)
$EncryptionKey = ""

# Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time. 
# Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = "In1Week"

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

# Enable notification (Optional)
$EnableNotification = $False

# Email SMTP server
$SMTPServer = ""

# Email FROM
$EmailFrom = "" 

# Email TO
$EmailTo = ""

# Email subject
$EmailSubject = ""

##################################################################
#                   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)
}


Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

Hi Daystrom,

Let's start with an easy check. Can you open windows powershell ISE and run it as an administrator? Then run the script from in there. The advantage is that the pane will stay open so you can see what is happening (maybe it is asking a question somewhere).

Let us know what it does
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by veremin »

Also, it might be verifying whether server and VM variables get assigned properly, use the following script to confirm that:

Code: Select all

Asnp VeeamPSSnapin
$VMNames = "AMA-DC1"
$HostName = "AMA-VH01"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
$VM
Thanks.
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

Thanks for those ps tips, new turf for me, and interesting.
running the script via admin ps shows this:

Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At C:\scripts\VeeamZIP_mms.ps1:88 char:40
+ $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+ ~~~
+ CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip

I don't see a parameter 'Entity' in the script?
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

I ran the test script.

PS C:\scripts> .\test01.ps1

Info : ama-vh01 (Microsoft Hyper-V Server)
ParentId : 00000000-0000-0000-0000-000000000000
Id : 1b42f5d8-2c94-4c16-bcb6-0e0b93d98721
Name : ama-vh01
Reference :
Description : Created by AMA\someadmin at 12/14/2015 3:07:19 PM.
IsUnavailable : False
Type : HvServer
ApiVersion : Unknown
PhysHostId : d7c4ff97-b99b-4d1f-884d-283b7b6b9ee3
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

Find-VBRHvEntity : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\scripts\test01.ps1:6 char:30
+ $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Find-VBRHvEntity], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.FindVBRHvEntity
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

Just noticed (at least I think) that V.Eremin probably has a typo in that test script

Code: Select all

Asnp VeeamPSSnapin
$VMName = "AMA-DC1"
$HostName = "AMA-VH01"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
$VM
Can you try again with the above code? (The variable name for the VM didn't match the variable name in the last line (an S too much) :-)
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

Right, with the revised script it returned this:

PS C:\scripts> .\test01.ps1

Info : ama-vh01 (Microsoft Hyper-V Server)
ParentId : 00000000-0000-0000-0000-000000000000
Id : 1b42f5d8-2c94-4c16-bcb6-0e0b93d98721
Name : ama-vh01
Reference :
Description : Created by AMA\someadmin at 12/14/2015 3:07:19 PM.
IsUnavailable : False
Type : HvServer
ApiVersion : Unknown
PhysHostId : d7c4ff97-b99b-4d1f-884d-283b7b6b9ee3
ProxyServicesCreds : Veeam.Backup.Common.CCredentials
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

Hi again,

From what I can see, it looks like you are not receiving all the information. I am going to ask you to do this "script" again but just copy/ paste the lines in the script pane of that ISE program we talked about.
Then, you have the possibility to run line by line and see what happens. (Select a line, press F8, then select the next line, press F8 and so on...) Normally I would expect that you see two outputs. The one you pasted above is the output for the variable $server (so we know that that one works :-)). But then you should also have an output for $VM and I cannot see that one.

Maybe really stupid but is your VMname actually ama-dc1 or is it named differently in Hyper-V manager?

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

Re: Nothing happens when I execute the veeam powershell scri

Post by veremin »

Right, with the revised script it returned this:
Only Hyper-V server gets returned, which means that VM with the given name cannot be found.

Can you see it, if you go to a backup console -> Virtual Machines node and expand the Hyper-V server? If yes, what exact name does it have?

Thanks.
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

So, nothing looks wrong with the script, but it fails? It must be working for many of you, and my case is very simple.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by veremin »

The script does not fail, it works, however, it does not return a specific VM you're trying to backup. If you go to backup console, open the Virtual Machines node, can you see the given VM there? What name does it have?

Can you also run the following script and check the list of object names returned by it?

Code: Select all

Asnp VeeamPSSnapin
$HostName = "AMA-VH01"
$Server = Get-VBRServer -name $HostName
Find-VBRHvEntity -Server $Server | select name
Thanks
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

Ack, apologies...since a day or two ago I had thought no one had posted new comments. I was refreshing the page I'd posted to, and it happened that my post was the last one on page 1, so the new comments never appeared in the browser. After my post today I saw the stuff on page 2. I am not getting notifications re new postings from this forum.

Here is the output from the test requested by v.Eremin

PS C:\scripts> .\test02.ps1

Info : ama-vh01 (Microsoft Hyper-V Server)
ParentId : 00000000-0000-0000-0000-000000000000
Id : 1b42f5d8-2c94-4c16-bcb6-0e0b93d98721
Name : ama-vh01
Reference :
Description : Created by AMA\someadmin at 12/14/2015 3:07:19 PM.
IsUnavailable : False
Type : HvServer
ApiVersion : Unknown
PhysHostId : d7c4ff97-b99b-4d1f-884d-283b7b6b9ee3
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

You had earlier asked "Can you see it, if you go to a backup console -> Virtual Machines node and expand the Hyper-V server? If yes, what exact name does it have? "

In the veeam backup and replication console it's like this:
Infrastructure
--Microsoft Hyper-V
----AMA-vh01

If I select AMA-vh01 in that left side VIRTUAL MACHINES area, the main panel on the right shows the three vms that run on AMA-VH01
AMA-DC1
AMA-APPS1
AMA-Test

In this initial test I intend to include only AMA-DC1 in the backup, but later would add the AMA-APPS1 server.

BTW, the host AMA-VH01 is windows server std, not R2. I think I mentioned that early on but am not sure. Is R2 needed to get veeam to work with ps?
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

This is in reponse to Mike's request. In ps ise, using F8:

Asnp VeeamPSSnapin
$VMName = "AMA-DC1"
$HostName = "AMA-VH01"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
$VM

All the script is doing is setting up two variables with the host name and vm name, instantiating the host, which is successful, and then attemping to locate the vm via expected vm name, and it returns nothing. That's correct? The vm name is correct. I tried the script with another of the vm names with the same result - nothing found.
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

Strange,

$VM should give you an output as V.Eremin and I already said. However, did you run the last script he asked? Because that last script should have given an output as such:

Name
------
AMA-VH01
AMA-DC01
AMA-APPS1
AMA-TEST
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

You're right, that was an error on my part, that was the wrong script output I showed. This is what the v.eremin shows


Name
----
ama-vh01
AMA-DC1 - Windows 2012 AD-FSMO Server - PRODUCTION
AMA-TEST
AMA-APPS1 - Windows 2012 Primary App Server - PRODUCTION
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

So, mystery solved - I never imagined that "AMA-DC1 - Windows 2012 AD-FSMO Server - PRODUCTION" was actually the name of the vm. I thought it was the name plus some kind of descriptor field. I didn't set these servers up. Anyways that's kind of a funny result to all of this. The test script now works as expected and no doubt the ps backup script will work too. Thanks to both of you for your help!
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

That is one hell of a name :-)

Since these are the names of the VM's, you can always use Hyper-V Manager and change those. However, be aware that there might be some other scripts or tools that use that specific name

Anyway, glad it is solved now!
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

BTW, is there a trick to getting notification by email of subscribed threads? At the bottom of this page is

Board index Subscribe topic Bookmark topic

and there is a checkbox next to subscribe. Clicking the checkbox does nothing - it's already checked, doesn't change value, possibly because I'm the OP? Nothing in spam folder. But I have never gotten any notices about this thread. I don't see any other switch for subscribing.
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by Mike Resseler »

Normally when you click on the checkbox, it should become an 'x' instead of (some sort of) a 'v'. When it is an x, you are subscribed and you should get notifications
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Nothing happens when I execute the veeam powershell scri

Post by daystrom »

It turns out that clicking the "check" does not do anything at all - it's an image and that's all. The text "subscribe topic" does take the action and the image goes from a check to an x. Pretty strange design by phpBB but that is how it works.
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests