Reputation: 1
Powershell is not my expertise. However, I'm trying to make a call to Azure using the following code.
function Set-UserAndAttribute
{
param(
[Parameter(Position=0,mandatory=$true)]
[string]$ObjectID,
[Parameter(Position=1,mandatory=$true)]
[string]$Attribute,
[Parameter(Position=2,mandatory=$true)]
[string]$Value
)
Connect-Directory
#The below line is causing the issue. My intention is to use dynamic variable for Attribute. Is there a way to accomplish this?
Set-AzureAdUser -ObjectID $ObjectID -$Attribute $value
}
Upvotes: 0
Views: 281
Reputation: 4164
You could make use of the Invoke-Expression
The Invoke-Expression cmdlet evaluates or runs a specified string as a command.
So your code would be :
Invoke-Expression "Set-AzureAdUser -ObjectID $ObjectID -$Attribute $value"
You are passing the command as a string - this has values populated dynamically.
Upvotes: 1