Giter Club home page Giter Club logo

drsrule's Introduction

DRSRule PowerShell module ReadMe

The DRSRule module allows you to work with all types of vSphere DRS rules. The module provides support for VM and VMHost groups. And, it works with affinity/anti-affinity VM rules and VM to VMHost rules.

Brief info on module

The module came from the need for DRS rule/group info gathering, exporting, and recreating. Initially there were some code blocks for exporting rule info and for importing again those rules, but things evolved into a module.

A couple of examples:

  • Export rule/group info: Export-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json
  • Import rule/group info: Import-DrsRule -Path c:\someFolder\myDrsRuleAndGroupInfo.json

How to set up the DRSRule module for use:

Via the PowerShell Gallery and PowerShellGet:

  • [optional, but smart] Save the module and inspect (safety first!): Find-Module DRSRule | Save-Module -Path c:\temp\someFolder
  • Once comfortable with the safety of the module: Find-Module DRSRule | Install-Module

Or, the "old", manual way:

  • Download and extract the module .zip file
  • Unblock-File on the extracted contents
  • Import-Module <path\To\ModuleFolder>
  • Use Get-Help as per usual for cmdlet help and examples

Cmdlets in this module

  • Export/Import:
    • Export-DrsRule
    • Import-DrsRule
  • Get:
    • Get-DrsVMGroup
    • Get-DrsVMHostGroup
    • Get-DrsVMToVMHostRule
    • Get-DrsVMToVMRule
  • New:
    • New-DrsVMGroup
    • New-DrsVMHostGroup
    • New-DrsVMToVMHostRule
    • New-DrsVMToVMRule
  • Remove:
    • Remove-DrsVMGroup
    • Remove-DrsVMHostGroup
    • Remove-DrsVMToVMHostRule
    • Remove-DrsVMToVMRule
  • Set:
    • Set-DrsVMGroup
    • Set-DrsVMHostGroup
    • Set-DrsVMToVMHostRule
    • Set-DrsVMToVMRule

drsrule's People

Contributors

mtboren avatar lucdekens avatar gpduck avatar

Stargazers

 avatar Matze avatar Ahmad Saleem avatar Raoul Schaffner avatar  avatar  avatar  avatar Jeff Jerousek avatar Hiko Davis avatar Dimi avatar Hans Guthrie avatar Miguel avatar Markus Kraus avatar DCLacoste avatar Vladan Laxa avatar  avatar Ryan Bolger avatar Matthew avatar Campbell Pool avatar  avatar Francisco Navarro avatar Andrei Nevedomskii avatar  avatar Jeff McCollum avatar yeahuh avatar  avatar Claudio Galletti avatar Kevin Kirkpatrick avatar Timo Sugliani avatar

Watchers

James Cloos avatar  avatar Ryan Bolger avatar Minhan Zhong avatar  avatar Claudio Galletti avatar  avatar Hiko Davis avatar  avatar  avatar Raoul Schaffner avatar Per Nygaard avatar Dimi avatar  avatar

drsrule's Issues

New-DrsVMtoVMHostRule setting affinity correctly?

For New-DrsVMtoVMHostRule the -AffineHostGroupName switch seems to set a new rule to be anti-affinity and -AntiAffineHostGroupName is setting it to be affinity?

e.g.
New-DrsVMToVMHostRule -Name licencing_windows_vmhostrule -Cluster $cluster -VMGroupName licencing_windows_vmgroup -AntiAffineHostGroupName licencing_windows_hostgroup -whatif
What if: Performing the operation "Create AffineVMToVMHost DRS rule 'licencing_windows_vmhostrule'" on target "cluster1".

vs

New-DrsVMToVMHostRule -Name licencing_windows_vmhostrule -Cluster $cluster -VMGroupName licencing_windows_vmgroup -AffineHostGroupName licencing_windows_hostgroup -whatif
What if: Performing the operation "Create AntiAffineVMToVMHost DRS rule
licencing_windows_vmhostrule'" on target "cluster1".

Unable to find type [DRSRule_VMToVMRule]

