Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Created November 22, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1RedOne/f69cc02763dbd5cf2077b04939d23914 to your computer and use it in GitHub Desktop.
Save 1RedOne/f69cc02763dbd5cf2077b04939d23914 to your computer and use it in GitHub Desktop.
VM Class example
#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