<vNugglets_note> I got to work with the PowerCLI master, Luc Dekens, on this module -- what a treat! (Check out his post about the new module at http://lucd.info/drsrule-drs-
The cmdlets from the module are solid as one would expect: pipeline support, value by object or name, WhatIf support, and so on. As for using some of the cool features of PowerShell, the module includes things like advanced/custom type support (including enabling tab-completion of properties later in the pipeline; handy), XML-based external help as manufactured by https://pscmdlethelpeditor.codeplex.com/, and leveraging other object storage formats so as to simplify handling/export/import of rich objects (via JSON) -- just a few of the great features/bonuses by Mr. Dekens. </vNugglets_note>
Now, more about the module.
Why the DRSRule module?
The core PowerCLI PSSnapin from VMware allows for many of the DRS rule operations that one might want to perform. There have been questions over the years in the VMware Communities PowerCLI forum about how to export DRS rules and groups, and, on how to then import such items.While there are several posts on the web about how to get/export such things, importing/recreating DRS rules/groups from such exported data has not received much focus. This was the spark for this DRSRule module: to allow for easy export/import of such rules/groups. As part of making a module to handle these actions, other cmdlets were born, like the Get-/New-/Remove-/Set-* cmdlet sets for DRS VM groups and VMHost groups, along with sets for DRS VM to VM rules and VM to VMHost rules.
How to use the DRSRule module?
The DRSRule module comes with an about_DRSRule.Once the module is installed, use that help topic to get a general introduction to the use of the DRSRule module:
Get-Help about_DRSRule
How to get the DRSRule module?
The source for this PowerShell module is hosted on GitHub.com.The repository is managed by the GitHub organization "PowerCLIGoodies", and the repo itself is at https://github.com/PowerCLIGoodies/DRSRule.
There are a few ways to get the module, and use it in your PowerShell session:
Automated
Via a scriptUse a PowerShell script to perform the download and the extract.
The script is included in the repository as file DownloadLatest.ps1.
Via PsGet
If you have the PsGet module loaded in your PowerShell session, then installing this DRSRule module is as simple as updating PsGet and then installing DRSRule:
Update-Module -Verbose -Module PsGet
Install-Module DRSRule
Manual
Grab the .zip file of the latest release from the GitHub repository.Extract the content to a suitable folder.
You can go for the Modules folder linked to the Windows account you are using. To find this path, run:
Join-Path ${env:\userprofile} "Documents\WindowsPowerShell\Modules"
Or, you can select any other folder you desire.
Either way you will end up with a folder named [PathToModule]\DRSRule, in which the PowerShell files for the DRSRule module reside.
Then, load the DRSRule module into your session:
If you selected one of the folders in $env:PSModulePath (your PSModule path), you can do this with
Import-Module DRSRule
If you picked another folder, you should use the full path to the folder that contains the module's files, like:
Import-Module [PathToModule]\DRSRule
Please also read the note below about using Unblock-File, since this module is not Authenticode signed
Note on Unblock-File
This section pertains to using the Manual method above to get the DRSRule module (downloading .zip file). Since there is no Authenticode certificate supplied for this module, and, assuming that one's PowerShell ExecutionPolicy is at least RemoteSigned, below is a quick/easy way to unblock files. But, this should only be done when you trust the code in the files that you are unblocking -- inspecting the files is for your own good.Get-ChildItem [PathToModule]\DRSRule | Unblock-File
You guys are life savers, busy migrating from one VC to another. You saved me from spending a whole night re-creating hundreds of DRS rules!
ReplyDeleteHey, Tom-
DeleteThanks for the feedback -- glad that the module was helpful!
this is a timer saver. thanks for the work on this module.
ReplyDeletei am getting this error trying to export using pcli6 and vc5.1
Get-DrsVMtoVMRule : Unable to find type [DRSRule.VMToVMRule]. Make sure that
the assembly that contains this type is loaded.
At C:\Temp\DRSRule-Latest\DRSRule.psm1:1066 char:9
+ (Get-DrsVMtoVMRule @hshParamsForGetCall),
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (DRSRule.VMToVMRule:TypeName)
[], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Try running the cmdlets on "VMware PowerCLI (32 bit)" console.
DeleteIt worked for me on PowerCLI 6.5.1.
I had the same issue. Re-installed PowerCLI using the default path C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI and my issue cleared up
ReplyDeleteWould it be possible to specify a vCenter using the import command? I'd like the ability to specify which vCenter to run the import against while connected to multiple vCenters.
ReplyDeleteSomething like:
Import-DrsRule -Path drs.json -Cluster cluster1 -server vCenter1
Thanks
Would it be possible to specify a vCenter using the import command? I'd like the ability to specify which vCenter to run the import against while connected to multiple vCenters.
ReplyDeleteSomething like:
Import-DrsRule -Path drs.json -Cluster cluster1 -server vCenter1
Thanks
Hello, Dan-
DeletePossible? Everything is posh-able, right?! (attempt at humor, with credit to <whoever first said that>). Anyway, sure thing!
In order to help us (anyone who wants to work on this module) track this enhancement request, could you please enter this request in the module's GitHub repo at https://github.com/PowerCLIGoodies/DRSRule/issues ? Then, we (anyone at all) can run with implementing that enhancement, update the world on progress, etc.
Cheers,
Matt
Fantastic tool! We're planning to take a 30-node cluster and split them up into two groups; one group for Windows and one for Linux guests using vmhostaffinity rules. Being able to add all of the vm's to the vm group programatically is a life-saver!!
ReplyDeleteHello, squebel-
DeleteGlad to hear that this module made the day better -- hurray for programability, for sure! Thanks for the feedback.
Cheers,
Matt
Superb work. Used it several times now. Thank you very much!
ReplyDeleteGlad to hear it, @Anonymous. And, hot off the presses: we released v2.0 last evening (15 Nov 2018). It's on e the PowerShell Gallery -- get yours today!
Delete