Returning correct data type to Reset-HvVmChangeTracking cmd?

PowerShell script exchange

Returning correct data type to Reset-HvVmChangeTracking cmd?

Veeam Logoby Mr Dudeman » Thu May 11, 2017 12:20 am

Hi All,

I am running some VEEAM PowerShell, after first filling an array with Key / Host / Virtual Machine data.

The array is used to feed parameters into the 'Reset-HvVmChangeTracking' cmdlet; here is some pseudo code to demonstrate!
Code: Select all
for($i=0; $i -lt $VMEnumerate; $i++)
{
   Reset-HvVmChangeTracking -Server $EduHosts_VMs[$i][1] -VMName $EduHosts_VMs[$i][2] -WhatIf
}


The 'Reset-HvVmChangeTracking' cmdlet requires a 'Veeam.Backup.Core.Common.CHost' object supplied as an argument to the -Server parameter.I have tried to supply the relevant object using two code techniques, each of which has produced errors.

Here are the two techniques that I have utilised, the first uses a script block -

Code: Select all
for($i=0; $i -lt $VMEnumerate; $i++)
{
    Reset-HvVmChangeTracking -Server {Get-VBRServer -Name $EduHosts_VMs[$i][1]} -VMName $EduHosts_VMs[$i][2] -WhatIf
}


The above code returns the following error -Reset-HvVmChangeTracking : Cannot bind parameter 'Server'. Cannot convert the " Get-VBRServer -Name $EduHosts_VMs[$i][1] " value of type
"System.Management.Automation.ScriptBlock" to type "Veeam.Backup.Core.Common.CHost".

The second code technique that I have attempted utilises brackets () -

Code: Select all
for($i=0; $i -lt $VMEnumerate; $i++)
{
    Reset-HvVmChangeTracking -Server (Get-VBRServer -Name $EduHosts_VMs[$i][1]) -VMName $EduHosts_VMs[$i][2] -WhatIf
}


The above code returns the following error -Reset-HvVmChangeTracking : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.Common.CHost' required by parameter 'Server'. Specified method is not supported.

Both of the issues that I have encountered essentially relate to the returned data type being incorrect.

How can I go about getting back data in the correct format for the 'Reset-HvVmChangeTracking' cmdlet?

Any help will be greatly appreciated.

Kind Regards,

Davo 
Mr Dudeman
Influencer
 
Posts: 20
Liked: never
Joined: Wed Mar 08, 2017 10:19 pm
Full Name: David Dartnell

Re: Returning correct data type to Reset-HvVmChangeTracking

Veeam Logoby nefes » Thu May 11, 2017 11:45 am

Second version is closer to the correct one. You could try to understand, why Get-VBRServer -Name $EduHosts_VMs[$i][1] gives several results for some $i.
Dirty workaround will be to take first of the servers you find, like (Get-VBRServer -Name $EduHosts_VMs[$i][1])[0], but it is better to find out, why you get several servers.
Or you may see the problem that incorrect server is used for resetting ChangeTracking.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests