PowerCLIGoodies / DRSRule

PowerShell module with support for managing vSphere DRS Rules and Groups
28 stars 9 forks source link

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

Open Poolshark314 opened 5 years ago

Poolshark314 commented 5 years ago

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

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

Poolshark314 commented 5 years ago

Good morning,

I am still having this issue. Is there anyone looking into this?

mtboren commented 5 years ago

Greetings, @Poolshark314 -

I've started looking into this. I have not been able to reproduce the situation, yet, but I also have no machines with PS v5.0 on them -- v5.1 or newer, here. I will continue to work to find such a machine.

In the meantime, how does the DRSRule v2.0 module do on other PowerShell versions for you? Like, Windows PowerShell v5.1, or on PowerShell Core v6.*? Those are the PS versions on which I tried to reproduce this error so far, and things are just working.

Let us know

Poolshark314 commented 5 years ago

I just did a fresh install of PowerCLI and DRSRule on a separate Windows Server 2019 server using Install-Module for both and it seems to be working fine now. I think it may have been issue with upgrading from previous versions of both PowerCLI and DRSRule. It is still not working on that Server 2012 R2 server but I can migrate my scheduled tasks over to the new one so if you prefer, we can close this issue.

mtboren commented 5 years ago

Hello, @Poolshark314 -

Thanks for the follow-up. Interesting. And, I wonder how the PowerShell version on that Win2012R2 server is playing in this situation, if at all (if it is anything to do w/ PS v5.0).

Are you in a position where you can try WMF 5.1 on that 2012R2 server? I wouldn't generally think, "PS v5.0 -- could be a problem!", but, in just now checking the supported versions of the WMF, I saw that WMF 5.0 is out of support (per this Microsoft Docs item). So, if we do spend time pursuing this, we probably want to use our time on supported versions of things.

Either way, thanks for the info. I'll leave this issue open for now, in case we can spend some more time researching.

Cheers,

Matt

Poolshark314 commented 5 years ago

Sorry I looked and the 2012R2 server is actually running 5.1. Oversight on my part.

Poolshark314 commented 5 years ago

I spoke too soon. This actually doesn't work on the Server 2019 VM either. I moved the script that I was using on the 2012 R2 server over and it is the Get-DrsVMGroup command that is failing still with the same error as above. The Get-DrsClusterGroup command returns results fine and I can see the preview of the VMs that are members of each group.

akers8806 commented 4 years ago

I am having this same exact issue. When trying to run my script as a scheduled task on a 2016 server, i get:

New-Object : Cannot find type [DRSRule_VMHostGroup]: verify that the assembly containing this type is loaded.

PS C:\Windows\system32> get-module VMWare.PowerCLI

ModuleType Version    Name                                ExportedCommands                                                                                                                                           
---------- -------    ----                                ----------------                                                                                                                                           
Manifest   11.5.0.... VMWare.PowerCLI                                                                                                                                                                                
PS C:\Windows\system32> get-module drsrule

ModuleType Version    Name                                ExportedCommands                                                                                                                                           
---------- -------    ----                                ----------------                                                                                                                                           
Script     2.0.0      DRSRule                             {Export-DrsRule, Get-DrsVMGroup, Get-DrsVMHostGroup, Get-DrsVMToVMHostRule...} 

no issues when running directly from a powershell session.

lussierd16 commented 4 years ago

I had this same issue with powershell version 5.1, vmware.powercli version 11.5, DRSRule version 2.0. All the versions were right but I had to add this to the top of set_spla_drs_rules.ps1:

using module DRSRule

That fixed it.

xmartinj commented 4 years ago

I had an Import-Module DRSRule that didn't work.

I added "using module DRSRule" at the top with Import-Module still in the script and that didn't work.

I removed the "Import-Module" and left the "using module" and now it works.

mtboren commented 4 years ago

Seems like for those hitting issue when using the DRSRule module within a script are able to work around / solve the issue via a using statement instead of using the Import-Module statement to which we are all accustomed. This need is seemingly due to the fact that the DRSRule module defines classes. From the Import-Module help at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module:

If the module includes class and enum definitions, use using module at the beginning of your script. This import the scripts, including the class and enum definitions

Thanks @lussierd16 and @xmartinj for letting us know about your successes via using.