简体   繁体   中英

How I can update the Field extensionAttribute3 with Powershell and System.Management.Automation in ASP.NET`?

net application and I want to update informations in the active directory. For this I use the System.Management.Automation namespace. With this I can use the Powershell for this. It works good but I don't know how I can update the field "extensionAttribute3" (this is our Costcenter).

here my code:

...
 PSCredential crend = new PSCredential(ADNAME, pw);

                using (Runspace runspace = RunspaceFactory.CreateRunspace(initial))
                {
                    runspace.Open();
                    using (Pipeline p = runspace.CreatePipeline())
                    {
                        Command command = new Command("Set-ADUser");
                        command.Parameters.Add("Identity", sAMAccountName);
                        //command.Parameters.Add("extensionAttribute3", CostCenter); ??? 
                        command.Parameters.Add("Description", Description);
                        command.Parameters.Add("Credential", crend);

                        p.Commands.Add(command);

                        p.Invoke();

                    }
                }
...

The Set-ADUser cmdlet doesn't have a parameter for all the possible attributes. For attributes that don't have dedicated parameter, you use the -Add, -Replace, and -Remove parameters and give them a hash table argument of the attribute names and values. Not sure this if the syntax is exactly right, but something like this:

command.Parameters.Add("Replace",@{extensionAttribute3='CostCenter'})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM