How to change the value of XML Element attribute using PowerShell?

前端 未结 3 673
南旧
南旧 2020-12-11 00:05

I am trying to access and change the particular attribute from XML tag

XML:


  
    <         


        
3条回答
  •  星月不相逢
    2020-12-11 00:17

    You can access the attributes directly in the [xml] object like this:

    # C:\temp> $xml = [xml](Get-Content C:\FE6Work.xml)
    # C:\temp> $xml.office.staff
    
    branch                   Type                           employee                                                             
    ------                   ----                           --------                                                             
    Hanover                  sales                          {Tobias Weltner, Cofi Heidecke}                                      
    London                   Technology                     {XXXX, Cofi}                                                         
    
    # C:\temp> $xml.office.staff | foreach{$_.branch = "New York"}
    # C:\temp> $xml.office.staff
    
    branch                   Type                           employee                                                             
    ------                   ----                           --------                                                             
    New York                 sales                          {Tobias Weltner, Cofi Heidecke}                                      
    New York                 Technology                     {XXXX, Cofi}                                                         
    

提交回复
热议问题