Walter Kindblad
Walter Kindblad

Reputation: 37

Use a variable as parameter in Set-MsolUser

Why can't I use a variable as a parameter in PowerShell?

Set-MsolUser -UserPrincipalName [email protected] -$parameter Stockholm

$parameter is equal to City in this case

Set-MsolUser : A positional parameter cannot be found that accepts argument '-City'.
At line:1 char:1
+ Set-MsolUser -UserPrincipalName [email protected]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-MsolUser], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Online.Administration.Automation.SetUser

Upvotes: 1

Views: 427

Answers (1)

Patrick
Patrick

Reputation: 2208

You could use the following options:

1)Invoke the command with arguments

Invoke-Command -ScriptBlock {Get-ChildItem} -ArgumentList "-$($para) C:\Temp"

2) Use splatting

$Val = 'Path'
$HashArguments  = @{
    $Val = 'C:\Temp'
}

Get-ChildItem @HashArguments

Upvotes: 1

Related Questions