Hi,
I have a problem with the DRSRule module v2:
Just a simple export script:

$vCenter = "servername"
$Exportpath = "C:\Scripts_chs"
$date = (Get-date -format yyyyMMdd)
Connect-VIServer $vCenter
Export-DrsRule -Path $Exportpath"\DrsRuleInfo_$date.json"

If I run the script .\bla.ps1 rise up the following error:

Unable to find type [DRSRule_VMToVMRule].
At C:\Program Files\WindowsPowerShell\Modules\DRSRule\2.0.0\DRSRule.psm1:271 char:15
+   [OutputType([DRSRule_VMToVMRule],[VMware.Vim.ClusterAffinityRuleSpe ...
+               ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (DRSRule_VMToVMRule:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

If I copy and paste the code in a fresh Powershell session, the export file will generate without a problem.

A little bit strange, isn't it?
Do you have any ideas?

My modules:

ModuleType Version    Name
---------- -------    ----
Script     2.0.0      DRSRule
Manifest   3.1.0.0    Microsoft.PowerShell.Management
Manifest   3.1.0.0    Microsoft.PowerShell.Utility
Script     6.7.0.1... VMware.Vim
Script     11.0.0.... VMware.VimAutomation.Cis.Core
Script     11.0.0.... VMware.VimAutomation.Common
Script     11.0.0.... VMware.VimAutomation.Core
Script     11.0.0.... VMware.VimAutomation.Sdk

Thanks

Error at addition in empty group the VM list

At addition in empty group the VM list

Set-DrsVMGroup -Name $vmDRSgroup -Append -VM $CNVMlist.Name -Cluster $cluster
Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null.
At C:\Program Files (x86)\WindowsPowerShell\Modules\DRSRule\DRSRule.psm1:1088 char:60
+         elseif ($null -eq (Compare-Object -ReferenceObject $arrOriginalVMIDsInTa ...
+                                                            ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
PS C:\> $vmDRSgroup
xx-NK

PS C:\> $CNVMlist.Name
89-NK-SQL02
77-NK-APP03
15-NK-TRM02
89-NK-PRN01
16-NK-1C03

Import-DrsRule does not support specifying rule by type

It would be nice to be able to specify the rule not only by name, but also by type, when importing DRS rules from a file.

The way it's implemented right now, if I say have a host group called "host2" and VM to host rule "host2" and I call Import-DrsRule with the following parameters:

Import-DrsRule -Cluster "my-cluster" -Path "drs-rule-export.json" -Name "host2"

Cmdlet will attempt to import both the group and the rule, which is not always what you want. This is the bit of code that checks the name:

## if -Name was specified, filter
if ($PSBoundParameters.ContainsKey("Name")) {$arrRuleObjects_filtered = $arrRuleObjects_filtered | Where-Object -FilterScript {$_.Name -like $Name}}

The following piece of code will need to be added to also check for type:

## if -Type was specified, filter
if ($PSBoundParameters.ContainsKey("Type")) {$arrRuleObjects_filtered = $arrRuleObjects_filtered | Where-Object -FilterScript {$_.Type -like $Type}}

Cannot find type [DRSRule_VMGroup]: Verify that the assembly containing this type is loaded

Hello I updated to version 2.0.0 from 1.2 and now I am receiving the following error when running Get-DrsVMGroup:

New-Object : Cannot find type [DRSRule_VMGroup]: verify that the assembly containing this type is loaded.
At C:\Program Files\WindowsPowerShell\Modules\DRSRule\2.0.0\DRSRule.psm1:92 char:11

  •       New-Object -TypeName DRSRule_VMGroup -Property @{
    
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Running VMware.VimAutomation.Cis.Core 11.2.0 on PS 5.1

Add Pester tests for more than Get-* cmdlets

Let's add Pester tests for as many of the rest of the cmdlets as we can. This will likely include some setup/removal of test objects, like temporary VMs to use in DRS VMGroups, for example.

We've needed to do this for a long time, but have not yet made the time to do so

Module won't load if VMware.VimAutomation.Core not already loaded

Requiring the VMware.Vim.dll assembly in the DRSRule PSD1 file essentially means that the VMware.VimAutomation.Core module should be imported in the current session. If that module is not loaded (or, if the person as not manually added the given VMware.Vim.dll assembly in the current PowerShell session), importing the DRSRule module fails.

Check if VM is in a DrsVMGroup

Hi,
is there a way to check if a VM is already in a DrsVMGroup?
Or can i load all the VM Names from the Group and match them by myself?

PowerCLI C:\> Get-DrsVMGroup -Name "All VMs" -Cluster DMZ -ReturnRawGroup

Vm          : {VirtualMachine-vm-720, VirtualMachine-vm-706, VirtualMachine-vm-703, VirtualMachine-vm-66968...}
LinkedView  :
Name        : All VMs
UserCreated : True
UniqueID    :

PowerCLI C:\> Get-DrsVMGroup -Name "All VMs" -Cluster DMZ

Name                     Cluster          UserCreated   VM
----                     -------          -----------   --
All VMs                 DMZ              True          {FOO-P01, BAR-P01, JADA-P01, LANA-T01...

Thanks Matthias

Module init failing for machine with multiple version of PowerCLI available

In the module initialization code, things fail is the machine on which the DRSRule module is being imported has more than one available version of the VMware.VimAutomation.Core module (like, when the module has been updated and the old version still remains).

This results in "broken module", due to the failure to determine the correct path for VMware.Vim.dll, which is the type definition portion of initialization references.

Unable to find type [DRSRule.VMGroup]

Version: Get-DRSRule 1.2.1

When trying to use a function, always get Errors:

Get-DrsVmGroup
Unable to find type [DRSRule.VMGroup].
At C:\Users\XXX\Documents\WindowsPowerShell\Modules\DRSRule\DRSRule.psm1:55 char:15
+   [OutputType([DRSRule.VMGroup],[VMware.Vim.ClusterVmGroup])]
+               ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (DRSRule.VMGroup:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Get-DrsVMHostRule
Unable to find type [DRSRule.VMHostGroup].
At C:\Users\XXX\Documents\WindowsPowerShell\Modules\DRSRule\DRSRule.psm1:167 char:15
+   [OutputType([DRSRule.VMHostGroup],[VMware.Vim.ClusterHostGroup])]
+               ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (DRSRule.VMHostGroup:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Get-DrsVmHostGroup
Unable to find type [DRSRule.VMHostGroup].
At C:\Users\XXX\Documents\WindowsPowerShell\Modules\DRSRule\DRSRule.psm1:167 char:15
+   [OutputType([DRSRule.VMHostGroup],[VMware.Vim.ClusterHostGroup])]
+               ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (DRSRule.VMHostGroup:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

See also:  https://communities.vmware.com/thread/508831
Latest Entrys have the same problem and it seems to be a new Issue.

Errors when importing from previously exported VMHost group

Opening new issue from comment from user @gillx0101 (original comment here)

Can someone help! I'm able to use the export-drsrule successfully, but get errors when importing the txt file with the following;

Get-DrsRuleObject : Cannot validate argument on parameter 'Object'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\Program Files\WindowsPowerShell\Modules\DRSRule\2.0.0\DRSRule.psm1:1572 char:38

... _filtered | Get-DrsRuleObject -Type 'ClusterAffinityRuleSpec|ClusterA ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidData: (:) [Get-DrsRuleObject], ParameterBindingValidationException
FullyQualifiedErrorId : ParameterArgumentValidationError,Get-DrsRuleObject
I am using Powercli VMware PowerCLI 11.3.0 build 13990089 and verion 2.0.0 of the DRSRule.

I am testing with vcentre 6.7, creating a test VM/Host group, exporting out then deleting from vmware and trying to import back in from the export file. Any pointers would be appreciated.>

Metadata file VMware.Vim.dll could not be found

I installed vmware module wit NuGet and it turnsout that VMware.Vim.dll is put in a subdirectory net45. your code:

$strVMwareVimDllDirectory = if ($oModuleInfo.Version -ge $verPowerCLIWhereDllMoved) {$oModuleInfo.ModuleBase} else {(Get-Item (Get-Module VMware.VimAutomation.Core).ModuleBase).Parent.Parent.FullName}

$pcliDll = Join-Path -Path $strVMwareVimDllDirectory -ChildPath "VMware.Vim.dll"

your code does not check for the net45 or netcoreapp2.0 folder.

Import-Module error in PowerCLI 6.5

When importing the DRSRule module in PowerCLI 6.5, the following error is displayed.

Import-DrsRule : Unable to find type [DRSRule.VMGroup]. Make sure that the assembly that contains this type is loaded.
At line:1 char:1

  • Import-DrsRule
  •   + CategoryInfo          : InvalidOperation: (DRSRule.VMGroup:TypeName) [], RuntimeException
      + FullyQualifiedErrorId : TypeNotFound
    

VMware.VimAutomation.Core path change in 6.5.1

Just downloaded the latest PowerCLI and ran into issues:

PowerCLI Version

VMware PowerCLI 6.5.1 build 5377412

Component Versions

VMware Cis Core PowerCLI Component 6.5 build 5374323
VMware VimAutomation Core PowerCLI Component 6.5 build 5374329

I manually modified $pcliDLL path in DRSRule.init.ps1 to fix the issue.

If new PowerCLI modules are installed to current user (via 6.5.1 user guide: Install-Module VMware.PowerCLI -Scope CurrentUser), then path is (for this build) $HOME\documents\WindowsPowerShell\Modules\VMware.VimAutomation.Core\6.5.1.5374329, if installing for all users it's Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Core\6.5.1.5374329

Obviously the version/build directory name will change with the new way PowerCLI/Modules are being delivered, so it might be best to get/store the version number in a variable in the path.

Improvement: add Argument Completers to cmdlet parameters

To enhance the ease of use of the cmdlets, let's add argument completers to as many parameters as makes sense. Like, auto-completer values for:

  • -Cluster
  • -VMHost
  • -VM
  • -Name for VMGroup, VMHostGroup, Rules, etc.
  • -AffineHostGroupName, -AntiAffineHostGroupName
    ..so on

Improvement: start using modern Class capabilities

Might be about time to move to the Class capabilities introduced in PowerShell v5 -- the "hopefully find and eventually refer to some DLL" game grows ever less fun, and we can modernize the module a bit, anyway.

That we already require the VMware.VimAutomation.Core module will have us already ready to use many VMware type references in our new PowerShell classes.

Deprecate/remove use of Latest tag and antiquated distro means

Embrace the use of PowerShellGallery for module distribution/updates (module is in the PSGallery as of Jul 2018).

We have the DownloadLatest.ps1 code that was provided for ease of module grabs before the days of PSGallery. Now that we leverage PSGallery for module distribution, we can remove the legacy code.

Remove VM from DRSVMGroup

Hello,

First of all, thanks for your work on ths module !
I'm certainly missing something but I can't figure how to remove a VM from a DRSVMGroup. Could you tell me if it's possible or not ?

Errors not throwing actual error.

The functions are throwing custom errors rather than passing the original error back out which is problematic. I ran into an issue when trying to wrap your module into another function where the drsrule functions were failing because I wasn't importing the vmware module into the global scope. So rather than the error displaying what was really happening (get-vm command not found) it was saying the vm itself wasn't found which was not the issue at all.

I changed the below with a possible alternative

          try {
            ## limit scope to this cluster
            $oThisCluster | Get-VM -Name $oThisVmItem -ErrorAction:Stop
          }
          catch {
          #this commented out is the original message
          #Throw "No VM of name '$oThisVmItem' found in cluster '$($oThisCluster.Name)'. Valid VM name?"
          Throw "$($oThisCluster.Name) - Error looking up $oThisVmItem - $($_.Exception.Message)"
          }

Module version not current

The ModuleVersion in the DRSRule.psd1 is "1.0.1", whereas this version of the module is actually "1.0.2". Module shows as "1.0.1" in PowerShell because of this configuration item.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.