Hi there. I’ll try to explain as best as I can the problem I am facing. Please let me know if I’ve omitted anything that could help you understand the problem I am trying to solve.
So I’m working with an object that is a collection of Amazon.EC2.Model.SecurityGroup objects. This object is created when I use the Get-EC2SecurityGroup powershell cmdlet. So the end goal is to run something like this $securitygroups = Get-EC2SecurityGroup -filter $VPC.id
and get back all the security groups I want to report on.
Now each security group object in this collection of Amazon.EC2.Model.SecurityGroup objects has a collection of Amazon.EC2.Model.IpPermission objects that represent the inbound allowed rules of the security group. This collection of objects contain a string property called IpProtocol. If “All Traffic” is allowed to the security group, the $securitygroups.IpPermission.IpProtocol string value is represented as “-1”. I want to change this value of “-1” to “All Traffic” so when I pipe the object $securitygroups to Export-Excel cmdlet I get cells that contain the end value I want in the report.
How can I take my $securitygroups variable and send it over the pipeline so that what exits the pipeline is the same collection of objects that entered the pipeline but the string values inside of $securitygroups.IpPermissions.IpProtocols is set to “All Traffic” when previously that value was “-1”? I don’t want to edit the string if the $securitygroups.IpPermissions.IpProtocols is “udp” or “tcp” etc.
I know I could accomplish this with Add-Member by adding a new noteproperty and defining that with an if else statement. I just don’t know how I can accomplish this in a one liner with the pipeline.
submitted by /u/warning1
[link] [comments]
The post How can I manipulate strings within an existing object? appeared first on How to Code .NET.