I'm using the below script to get Promiscuous Mode then I set it to desired value, I need assistance in order to create a script that can:
$ESXs=get-vmhost
$ESXs | % {
$esx=$_ ; $switchs= Get-VirtualSwitch $esx
$switchs | % { $switch=$_ ; $sec=Get-SecurityPolicy $switch ; `
"$esx $switch $($sec.AllowPromiscuous) $($sec.ForgedTransmits) $($sec.MacChanges)" >> $file_before}
}
$ESXs | Get-VirtualSwitch | Get-SecurityPolicy | Set-SecurityPolicy `
-MacChanges $false `
-ForgedTransmits $false `
-AllowPromiscuous $false
$ESXs | % {
$esx=$_ ; $switchs= Get-VirtualSwitch $esx
$switchs | % { $switch=$_ ; $sec=Get-SecurityPolicy $switch ; `
"$esx $switch $($sec.AllowPromiscuous) $($sec.ForgedTransmits) $($sec.MacChanges)" >> $file_after }
}
Try something like this.
It works for VSS and VDS.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I got the below error message:
Get-SecurityPolicy : Cannot validate argument on parameter 'VirtualSwitch'. The argument is null. Provide a valid value for the argument, and then try running the
command again.
At X:\Test.ps1:576 char:39
+ Get-SecurityPolicy -VirtualSwitch $switch -PipelineVariable polic ...
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-SecurityPolicy], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetSecurityPolicy
Get-SecurityPolicy : Cannot validate argument on parameter 'VirtualSwitch'. The argument is null. Provide a valid value for the argument, and then try running the
command again.
At X:\Test.ps1:576 char:39
+ Get-SecurityPolicy -VirtualSwitch $switch -PipelineVariable polic ...
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-SecurityPolicy], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetSecurityPolicy
There was some code in there that I forgot to remove.
Code is updated
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks there's no error now but both csv file are empty
There was another typo in the code, which I just corrected.
If none of the switches has an incorrect setting, the CSV files will be empty.
That is exactly what your request seems to ask for.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference