How to use a PowerShell variable as command parameter?

Typically to use a variable to populate cmdlet parameters, you'd use a hash table variable, and splat it, using.

Typically to use a variable to populate cmdlet parameters, you'd use a hash table variable, and splat it, using @ $newVar = @{option1 = $true} mycommand @newVar Added example: $AS_policy1 = @{ Identity = "asdf" AllowBluetooth = $true } Set-ActiveSyncMailboxPolicy @AS_policy1.

Thanks for the help, but that returns an error "A positional parameter cannot be found that accepts argument 'System.Collections. Hashtable'. Specifically I have a loop to get properties properties from a Csv and run them into Set-ActiveSyncMailboxPolicy.

For a specific instance I'll say $_. Name = "AllowBluetooth" and $_. Value = $true (I wrote these variables out to confirm correct values.

However, I can't quite put it all together Set-ActiveSyncMailboxPolicy -Identity "asdf" @{$_. Name = $_. Value} or -$_.

Name:$_.value. It takes $_. Value just fine though.

– Fantabulum May 11 at 13:17 See edit. If you splat the parameters, you should include all of them in the hashtable. – mjolinor May 11 at 13:40 Outstanding, I don't think I ever would have figured that out.

Now all I must do is figure out an exception for arrays in my Csv and I'll be done. Thank you all for you help, it's greatly appreciated! – Fantabulum May 11 at 14:54.

See if this works for you: iex "MyCommand -$($newVar):$true.

Thanks manojlds, this got me a little closer. Literally, $newVar is $_. Name and $true is $_.

Value (which equals "Allow"). The way I was doing it, it accepted $_. Value for the value but not $_.

Name as a parameter. Using your method accepts $_. Name as my parameter but not $_.

Value as the value... Saying cannot convert value "System. String" to type type. I'll keep trying other things though.

– Fantabulum May 11 at 13:38 I got your method to work when -$($newVar) wants a string, but it fails on boolean values because it thinks it's a string. I believe it's because the whole command is in quotes. Any pointers?

– Fantabulum May 11 at 14:02 @Fantabulum: iex "MyCommand -$($_. Name):$($_. Value)" should work then, for the reason I've explained in my answer.

+1 @manojlds. – empo May 11 at 14:08.

I would try with: $mycmd = "MyCommand -$($newVar):$true" & $mycmd result Can't work because the ampersand operator just execute single commands without prameters, or script blocks.

Thanks for the suggestion empo, but this seems to behave the same way as my original. I can post an excerpt of my actual script if that would help, but it involves several loops and Exchange commands so I think it would just cause confusion. – Fantabulum May 11 at 13:23 @Fantabulum: I think @manojlds is the right way to go.

– empo May 11 at 14:08.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions