Last active
January 13, 2017 23:48
-
-
Save brianbunke/13e32ae67a9232d2224601e937eebba7 to your computer and use it in GitHub Desktop.
Trying to figure out how to mock a PowerCLI VM object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code doesn't work. :) Soliciting feedback | |
# Just started duplicating info from here: | |
# (Get-VM 'ExampleVM') | gm | Where MemberType -eq 'Property' | Select Name,Definition | |
$r = "c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk\VMware.VimAutomation.Sdk.Types.dll", | |
"c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.ViCore.Types.dll" | |
Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
using VMware.VimAutomation.ViCore.Types.V1; | |
using VMware.VimAutomation.ViCore.Types.V1.Inventory; | |
using VMware.VimAutomation.ViCore.Types.V1.Cluster; | |
using VMware.VimAutomation.ViCore.Types.V1.VM; | |
using VMware.VimAutomation.ViCore.Types.V1.VM.Guest; | |
namespace Mocks | |
{ | |
public class MockVM : VirtualMachine | |
{ | |
public int CoresPerSocket { get; set; } | |
public string CustomFields { get; set; } | |
public string[] DatastoreIdList { get; set; } | |
public DrsAutomationLevel DrsAutomationLevel { get; set; } | |
public object ExtensionData { get; set; } | |
public Folder Folder { get; set; } | |
public string FolderId { get; set; } | |
public VMGuest Guest { get; set; } | |
public string GuestId { get; set; } | |
public HAIsolationResponse HAIsolationResponse { get; set; } | |
public HARestartPriority HARestartPriority { get; set; } | |
public string Id { get; set; } | |
public decimal MemoryGB { get; set; } | |
public decimal MemoryMB { get; set; } | |
public string Name { get; set; } | |
public string Notes { get; set; } | |
public int NumCpu { get; set; } | |
public string PersistentId { get; set; } | |
public PowerState PowerState { get; set; } | |
public decimal ProvisionedSpaceGB { get; set; } | |
public ResourcePool ResourcePool { get; set; } | |
public string ResourcePoolId { get; set; } | |
public string Uid { get; set; } | |
public decimal UsedSpaceGB { get; set; } | |
public VApp VApp { get; set; } | |
public VMVersion Version { get; set; } | |
public VMHost VMHost { get; set; } | |
public string VMHostId { get; set; } | |
public VMResourceConfiguration VMResourceConfiguration { get; set; } | |
public VMSwapfilePolicy VMSwapfilePolicy { get; set; } | |
} | |
}" | |
<# | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.HARestartPriority'. | |
'Mocks.MockVM.HARestartPriority' cannot implement | |
'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.HARestartPriority' because it does not have the | |
matching return type of 'VMware.VimAutomation.ViCore.Types.V1.Cluster.HARestartPriority?'. | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb....tartPriority?'.:CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.HAIsolationResponse'. | |
'Mocks.MockVM.HAIsolationResponse' cannot implement | |
'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.HAIsolationResponse' because it does not have the | |
matching return type of 'VMware.VimAutomation.ViCore.Types.V1.Cluster.HAIsolationResponse?'. | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb....tionResponse?'.:CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.DrsAutomationLevel'. | |
'Mocks.MockVM.DrsAutomationLevel' cannot implement | |
'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.DrsAutomationLevel' because it does not have the | |
matching return type of 'VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsAutomationLevel?'. | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb....omationLevel?'.:CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.VMSwapfilePolicy'. | |
'Mocks.MockVM.VMSwapfilePolicy' cannot implement | |
'VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine.VMSwapfilePolicy' because it does not have the | |
matching return type of 'VMware.VimAutomation.ViCore.Types.V1.VMSwapfilePolicy?'. | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb....apfilePolicy?'.:CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.ExtensionData.LockUpdates()' | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb.....LockUpdates()':CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : 'Mocks.MockVM' does not implement | |
interface member 'VMware.VimAutomation.ViCore.Types.V1.ExtensionData.UnlockUpdates()' | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(9) : { | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(10) : >>> public class MockVM : VirtualMachine | |
c:\Users\bb\AppData\Local\Temp\hun0er5x.0.cs(11) : { | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (c:\Users\bb....nlockUpdates()':CompilerError) [Add-Type], Exception | |
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand | |
Add-Type : Cannot add type. Compilation errors occurred. | |
At line:1 char:5 | |
+ Add-Type -ReferencedAssemblies $r -TypeDefinition " | |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException | |
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment