Using a variable in a parameter form- what is wrong?

I can’t figure out why it recognize the variable and still gives an error
look at the first example and see it’s basically the same as the second but the first works and the second don’t, I want to use a variable there but can’t for some reason
anyone have any idea how to fix it ?
thanks in advance

Hi, welcome to the forum :wave:

What PowerShell is trying to do here is bind your variable to a parameter. It can’t use the value of your variable as a parameter name.
If you had not specified $user it would actually work (although not as you’d expect, it would pass the Identity parameter the value office).

To sort of achieve what you’re trying to do, use splatting:

$params = @{
    Identity = $user
    Office = $NewField

Set-ADUser @params

Thanks for the help, it works :smile: