Created
January 15, 2017 18:41
-
-
Save brianbunke/b31765f69781112f4b2ddfa9f949599e to your computer and use it in GitHub Desktop.
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
# Barely working :D | |
# Follows my previous Gist, https://gist.github.com/brianbunke/13e32ae67a9232d2224601e937eebba7 | |
# http://theshellnut.com/exploring-powercli-types/ | |
# http://stackoverflow.com/questions/14141043/resolving-an-ambiguous-reference | |
ipmo VMware.VimAutomation.Core | |
$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", | |
"c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core\VMware.Vim.dll" | |
Add-Type -ReferencedAssemblies $r -Verbose -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; | |
using VirtualMachine = VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine; | |
using VimVirtualMachine = VMware.Vim.VirtualMachine; | |
using InvFolder = VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder; | |
using InvResourcePool = VMware.VimAutomation.ViCore.Types.V1.Inventory.ResourcePool; | |
namespace Mocks | |
{ | |
public class MockObject | |
{ | |
public static object Testing { get { return 1; } } | |
} | |
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 VimVirtualMachine ExtensionData { get; set; } | |
public InvFolder 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 InvResourcePool 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; } | |
object ExtensionData.ExtensionData { get { return MockObject.Testing; } } | |
public void LockUpdates() { } | |
public void UnlockUpdates() { } | |
} | |
}" | |
$MockVM = New-Object Mocks.MockVM | |
$MockVM -is [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine] | |
$MockVM.GetType() | |
$MockVM.Name = 'TestVMName' | |
$MockVM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment