Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

get-childitem sees Null -Path when using a variable.

$
0
0

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

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles