0

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 
    }
0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the response. Will give a try with this.
Please consider accepting this solution if it had helped :) meta.stackexchange.com/questions/5234/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.