Splatting with dot notation.

Welcome Forums General PowerShell Q&A Splatting with dot notation.

Viewing 9 reply threads
  • Author
    Posts
    • #242564
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,323
      Helping Hand
      Rank: Community Hero

      Hello there!

      I have some configuration as below…

      And I want to make use of splatting for two different cmdlets like this…

       

      But I don’t want to use any temporary variable in between…

      This works, but I am just wondering any other possible ways? I have tried the combinations as below, but still no luck…

       

      Any idea, please…?

       

      Thank you,

      Kiran P.

      • This topic was modified 2 months, 1 week ago by Kiran. Reason: Code Formatting
      • This topic was modified 2 months, 1 week ago by Kiran.
      • This topic was modified 2 months, 1 week ago by Kiran.
      • This topic was modified 2 months, 1 week ago by Kiran.
      • This topic was modified 2 months, 1 week ago by Kiran.
    • #242588
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero

      If the key is not unique, it would be ignored by the other functions\cmdlets assuming it’s using ValueFromPipelineByPropertyName:

      • This reply was modified 2 months, 1 week ago by Rob Simmers.
      • This reply was modified 2 months, 1 week ago by Rob Simmers.
    • #242597
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,323
      Helping Hand
      Rank: Community Hero

      What if I have $splat like this…

    • #242603
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero
    • #242627
      Senior Moderator
      Topics: 9
      Replies: 1311
      Points: 4,794
      Helping Hand
      Rank: Community Hero

      Good option would be to not to use splatting, but If you can modify the function to take values from pipeline, then a complex object would do the job.

      • This reply was modified 2 months, 1 week ago by kvprasoon. Reason: code formatting
      • #242684
        Moderator
        Topics: 5
        Replies: 237
        Points: 1,323
        Helping Hand
        Rank: Community Hero

        Thanks Prasoon! But still, I can’t add a new configuration/property since its an object.

    • #242672
      Participant
      Topics: 8
      Replies: 568
      Points: 2,171
      Helping Hand
      Rank: Community Hero

      Wow I did not know you could do this. It’s similar to a filter hashtable, without the cmdlet having that parameter.

      Very neat.

      • This reply was modified 2 months, 1 week ago by Doug Maurer.
    • #242693
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,323
      Helping Hand
      Rank: Community Hero

      Thanks Rob, even I have been searching but couldn’t be figured it out. Looks like there is no workaround for this.

    • #242696
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,323
      Helping Hand
      Rank: Community Hero

      Yes, it works like this…

      Thanks, Prasoon!

      • This reply was modified 2 months, 1 week ago by Kiran.
    • #243068
      Senior Moderator
      Topics: 9
      Replies: 1311
      Points: 4,794
      Helping Hand
      Rank: Community Hero

      You can elements add using Add-Member cmdlet

    • #243320
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,323
      Helping Hand
      Rank: Community Hero

      Thanks @kvprasson!

      Yeah, the concept is good, but it’s not suitable for my scenario, because some of the cmdlets don’t support ValueFromPipeline attribute properties, so I have to use splatting or passing the parameters directly. So I have to use an intermediate variable.

       

Viewing 9 reply threads
  • You must be logged in to reply to this topic.