-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateVM.ps1
66 lines (49 loc) · 1.7 KB
/
CreateVM.ps1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Create_VM.ps1 - written in 2015 by wadejm
#
# How to run: This script should be called by a controller script, but could be run if the proper variables are passed in the correct order below.
# What is needed to run: Variables in the correct order with valid information
# vcenter credentials
#
# ChangeLog:
# Date - Changer What was changed
# 20151015 - wadejm Initial Conception
#
#
#
# Pass varibles to this script in this order
#
# $FOLDER : Folder to store tmp VMs
# $VCENTER : vcenter server
# $DATASTORE : datastore for tmp VMs
# $NETWORK : Network to use
# $TEMPLATE : Template to clone
# $VMhost : Resource pool to put VMs
# $HN : Hostname of the new system
param(
[Parameter(Mandatory=$true)]
[String]$FOLDER,
[String]$VCENTER,
[String]$DATASTORE,
[String]$NETWORK,
[String]$TEMPLATE,
[String]$VMhost,
[String]$HN
)
start-transcript -OutputDirectory "d:\scripts\log\"
Add-PSSnapin vm*
#New-VICredentialStoreItem -Host VCENTER -User "USERNAME" -Password "PASSWORD"
Connect-VIServer $VCENTER
write-host "Hostname : $HN"
write-host "Folder : $FOLDER"
write-host "Vcenter : $VCENTER"
write-host "Datastore : $DATASTORE"
write-host "NETWORK : $NETWORK"
write-host "TEMPLATE : $TEMPLATE"
write-host "VMhost : $VMhost"
New-VM -vmhost $VMhost -name $HN -location $($FOLDER) -template $TEMPLATE -datastore $DATASTORE
Set-annotation -entity $HN -CustomAttribute "Contact" -Value "Open"
Set-Annotation -entity $HN -CustomAttribute "Build Date" -value $(Get-Date)
Get-VM $HN | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup $NETWORK -Confirm:$false
New-HardDisk -VM $HN -CapacityGB 100 -StorageFormat thin
Stop-Transcript