Hello,
What I'm trying to do seemed simple enough until six hours into debugging... I'm writing a script to move files older than a date specified in an xml file. I'm also specifying the paths in the xml file. When I run the script I get the following error:
I have tried converting the variable to a string using .ToString and | Out-String, but I get the same error. If I check the variable, I see that it is populated from the xml. The script also works fine if I replace the variables with text.
Here's my script, any recommendations will be appreciated:
# Read config.xml and configure variables accordingly.
[xml]$settings = Get-Content config.xml
$CurrentLogPath = $settings.settings.paths.path.currentlogpath
$ArchiveLogPath = $settings.settings.paths.path.archivelogpath
$LogMaxAge = $settings.settings.limits.limit.logmaxage
# Move all files in $CurrentLogPath that are older than $LogMaxAge into $ArchiveLogPath
get-childitem -Path $CurrentLogPath | where-object {($_.LastWriteTime -lt (get-date).AddDays(-$LogMaxAge))}| move-Item -force -Destination c:\test\archive