How to use "-replace" in Set-ADUser?

I want to use PowerShell through my C # to change Active Directory attributes. Here is my PowerShell command that I can use to replace the Active Directory attribute:

Set-ADUser -Identity "kchnam" -Replace @{extensionAttribute2="Neuer Wert"} 

How to add the command @{extensionAttribute2="Neuer Wert"} to a C # command?

My solution does not work:

 Command setUser = new Command("Set-ADUser"); setUser.Parameters.Add("Identity", aduser); string testadd = "@{extensionAttribute2=" + quote + "Neuer Wert" + quote + "}"; setUser.Parameters.Add("Replace", testadd); 
+4
source share
1 answer

In PowerShell:

 @{extensionAttribute2="Neuer Wert"} 

means a Hashtable literal, not just a string . So in C # you also need to create a Hashtable object:

 new Hashtable{{"extensionAttribute2","Neuer Wert"}} 

Although this is not completely equivalent to PowerShell, as PowerShell creates a Hashtable using a case-insensitive key. But, most likely, you can use any collection that implements IDictionary , and not just Hashtable .

+2
source

All Articles