PowerShell script exchange
Post Reply
duck304
Novice
Posts: 3
Liked: never
Joined: Apr 26, 2017 5:26 pm
Full Name: Dave Greebe
Contact:

Storage policy not applied

Post by duck304 » Apr 26, 2017 5:40 pm

Hi All,

I'm building a PS-script that will automaticaly restore 4 random VM's every day.
I want to apply a seperate storagepolicy to those VM's but the default storage policy is applied and I cannot figure out why.

A snippet of my code;

Code: Select all

   
$selectedHost = (Get-Cluster -Name Productie | Get-VMHost | where ConnectionState -like "Connected" | Get-Random).tostring()

$VBRhost = Get-vbrserver -Type ESXi | where Name -like $selectedHost

$AllProdVMs = Get-VBRRestorePoint -Backup $Backup | where CreationTime -lt (get-date).AddDays(-$DaysBackInHistory) 

$SelectedVM = Get-random -InputObject $AllProdVMs

$Datastore = (Get-AvailableStorageVSAN -VMSize ([math]::Round(($SelectedVM.ApproxSize / 1024 / 1024 / 1024), 0) ) )
$VBRDatastore = Find-vbrvidatastore -Name "$Datastore" -server "$selectedHost"

$VBRStoragePolicy = Find-VBRViStoragePolicy -Server $VBRhost -Name "vSAN No Redundancy"

Start-VBRRestoreVM -RestorePoint $SelectedVM -Datastore $VBRDatastore -Folder $RestoreFolder -VMName "$restoredVMName" -StoragePolicy $VBRStoragePolicy -Server $selectedHost -Reason "Script-ID $scriptID. Scripted restore-test" -OutVariable Restore | out-null
Basically;
Get hosts
Get a random host
Get Backup file
Get all restore-points
Get a random restorepoint and that will be your VM that will be restored
Check is storage is available. its a custom function.
Get storagepolixy by name
Restore VM to a new location.

The "vSAN No redundancy" is available because I don't get an error and in the GUI I do see that policy....
I'm using Veeam V9.

Hope to hear from somebody

best regards
dave

v.eremin
Product Manager
Posts: 16359
Liked: 1348 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Storage policy not applied

Post by v.eremin » Apr 26, 2017 6:56 pm

Can you tell me whether inputting $VBRStoragePolicy variable on its own returns something? Want to make sure the variable gets assigned properly. Thanks.

duck304
Novice
Posts: 3
Liked: never
Joined: Apr 26, 2017 5:26 pm
Full Name: Dave Greebe
Contact:

Re: Storage policy not applied

Post by duck304 » Apr 27, 2017 4:27 am

v.Eremin wrote:Can you tell me whether inputting $VBRStoragePolicy variable on its own returns something? Want to make sure the variable gets assigned properly. Thanks.
it return

Code: Select all

Id          : 780fd103-f300-4ddb-adc8-c62d41c406d5
UpdateTime  : 06-Feb-17 4:57:49 PM
HostId      : 7bfc5c3a-d938-4975-a56c-c2f33e5afd1b
Name        : vSAN No Redundancy
Description : 

v.eremin
Product Manager
Posts: 16359
Liked: 1348 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Storage policy not applied

Post by v.eremin » Apr 27, 2017 9:48 am

OK, variable assignment works correctly. We'll try to confirm the reported problem. I'll update the topic, once I have more information.

v.eremin
Product Manager
Posts: 16359
Liked: 1348 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Storage policy not applied

Post by v.eremin » Apr 27, 2017 2:23 pm

We have been unable to confirm the experienced behaviour. In our tests we've used version 9.5. So, it might be worth updating to the latest product version and checking whether the problem persists. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests