I am trying to write a script which gets/sets the security policy for a specific port group on a specific host via a powercli connection to a vCenter. This does not seem to be possible as both commands seem unable to accept pipeline input so if I do a "Get-SecurityPolicy" for a specific Port Group it returns the settings for each and every standard port group with the same name present on ANY host in vCenter. I want to get/set the security policy for a specific port group on a specific switch on a specific host.
Is this possible? It is part of a build / config script so I do not want to have to disconnect from vCenter and connect directly to the host just to configure this one option and then reconnect back to the vCenter again.
Thanks
Since you didn't share any code, not sure how you are doing this, but the following works for me.
Get-VirtualPortGroup -Name 'MyPG' -VMHost MyEsx |
Get-SecurityPolicy |
Set-SecurityPolicy -ForgedTransmits $true
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have been trying to do this via "$vmhost | Get-VirtualPortGroup" which does not seem to work.
So I normally fire up the Powershell ISE and lookup the command option from the side toolbar, the "VMHost" option was not listed there.
I will give this method a try, thanks.
It depends what you have in $vmhost.
Is that an object returned by Get-VMHost or a String?
The latter will not work in this way.
Also,
Get-Module -Name VMware* -ListAvailable
check which PowerCLI version you are using.
You might benefit from an upgrade if you are using an older version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$vmhost was an object obtained from
$vmhost = Get-VMHost <FQDN of host>
This did not work.
Which PowerCLI version are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Version 12 I believe
What error did you get when you said "This did not work."
Can you show the code and the eventual error message?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$vmhost | Get-SecurityPolicy -VirtualPortGroup EPG-CORE-MGMT
Get-SecurityPolicy : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or
the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:11
+ $vmhost | Get-SecurityPolicy -VirtualPortGroup EPG-CORE-MGMT
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (<Hostname>:PSObject) [Get-SecurityPolicy], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetSecurityPolicy
Earlier you said you did
$vmhost | Get-VirtualPortGroup
now you say you do
$vmhost | Get-SecurityPolicy -VirtualPortGroup EPG-CORE-MGMT
which of course doesn't work since the Get-SecurityPolicy cmdlet does only take a VirtualPortgroup object over the pipeline, not a VMHost object.
Why don't you just use the code I gave at the beginning of this thread?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am going to try it but I do believe you when you say it works, the rest after that is just me answering your questions. I will report back if there are any problems.
