$newVSSPolicy = @{
VirtualSwitchPolicy = $null
AllowPromiscuous = $false
MacChanges = $false
ForgedTransmits = $false
Confirm = $false
}
$newVDSPolicy = @{
Policy = $null
AllowPromiscuous = $false
MacChanges = $false
ForgedTransmits = $false
Confirm = $false
}
$reportBefore = @()
$reportAfter = @()
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
# VSS
Get-VirtualSwitch -Standard -VMHost $esx -PipelineVariable vss |
Get-SecurityPolicy -PipelineVariable policy |
where{$_.AllowPromicious -or $_.MacChanges -or $_.ForgedTransmits} |
ForEach-Object -Process {
$reportBefore += New-Object -TypeName PSObject -Property @{
VMHost = $esx.Name
Switch = $vss.Name
AllowPromicious = $policy.AllowPromiscuous
MacChanges = $policy.MacChanges
ForgedTransmits = $policy.ForgedTransmits
}
$newVSSPolicy.VirtualSwitchPolicy = $policy
Set-SecurityPolicy @newVSSPolicy
Get-SecurityPolicy -VirtualSwitch $vss |
ForEach-Object -Process {
$reportAfter += New-Object -TypeName PSObject -Property @{
VMHost = $esx.Name
Switch = $vss.Name
AllowPromicious = $_.AllowPromiscuous
MacChanges = $_.MacChanges
ForgedTransmits = $_.ForgedTransmits
}
}
}
# VDS
Get-VDSwitch -VMHost $esx -PipelineVariable vds |
Get-VDSecurityPolicy -PipelineVariable policy |
where{$_.AllowPromicious -or $_.MacChanges -or $_.ForgedTransmits} |
ForEach-Object -Process {
$reportBefore += New-Object -TypeName PSObject -Property @{
VMHost = $esx.Name
Switch = $vds.Name
AllowPromicious = $policy.AllowPromiscuous
MacChanges = $policy.MacChanges
ForgedTransmits = $policy.ForgedTransmits
}
$newVDSPolicy.Policy = $policy
Set-VDSecurityPolicy @$newVDSPolicy
Get-VDSecurityPolicy -VDSwitch $vds |
ForEach-Object -Process {
$reportAfter += New-Object -TypeName PSObject -Property @{
VMHost = $esx.Name
Switch = $vds.Name
AllowPromicious = $_.AllowPromiscuous
MacChanges = $_.MacChanges
ForgedTransmits = $_.ForgedTransmits
}
}
}
}
$reportBefore | Export-Csv -Path .\report-before.csv -NoTypeInformation -UseCulture
$reportAfter | Export-Csv -Path .\report-after.csv -NoTypeInformation -UseCulture