-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetItems.ps1
More file actions
246 lines (206 loc) · 11.7 KB
/
Copy pathGetItems.ps1
File metadata and controls
246 lines (206 loc) · 11.7 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
function Get-VNVDTrafficFilterPolicyConfig {
<# .Description
Get the VDTrafficFilterPolicy configuration for the given VDPortgroup(s) from VDSwitch(es)
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig
Get the TrafficFilter policy config for the given VDPortgroup
.Outputs
VNVDTrafficFilterPolicyConfig with properties with at least VMware.Vim.DvsTrafficFilterConfig and VMware.Vim.DistributedVirtualPortgroup for the TrafficFilter policy config
#>
[CmdletBinding()]
[OutputType([VNVDTrafficFilterPolicyConfig])]
param (
## The virtual distributed portgroup for which to get the traffic filtering and marking policy configuration
[parameter(Mandatory=$true, ValueFromPipeline=$true)][VMware.VimAutomation.Vds.Types.V1.VmwareVDPortgroup[]]$VDPortgroup
) ## end param
process {
$VDPortgroup | Foreach-Object {
$oThisVDPG = $_
New-Object -Type VNVDTrafficFilterPolicyConfig -Property @{
TrafficFilterPolicyConfig = $oThisVDPG.ExtensionData.Config.DefaultPortConfig.FilterPolicy.FilterConfig
VDPortgroupView = $oThisVDPG.ExtensionData
} ## end new-object
} ## end foreach-object
} ## end process
} ## end fn
function Get-VNVDTrafficRuleSet {
<# .Description
Get the DvsTrafficRuleset for the given VDTrafficFilterPolicy configuration from VDPortgroup(s), or from VDPortgroup(s) directly
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig | Get-VNVDTrafficRuleSet
Get the traffic ruleset from the TrafficFilterPolicyConfig object of a given vDPG. Can also get the ruleset from just the vDPG, but this "from TrafficFilterPolicyConfig" method is to help show the relationship between the vDPG, the TrafficFilterPolicyConfig, and the TrafficRuleset
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficRuleSet
Get the traffic ruleset directly from the given vDPG
.Outputs
VNVDTrafficRuleSet with properties with at least VMware.Vim.DvsTrafficRuleset and VMware.Vim.DistributedVirtualPortgroup for the Traffic rule set
#>
[CmdletBinding(DefaultParameterSetName="ByTrafficFilterPolicyConfig")]
[OutputType([VNVDTrafficRuleSet])]
param (
## The traffic filter policy config of the virtual distributed portgroup for which to get the traffic ruleset
[parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName="ByTrafficFilterPolicyConfig")][VNVDTrafficFilterPolicyConfig[]]$TrafficFilterPolicyConfig,
## The virtual distributed portgroup for which to get the traffic ruleset
[parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName="ByVDPortGroup")][VMware.VimAutomation.Vds.Types.V1.VmwareVDPortgroup[]]$VDPortgroup,
## The View object for the virtual distributed portgroup for which to get the traffic ruleset
[parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName="ByVDPortGroupView")][VMware.Vim.DistributedVirtualPortgroup[]]$VDPortgroupView
) ## end param
process {
Switch ($PSCmdlet.ParameterSetName) {
"ByTrafficFilterPolicyConfig" {
$TrafficFilterPolicyConfig | Foreach-Object {
New-Object -Type VNVDTrafficRuleSet -Property @{
TrafficRuleset = $_.TrafficFilterPolicyConfig.TrafficRuleset
TrafficRulesetEnabled = $_.TrafficFilterPolicyConfig.TrafficRuleset.Enabled
NumTrafficRule = ($_.TrafficFilterPolicyConfig.TrafficRuleset.Rules | Measure-Object).Count
VDPortgroupView = $_.VDPortgroupView
} ## end new-object
} ## end foreach-object
break
} ## end case
{"ByVDPortGroup", "ByVDPortGroupView" -contains $_} {
## get the View objects over which to iterate (either the .ExtensionData)
$(if ($PSCmdlet.ParameterSetName -eq "ByVDPortGroup") {$VDPortgroup | Foreach-Object {$_.ExtensionData}} else {$VDPortgroupView}) | Foreach-Object {
## update the ViewData for this vDPG, just to be sure that all is current
$oThisVDPGView = $_; $oThisVDPGView.UpdateViewData("Config")
$oThisVDPGView.Config.DefaultPortConfig.FilterPolicy.FilterConfig | Foreach-Object {
New-Object -Type VNVDTrafficRuleSet -Property @{
TrafficRuleset = $_.TrafficRuleset
TrafficRulesetEnabled = $_.TrafficRuleset.Enabled
NumTrafficRule = ($_.TrafficRuleset.Rules | Measure-Object).Count
VDPortgroupView = $oThisVDPGView
} ## end new-object
} ## end foreach-object
} ## end foreach-object
} ## end case
} ## end switch
} ## end process
} ## end function
function Get-VNVDTrafficRule {
<# .Description
Get the VDTrafficRule for the TrafficRuleset from the given VDTrafficFilterPolicy configuration from VDPortgroup(s)
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig | Get-VNVDTrafficRuleSet | Get-VNVDTrafficRule
Get the traffic rules from the TrafficeRuleset, which was gotten from the vDPG's TrafficFilterPolicyConfig
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig | Get-VNVDTrafficRuleSet | Get-VNVDTrafficRule myTestRule*
Get traffic rules whose name is like "myTestRule*"
.Outputs
VNVDTrafficRule with at least properties for VMware.Vim.DvsTrafficRule and VMware.Vim.DistributedVirtualPortgroup for the Traffic rule set rule
#>
[CmdletBinding(DefaultParameterSetName="Default")]
[OutputType([VNVDTrafficRule])]
param (
## The name(s) of the Traffic Rule(s) to return (accepts wildcards). If -Name or -LiteralName not specified, will return all Traffic Rules for the given traffic rule set
[parameter(ParameterSetName="ByName", Position=0)][String[]]$Name,
## The name(s) of the Traffic Rule(s) to return (exact match only, no wildcarding employed). If -Name or -LiteralName not specified, will return all Traffic Rules for the given traffic rule set
[parameter(ParameterSetName="ByLiteralName")][String[]]$LiteralName,
## The traffic ruleset from the traffic filter policy of the virtual distributed portgroup for which to get the traffic rule(s)
[parameter(Mandatory=$true, ValueFromPipeline=$true)][VNVDTrafficRuleSet[]]$TrafficRuleset
) ## end param
process {
$TrafficRuleset | Foreach-Object {
$oThisTrafficRuleset = $_
$arrRulesOfInterest =
## if -Name was passed, only return rules whose descriptions are like the given name value(s)
if ($PSBoundParameters.ContainsKey("Name")) {$_.TrafficRuleset.Rules | Where-Object {$oThisDescription = $_.Description; ($Name | Foreach-Object {$oThisDescription -like $_}) -contains $true}}
elseif ($PSBoundParameters.ContainsKey("LiteralName")) {$_.TrafficRuleset.Rules | Where-Object {$LiteralName -contains $_.Description}}
else {$_.TrafficRuleset.Rules | Where-Object {$null -ne $_}}
$arrRulesOfInterest | Foreach-Object {
$oThisTrafficRule = $_
New-Object -Type VNVDTrafficRule -Property @{
Name = $oThisTrafficRule.Description
TrafficRule = $oThisTrafficRule
VDPortgroupView = $oThisTrafficRuleset.VDPortgroupView
VNVDTrafficRuleSet = $oThisTrafficRuleset
} ## end new-object
} ## end foreach-object
} ## end foreach-object
} ## end process
} ## end function
function Get-VNVDTrafficRuleQualifier {
<# .Description
Get the VDTrafficRule Qualifier for the TrafficRule from the given VDTrafficFilterPolicy configuration from VDPortgroup(s)
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig | Get-VNVDTrafficRule | Get-VNVDTrafficRuleQualifier
Get the traffic rules qualifiers from the traffic rules from the TrafficeRuleset property of the TrafficFilterPolicyConfig
.Outputs
VMware.Vim.DvsNetworkRuleQualifier
#>
[CmdletBinding()]
[OutputType([VMware.Vim.DvsNetworkRuleQualifier])]
param (
## The traffic ruleset rule from the traffic filter policy of the virtual distributed portgroup for which to get the traffic rule qualifier(s)
[parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName="ByTrafficRule")][VNVDTrafficRule[]]$TrafficRule
) ## end param
process {
$TrafficRule | Foreach-Object {
$_.TrafficRule.Qualifier | Where-Object {$null -ne $_} | Foreach-Object {
## get the qualifier TypeName short name (like, if TypeName is "VMware.Vim.DvsIpNetworkRuleQualifier", this will be "DvsIpNetworkRuleQualifier")
$strQualifierTypeShortname = ($_ | Get-Member | Select-Object -First 1).TypeName.Split(".") | Select-Object -Last 1
## the properties to select for this Qualifier object
$arrPropertyForSelectObject = @{n="QualifierType"; e={$strQualifierTypeShortname}}, "*"
## if the Qualifier object is of type VMware.Vim.DvsSystemTrafficNetworkRuleQualifier, essentially "expand" the TypeOfSystemTraffic.Value property to be one level up in the return object
if ($strQualifierTypeShortname -eq "DvsSystemTrafficNetworkRuleQualifier") {$arrPropertyForSelectObject += @{n="TypeOfSystemTraffic_Name"; e={$_.TypeOfSystemTraffic.Value}}}
$_ | Select-Object -Property $arrPropertyForSelectObject
} ## end foreach-object
} ## end foreach-object
} ## end process
} ## end function
function Get-VNVDTrafficRuleAction {
<# .Description
Get the VDTrafficRule Action for the TrafficRule from the given VDTrafficFilterPolicy configuration from VDPortgroup(s)
.Example
Get-VDSwitch -Name myVDSw0 | Get-VDPortGroup -Name myVDPG0 | Get-VNVDTrafficFilterPolicyConfig | Get-VNVDTrafficRule | Get-VNVDTrafficRuleAction
Get the traffic rules action from the traffic rules from the TrafficeRuleset property of the TrafficFilterPolicyConfig
.Outputs
VMware.Vim.DvsNetworkRuleAction
#>
[CmdletBinding()]
[OutputType([VMware.Vim.DvsNetworkRuleAction])]
param (
## The traffic ruleset rule from the traffic filter policy of the virtual distributed portgroup for which to get the traffic rule action
[parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName="ByTrafficRule")][VNVDTrafficRule[]]$TrafficRule
) ## end param
process {
$TrafficRule | Foreach-Object {
$_.TrafficRule.Action
} ## end foreach-object
} ## end process
} ## end function
function Get-VNVSwitchByVMHostNetworkAdapter {
<# .Description
Get the virtual switch (standard or distributed) with which the given VMHostNetworkAdapter physical NIC is associated, if any.
.Example
Get-VMHost myVMHost0.dom.com | Get-VMHostNetworkAdapter -Name vmnic2 | Get-VNVSwitchByVMHostNetworkAdapter
Get the vSwitch with which VMNIC2 on myVMHost0.dom.com is associated
.Outputs
Virtual standard- or distributed switch with which given physical VMHost network adapter is associated, if any
#>
[CmdletBinding()]
param(
## The VMHostNetworkAdapter (physical NIC) for which to get the vSwitch
[parameter(Mandatory=$true, ValueFromPipeline=$true)][VMware.VimAutomation.Types.Host.NIC.PhysicalNic[]]$VMHostNetworkAdapter
) ## end param
process {
$VMHostNetworkAdapter | Foreach-Object {
$oThisVMHostNetworkAdapter = $_
if ($oAssociatedVSwitch = $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.Vswitch, $oThisVMHostNetworkAdapter.VMHost.ExtensionData.Config.Network.ProxySwitch | Foreach-Object {$_} | Where-Object {$_.Pnic -contains $oThisVMHostNetworkAdapter.Id}) {
switch ($oAssociatedVSwitch) {
## vSS
{$_ -is [VMware.Vim.HostVirtualSwitch]} {
$oThisVMHostNetworkAdapter.VMHost | Get-VirtualSwitch -Standard -Name $oAssociatedVSwitch.Name
break
} ## end case
## vDSwitch
{$_ -is [VMware.Vim.HostProxySwitch]} {
$oThisVMHostNetworkAdapter.VMHost | Get-VDSwitch -Name $oAssociatedVSwitch.DvsName
break
} ## end case
default {Write-Warning "vSwitch not of expected type of either [VMware.Vim.HostVirtualSwitch] or [VMware.Vim.HostProxySwitch]. What kind of vSwitch is it? $_"}
} ## end switch
} ## end if
else {Write-Verbose "No vSwitch associated with VMNIC '$($oThisVMHostNetworkAdapter.Name)' found on VMHost '$($oThisVMHostNetworkAdapter.VMHost.Name)'"}
} ## end Foreach-Object
} ## end process
} ## end fn