What I’m trying to do is create a PowerShell script which gets a list of folders in a directory which is filtered by a regular expression screening out folder names with nnnnnnx31 or nnnnnnddd where n = alpha chars for the first 6 characters and the last 3 is either numbers of the static string x31. Next it screens if the files are 90 days old which will be copied to a different directory.
When i try to run:
get-childitem | where {$_.name -match '^\d{6}([a-zA-Z]{3}|x31)$'} | where {$_.lastwritetime -lt (get-date.adddays(-90)}
I get the error:
You must provide a value expression on the right-hand side of the -lt operator At line: 1 char: 96 + get-childitem | where {$_.name -match '^\d{6}([a-zA-Z]{3}|x31)$'} | where {$_.lastwritetime -lt <<<< get-date.adddays(-90)}
I also tried the following and it didn’t work:
get-childitem | where {$_.name -match '^\d{6}([a-zA-Z]{3}|x31)$'} | where {$_.lastwritetime -lt (get-date | foreach-object {$_.adddays(-90)}) }
Any ideas?
you need to do
(get-date).AddDays(-90)