Here is my situation. I have an XML that resides in a path that contains 260+ characters. One of the folders in this path will always be random, another one is based on versions so it could be different as well.
I am trying to load the XML, make changes to it, and save it back. So far I haven't been able to do that in place so I am copying it to C:\Windows\Temp, making the changes there, and then trying to copy it back in place, which has worked in manual tests.
My main problem is the file path contains more than 260+ characters so Copy-Item hasn't worked properly and I haven't been able to figure out how to get Robocopy to work since I have to use a variable for the path because of the random folders.
XML modification works, copying out to Temp works, the problem I am having is copying it back to the 260+ character path.
I am very new to Powershell as an FYI. Here is what I have come up with so far:
$folderLocation = Get-ChildItem -Path C:\Windows\System32\config\systemprofile\AppData\Local\ProgramA\ -Filter userConfig.xml -Recurse |
Sort-Object LastWriteTime |
Select-Object -last 1 |
Select-Object Directory |
Format-Table -hide
foreach ($f in $folderLocation){
Copy-Item userConfig.xml C:\Windows\Temp
}
$myXML = New-Object System.Xml.XmlDocument
$myXML.Load("C:\Windows\Temp\userConfig.xml")
$isActive = $myXML.SelectSingleNode("//setting[@name = 'Active']")
$isActive.value = "True"
$myXML.Save("C:\Windows\Temp\userConfig.xml")
$convertFolder = [System.String]$folderLocation
Copy-Item ("C:\Windows\Temp\userConfig.xml") $convertFolder
Here is the Robocopy code I tried, I know it's a hackjob but I tried to imitate some things I saw online:
function copy-stuff
{
param([string]$source = "C:\Windows\Temp",
[string]$destination = $convertFolder,
[string]$options = “/R:0″,”/W:0″,”/COPY:DAT”)
[string]$file = "userConfig.xml"
robocopy $source $destination $file $options
}
I tried a couple different things with robocopy but this is what I still had saved. I haven't studied up on creating and using functions in Powershell so this was a monkey see monkey do attempt.