/w21froster

i post stuff

New Blog



I have been thinking about creating a blog for some time and I finally got around to it. This content is hosted on a NodeJS platform called Hexo which serves static content. (Eg. I update it by writing pseudo-code and pushing updates to Github. Speaking of Github, they allow you to host a website as a subdomain for free to do whatever you like. (As long as it is tasteful…) You can even use it for monetary gains. At this time I have chosen not to do ads.

Anyways.

Here is a snippet of PowerShell code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Import PowerCLI Modules
Get-Module –ListAvailable VM* | Import-Module
# Define Variables for Reference Image and Environment
$HostName = "PO-INFR08.panoramaortho.com"
$REFVM = "CAPTURE01"
$RAM = 4
$DISK = 200
$NETWORK = "Bridged"
$DATASTORE = ""
$ISO = "[vmware-isos] MS WorkStation OS\Win 7\LiteTouchPE_x64.iso"
$SMTPServer = ""
$VMSearch = $REFVM
$VMHost = ""
$FROM = "wf_admin@testdomain.com"
$TO = "myemail"
# Connect to VSphere
Connect-VIServer $HostName
#Remove any existing VM's with name matching in $REFVM
If ((Get-VM -Name $REFVM -ErrorAction SilentlyContinue).PowerState -eq "PoweredOn") {
Send-MailMessage -SmtpServer $SMTPServer -From $FROM -To $TO `
-Subject "Reference Image creation previous attempt failed" `
-Body "Something went wrong with the last reference image capture process.`
Please connect to $REFVM on $HostName and solve any issues."
Exit
}
Else {
Remove-VM -VM $REFVM -Server $HostName -DeleteFromDisk -Confirm:$false
}
#Create a new VM with specified configuration
New-VM -Name $REFVM -Datastore $DATASTORE -DiskGB $DISK -DiskStorageFormat Thin -MemoryGB $RAM `
-GuestId windows7_64Guest -NumCpu 2 -VMHost $VMHost
New-CDDrive -VM $REFVM -IsoPath $ISO -StartConnected:$true -Confirm:$false
Get-NetworkAdapter -VM $REFVM | Set-NetworkAdapter -StartConnected:$true -NetworkName "VM Network" -Confirm:$false
#Start VM
Start-VM -VM $REFVM -Confirm:$false
#Email informing that the reference image creation has begun as scheduled
Send-MailMessage -SmtpServer $SMTPServer -From $FROM -To $TO `
-Subject "Reference Image creation has begun" `
-Body "Please monitor for an email in about 2-3 hours to signal that the image has been created."
⬅️ Go back