Invoke.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#<#
# This script expects to be passed a psobject with all the needed properties
# in order to invoke a 'VirtualMachine' DSC resource.
##>
#param(
# $Options,
# [bool]$Direct = $true
#)

#$type = $Options.Resource.split(':')[1]

#switch ($type) {
# 'vm' {
# $provJson = ''
# if ($null -ne $Options.options.provisioners) {
# $provJson = ConvertTo-Json -InputObject $Options.options.provisioners -Depth 999
# }

# if ($null -eq $provJson) {
# $provJson = ''
# }

# if ($Direct) {
# if ($null -eq $Options.options.Ensure) {
# $Options.Options | Add-Member -MemberType NoteProperty -Name Ensure -Value 'Present' -Force
# }
# $hash = @{
# Ensure = $Options.options.Ensure.ToString()
# Name = $Options.Name
# PowerOn = $Options.options.PowerOn
# vCenter = $Options.options.vCenter
# VMTemplate = $Options.options.VMTemplate
# TotalvCPU = $Options.options.TotalvCPU
# CoresPerSocket = $Options.options.CoresPerSocket
# vRAM = $Options.options.vRAM
# Datacenter = $Options.options.Datacenter
# Cluster = $Options.options.Cluster
# InitialDatastore = $Options.options.InitialDatastore
# Disks = ConvertTo-Json -InputObject $Options.options.disks -Depth 999
# CustomizationSpec = $Options.options.CustomizationSpec
# Networks = ConvertTo-Json -InputObject $Options.options.networks -Depth 999
# Provisioners = $provJson
# }

# # Credentials may be specified in line. Test for that
# if ($Options.Options.vCenterCredentials -is [pscredential]) {
# $hash.vCenterCredentials = $Options.Options.vCenterCredentials
# }
# if ($Options.Options.GuestCredentials -is [pscredential]) {
# $hash.GuestCredentials = $Options.Options.GuestCredentials
# }
# if ($Options.Options.DomainJoinCredentials -is [pscredential]) {
# $hash.DomainJoinCredentials = $Options.Options.DomainJoinCredentials
# }
# if ($Options.Options.IPAMCredentials -is [pscredential]) {
# $hash.IPAMCredentials = $Options.Options.IPAMCredentials
# }
# if ($Options.Options.IPAMFqdn -is [string]) {
# $hash.IPAMFqdn = $Options.Options.IPAMFqdn
# }

# # Credentials may be listed under secrets. Test for that
# if ($Options.options.secrets.vCenter) {
# $hash.vCenterCredentials = $Options.options.secrets.vCenter.credential
# }
# if ($Options.options.secrets.guest) {
# $hash.GuestCredentials = $Options.options.secrets.guest.credential
# }
# if ($Options.options.secrets.domainJoin) {
# $hash.DomainJoinCredentials = $Options.options.secrets.domainJoin.credential
# }
# if ($Options.options.secrets.ipam) {
# $hash.IPAMCredentials = $Options.options.secrets.ipam.credential
# $hash.IPAMFqdn = $Options.options.secrets.ipam.options.fqdn
# }

# # If the guest credential doesn't have a domain or computer name
# # as part of the username, make sure to add it
# if ($hash.GuestCredentials.UserName -notlike '*\*') {
# $userName = "$($Options.Name)`\$($hash.GuestCredentials.UserName)"
# $cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($userName, $hash.GuestCredentials.Password)
# $hash.GuestCredentials = $cred
# }

# return $hash
# } else {
# Write-Verbose -Message 'Returning invoke string for resource: VM'

# $cmd =
#@'
# $provJson = [string]::empty
# if ($null -ne $_.options.provisioners) {
# $provJson = ConvertTo-Json -InputObject $_.options.provisioners -Depth 999
# }

# if ($null -eq $provJson) {
# $provJson = [string]::empty
# }
# VM $_.Name {
# Ensure = $_.options.Ensure
# Name = $_.Name
# PowerOnAfterCreation = $_.options.PowerOnAfterCreation
# vCenter = $_.options.vCenter
# vCenterCredentials = $_.options.secrets.vCenter.credential
# VMTemplate = $_.options.VMTemplate
# TotalvCPU = $_.options.TotalvCPU
# CoresPerSocket = $_.options.CoresPerSocket
# vRAM = $_.options.vRAM
# Datacenter = $_.options.Datacenter
# Cluster = $_.options.Cluster
# InitialDatastore = $_.options.InitialDatastore
# Disks = ConvertTo-Json -InputObject $_.options.disks
# CustomizationSpec = $_.options.CustomizationSpec
# GuestCredentials = $_.options.secrets.guest.credential
# IPAMCredentials = $_.options.secrets.ipam.credential
# IPAMFqdn = $_.options.secrets.ipam.options.fqdn
# DomainJoinCredentials = $_.options.secrets.domainJoin.credential
# Networks = ConvertTo-Json -InputObject $_.options.networks
# ChefRunlist = $_.options.ChefRunList
# Provisioners = $_
# }
#'@
# write-verbose $cmd
# return $cmd
# }
# }
#}