Is there a way to continue using the name that begins with a space and splat that?
So this of course works:
$Splat = @{
name = 'chrome'
fileversioninfo = $true
}
(Get-Process @Splat)[0]
For me it returns:
ProductVersion FileVersion FileName
-------------- ----------- --------
84.0.4147.125 84.0.4147.125 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Now, if I change the variable name to ' Chrome File Path and Version ' I get this:
${ Chrome File Path and Version } = @{
name = 'chrome'
fileversioninfo = $true
}
The variable is valid and returns the properties:
Name Value
---- -----
fileversioninfo True
name chrome
But trying to splat it, it thinks I am trying to create a hashtable because of the brackets:
At line:5 char:23
+ (Get-Process @{ Chrome File Path and Version })[0]
+ ~
Missing '=' operator after key in hash literal.
So my question is, anyone aware of a way to splat a variable that requires brackets around it? I'm well aware a simple
$splat = ${ Chrome File Path and Version }
Would work, but the question isn't for a workaround, just if there's a way to splat variables with a space as the first character. I've tried escape characters, single/double quotes, subexpressions and piping to drop the name in place but with no documentation on this, I'm pretty sure it's just not supported :/
Also, in case it matters, I am still on version 5.1.19041.1