2013-12-20 43 views
0

網絡應用程序,我想更新活動目錄中的信息。爲此,我使用System.Management.Automation命名空間。有了這個,我可以爲此使用Powershell。它工作得很好,但我不知道如何更新字段「extensionAttribute3」(這是我們的Costcenter)。如何使用PowerShell和System.Management.Automation在ASP.NET中更新字段extensionAttribute3?

這裏我的代碼:

... 
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(); 

        } 
       } 
... 

回答

1

使用Set-ADUser便有cmdlet不會對所有可能的屬性的參數。對於沒有專用參數的屬性,可以使用-Add,-Replace和-Remove參數,併爲它們提供屬性名稱和值的哈希表參數。不確定這是否語法是完全正確的,但是像這樣:

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