I have a PowerShell script that looks for specific files and folders and the file and folder URLs in contained in an XML file (written to a variable in PowerShell). I want to be able to look for files in the directory of the current user, but XML files can't contain dynamic variables, so I can't just do the following
<URL>C:\Users\$Env:UserName\SomeFile.*</URL>
So what I have done is declare an XML Entity as such:
<!DOCTYPE config [
<!ENTITY user "UserName!">
]>
BUT, I can not figure out how to reference this entity from PowerShell to update it. So I can't just do this:
$Config.Config.UserName = $Env:UserName
Is there anyway to access entities once an XML file is written to a PowerShell variable. I.E. written to a var like this:
[xml]$Config = Get-Content ./SomeXML_File.xml
Update -- Here is an example of what I am looking at. I want to use PowerShell to replace "UserName!" with the current user of the system. So that "&user;" will be read as the current system user when the script gets data from the xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE config[
<!ENTITY user "UserName!">
]>
<Configuration>
<Files>
<URL>C:\Users\&user;\Desktop\NewFolder</URL>
</Files>
</Configuration>
'''