Reputation: 37
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
Reputation: 2208
You could use the following options:
1)Invoke the command with arguments
Invoke-Command -ScriptBlock {Get-ChildItem} -ArgumentList "-$($para) C:\Temp"
$Val = 'Path'
$HashArguments = @{
$Val = 'C:\Temp'
}
Get-ChildItem @HashArguments
Upvotes: 1