At the Dutch VMUG, together with my colleague Jos Vanaubel, I presented about how to do cheap disaster recovery using only PowerShell. At the London VMUG I held the same presentation again and promised to upload the scripts to my blog. Well, here it is in PDF format:
The scripts can be downloaded by clicking this link -> Cheap Disaster Recovery Scripts
Before we can failover to DR site, we need the data from the production site. Therefore run the “preparation” scripts weekly or daily, depending on the number of changes. These are your backups. When failover needs to occur, first run failover step 1 and 2, then start the import section. Last step is to boot the vms in failover step 3.
Use the scripts in this order (in the zip file an Excel sheet is included with this info):
Nr | Preparation: | Script name |
1 | Export custom attributes at vCenter level | export-01-attributes |
2 | Export resource pools | export-02-resource-pools |
3 | Export resource pool – VM relation | export-03-resource-pools-with-vms |
4 | Export folders | export-04-folders |
5 | Export folders – VM relation | export-05-vms-with-folderpath |
6 | Export roles and permissions | export-06-roles-permissions-xml |
7 | Export notes from VMs | export-07-vms-with-notes |
8 | Export custom attributes from VMs | export-08-vms-with-attributes |
Nr | Failover: | Script name |
1 | Stop all VMs on production site | failover-01-stop-vms |
2 | Scan datastores for VMs | failover-02-find-register-vms |
Nr | Import: | Script name |
1 | Import custom attributes at vCenter level | import-01-attributes |
2 | Import resource pools | import-02-resource-pools |
3 | Move VMs to resource pools | import-03-move-vms-resource-pools |
4 | Import folders | import-04-folders |
5 | Move VMs to folders | import-05-move-vms-folders |
6 | Import roles and permissions | import-06-roles-permissions-xml |
7 | Import notes from VMs (skipped because included in VMX) | n/a |
8 | Import custom attributes from VMs | import-08-add-VM-attributes |
Nr | Failover: | Script name |
3 | Start all VMs on DR site | failover-03-start-vms |
A special word of thanks to the guys who helped me with these scripts:
Alan Renouf – http://www.virtu-al.net
Luc Dekens – http://www.lucd.info/
Arnim van Lieshout – http://www.van-lieshout.com
Maish Saidel-Keesing – http://technodrone.blogspot.com/
If you have improvements or additions to the scripts, let me know, I’d be happy to post them here.
UPDATE:
Bjørn-Ove Kill found an error in the “export-06-roles-permissions-xml.ps1” script and was able to fix it. Since I can’t test all possible scenario’s in PowerShell combinations, I’m leaving the original script up and offer the simple fix here:
From his e-mail:
The script generated errors on line 64, 65 and 68 in the Attached script file (modified Your script – just one line needed to be modified to make it work).
At line 76 you have specified
[XML]$vInventory = “
I replaced that With this: $global:vInventory =
“<Inventory><Roles/><Permissions/></Inventory>”
Thank you for your solution Bjørn-Ove !!! Visit his blog at http://www.auxilium.no/auxilium/blogg.
Yes….. koet gedaan :-D
Special greeeeetz from Brad Pit from Rekem
Ping back
https://community.emc.com/message/535760#535760
I’m very pleased with your work.
When attempting to run your script, I get the following error. Any help possibly? Thanks!
You cannot call a method on a null-valued expression.
At C:scriptsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:64
char:3
+ $tmp = $global:vInventory.CreateElement($nodeName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:scriptsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:65
char:3
+ $node.AppendChild($tmp)
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:scriptsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:69
char:3
+ $node.SetAttribute($name, $value)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Hi, Just sent you an e-mail.
I’m getting the same error as Christopher Apostolof… Can you help?
Hi. I have the same problem. Can you please assist?
Thanks,
Mark
I have just sent you an e-mail.
Sorry, I somehow missed your comment. Still need help?
Hello, I am also getting the same error attempting the export of the roles/permissions.
Are you able to publish the fix?
Thanks
Brad
Hi Brad, check your e-mail.
Hello Gabrie,
can you send me the mail too?
Thanks!
Check your e-mail :-)
I am having the same issue as well, can you let me know the solution?
Hi Gabrie
Can you please send me the fix as well.
Thanks
Hi. Please send me an e-mail or post with your real e-mail address. I haven’t got a fix for it since I’m not running into this error in my test. When you e-mail me, I will try to help you figure out what is going wrong.
Im having this problem as well can you send the fix to vmware-issue@yopmail.com please :-)
Gabe, I am having the sam issue with the roles. Can you help? viper3256@hotmail.com
Hi, great scripts for migrating to New vcenter servers. But, I’m experiencing the same issues as many others. Could you please give me a hint to how to fix this ? What did the other do to get past this ? Thanks!
Hi, unfortunately I received no responses of the other people who left a comment to be able to help them troubleshoot. I will send you a private e-mail to which you can reply.
Awesome! I couldn’t import the folders in one piece and rather had to split the script to single-line extracts but it worked awesome to export and import more than 130 folders including subfolders etc. – perfect, THANK YOU!
Good Afternoon, I modified the import permissions with Bjørn-Ove Kill fix, but I got the below error:
I changed it from this:
[XML]$vInventory = “”
to this:
$global:vInventory =
“”
was that correct ?
I got the below error:
Method invocation failed because [System.String] does not contain a method named ‘Load’.
At line:54 char:1
+ $vInventory.Load($XMLfile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.String] does not contain a method named ‘SelectNodes’.
At line:61 char:1
+ $vInventory.SelectNodes($XpathRoles) | % {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.String] does not contain a method named ‘SelectNodes’.
At line:72 char:1
+ $vInventory.SelectNodes($XpathPermissions) | % {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
I am getting the same error. I have updated line 75 from [XML]$vInventory = “” to $global:vInventory = “”.
What else is required?
Did you ever get a reply for this question? I could need this script to work aswell
Sorry, the script is very old and I don’t have the environment to reproduce the error.
I got an powershellwizard at work to help me with this, and the correct line for my environment is: [xml] $global:vInventory = “”
Hi,
I know this is pretty old, but I wanted to use these scripts and I am getting below error. Is there any chance you can help me with the fix which you have sent to others in the discussion ?
Method invocation failed because [System.String] does not contain a method named ‘SelectNodes’.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:73 char:3
+ $vInventory.SelectNodes($path)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.String] does not contain a method named ‘CreateElement’.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:64 char:3
+ $tmp = $global:vInventory.CreateElement($nodeName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
You cannot call a method on a null-valued expression.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:65 char:3
+ $node.AppendChild($tmp)
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:69 char:3
+ $node.SetAttribute($name, $value)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:69 char:3
+ $node.SetAttribute($name, $value)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:69 char:3
+ $node.SetAttribute($name, $value)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Method invocation failed because [System.String] does not contain a method named ‘CreateElement’.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:64 char:3
+ $tmp = $global:vInventory.CreateElement($nodeName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
You cannot call a method on a null-valued expression.
At C:UserspprasannanDownloadsCheapDisasterRecoveryexport-06-roles-permissions-xml.ps1:65 char:3
+ $node.AppendChild($tmp)
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
Hi
Did you see the update I wrote below my post? Did this solve your issue?
Gabrie
Hi , Thanks a lot for your reply. I hope you are pointing about the solution by Bjørn-Ove, I already tried it. It didnt help me.
-Praveen
I’m afraid the Powershell version might be too old and I can’t reproduce the issue since I don’t have the same components anymore. Maybe you can find another script to export the permissions?