0

I am trying to pass a variable through to be used as a parameter within a function. I'm not even sure if this is possible but below is what i am attempting to accomplish, what i have tried so far keeps kicking out a "positional parameter cannot be found that accepts argument" error

$Var = Read-host "enter Attribute number"
$CustomAtt = "CustomAttribute$Var"

Get-Mailbox -Identity $Email | Set-Mailbox -$CustomAtt "TestTest"

1 Answer 1

1

You cannot set cmdlet arguments that way in powershell. You can do what your are attempting to do by using a feature called argument splatting. Simply store your arguments in an array or hashtable and then apply them to the cmdlet using @ symbol.

Like this:

$mailBoxAttributes = @{
    $CustomAtt = "TestTest" }

Get-Mailbox -Identity $Email | Set-Mailbox @mailBoxAttributes
Sign up to request clarification or add additional context in comments.

1 Comment

This did solve the issue, with some tweaking at least,. I realized i was doubling up cmdlets and dropped the Get-mailbox completely and just splatted in the identity and customattribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.