Q:

Change encoding and extension of files within a directory using powershell

I've been trying to write a script to change the file encoding and file extension for a group of files within a specific directory to no avail.  So far the get-content and set-content method has been working, but only for individual files (haven't gotten it to loop).  
i.e
get-content testdocument.txt | set-content -encoding utf8 "testdocument.xml" 
#works! 

i.e.
$a = dir |
    $a foreach-object |
        get-content | set-content -encoding utf8 $a_fullname.xml
#doesn't work =(

I've also had success (limited) with the rename-item cmdlet.  I'm able to rename all the items within a directory, but am unable to change the encoding. 
i.e
get-childitem *.txt | rename-item -newname {$_.name -replace '.txt','.xml'} 
#works! 

i.e
get-childitem *.txt | rename-item -newname {$_.name -replace '.txt','.xml'} | -encoding utf8
#doesn't work =(

Any help would be much appreciated.  I apologize if this question seems trivial (new to Powershell/scripting in general, also first time posting).  Thanks in advance! 

A:

For your loop, you need to modularize your commands to where you can reference them and call them properly.   In your case, rather than calling the "fullName" property, you need to be calling "baseName" and appending ".xml" to it in your original command that works.   After that, simply using the right variables in the right places in your ForEach loop will make it work. 
$a = Get-ChildItem
ForEach ($item in $a) {
  Get-Content $item. FullName | Set-Content -Encoding utf8 "$($item. Basename).xml"
}

This will allow you to have your original files next to your new xml files with the appropriate encoding. 