Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splatting a property #5227

Closed
JohnLBevan opened this issue Oct 25, 2017 · 3 comments
Closed

Splatting a property #5227

JohnLBevan opened this issue Oct 25, 2017 · 3 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.

Comments

@JohnLBevan
Copy link
Contributor

Summary

It would be helpful if we could splat using the property of a variable (i.e. where that property is itself a hashtable) to a command.

Code Example:

function Test-Demo {
    [CmdletBinding()]
    Param (
        [Parameter()]
        [string]$One
        ,
        [Parameter()]
        [string]$Two
    )
    "1 = $One"
    "2 = $Two"
}
$test = @{
    testInt = @{ 
        One = '1'
        Two = '2'
    }
    testString = @{
        One = 'One'
        Two = 'Two'
    }
}

#to splat a property, we first need to assign the property to a "top level" variable:
$t = $test.testString
Test-Demo @t 

#however it would be nice if we could instead do this:
Test-Demo @test.testString 

#or if that's not possible for some reason, maybe something like this:
Test-Demo ([splat]$test.testString) 

This could be particularly useful when dealing with config files. e.g. Our config holds database information (instance, catalog, credentials), and also sections with other properties specific to our functions. e.g.

$config = Get-MyScriptConfig -Path '.\Config.xml'
Invoke-Something @config.DatabaseConnectionInfo @config.Something
@IISResetMe
Copy link
Collaborator

Sounds like we need to revive PowerShell/PowerShell-RFC#6 - the RFC draft suggests generalized expression splatting, with syntax like:

Test-Demo @$test.testString

@iSazonov
Copy link
Collaborator

@JohnLBevan Can we close the Issue looking PowerShell/PowerShell-RFC#6 ?

@JohnLBevan
Copy link
Contributor Author

@iSazonov ; yes, happy for this to be closed given it's already covered there. Thank-you.

@iSazonov iSazonov added Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered. labels Oct 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.
Projects
None yet
Development

No branches or pull requests

3 participants