Created
November 22, 2016 21:26
-
-
Save 1RedOne/f69cc02763dbd5cf2077b04939d23914 to your computer and use it in GitHub Desktop.
VM Class example
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
#New-VM -Name "new 2" -MemoryStartupBytes 1GB | |
#-NewVHDPath d:\vhd\base.vhdx | |
Class VM | |
{ | |
[string]$Name | |
[string]$MemoryStartupBytes = 4 | |
[string]$VHDPath = 'c:\temp\' | |
[string]$VHDSize = 30 | |
Build () { | |
New-vm -Name $this.Name ` | |
-MemoryStartupBytes $this.MemoryStartupBytes ` | |
-NewVHDPath $this.VHDPath ` | |
-NewVHDSizeBytes $this.VHDSize -WhatIf | |
} | |
VM ([string]$name,[string]$MemoryStartupBytes ,[string]$VHDPath, [string]$VHDSize) | |
{$this.Name = $Name | |
$this.MemoryStartupBytes= $MemoryStartupBytes | |
$this.VHDPath = $VHDPath | |
$this.VHDSize = $VHDSize | |
} | |
} | |
#Instantiate a new instance of this class | |
$VM=[VM]::new('ClassVM',4096,'c:\temp\ClassVM.vhdx',30) | |
#Call the instance method to create a new VM | |
$vm.Build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment