Garacesh Posted June 1, 2015 Posted June 1, 2015 } elseif (!(Test-Path "\\Path\To\File\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")))) { [color="#FF0000"]Test-Path : A parameter cannot be found that matches parameter name 'NewerThan'. At C:\Users\AKPADS Server\Desktop\CoverList.ps1:5 char:101 + ... *.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")))) { + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: ( [Test-Path], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestPathCommand[/color] Been using this script for over 6 months without an issue and suddenly I'm using an invalid parameter..? Doesn't make any sense.
mikecampbell Posted June 1, 2015 Posted June 1, 2015 Did you upgrade/downgrade Powershell? By the looks of it the -NewerThan was introduced in Powershell 3.
Steve21 Posted June 1, 2015 Posted June 1, 2015 You running it on the same machine etc? Don't think NewerThan exists pre v3 so if it's another machine it might not work on if older version of powershell. Steve
Garacesh Posted June 1, 2015 Author Posted June 1, 2015 Aye, same machine. Nothing's changed in the past 6 months. No Powershell upgrade/change done at all. Was working the Friday we broke up. Came back today and bam, error.
Steve21 Posted June 1, 2015 Posted June 1, 2015 You sure there's a word document in that path? Just tried it and without one get same error, with one it works. Steve 1
Steve21 Posted June 1, 2015 Posted June 1, 2015 PS N:\> Test-Path -Path "\\its-001\c$\test\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")) True PS N:\> Test-Path -Path "\\its-001\c$\test\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")) Test-Path : A parameter cannot be found that matches parameter name 'NewerThan'. At line:1 char:44 + Test-Path -Path "\\its-001\c$\test\*.docx" -NewerThan ((Get-Date).ToString("dd/M ... + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: ( [Test-Path], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestPathCommand etc Steve
Garacesh Posted June 1, 2015 Author Posted June 1, 2015 (edited) facepalm Should've checked that, alas, you're right. tl;dr the Cover Supervisor exports the cover list, and I convert it to a html file and slap it on our digital signage. This has been done in the same way since I joined 3 years ago and (without being insulting) she's not the most technically literate of users (though by far she isn't the least, either).. I saw no reason that her standard procedure would have suddenly changed. For some reason it's created a subfolder and saved in there. Edit: Nope. Timestamp says that's not the right file. What a stupid, stupid error message. (!(Test-Path "\\Path\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")))) should, in this case, be True (as there is no word document created today), therefore it meets the criteria for the elseif check and thus should execute the script block thereafter (which is just a write-host file not found error).. Why it's complaining about an invalid parameter I have no idea.. Edited June 1, 2015 by Garacesh
Steve21 Posted June 1, 2015 Posted June 1, 2015 Because you're effectively piping two commands together which don't have logical connectors It's like saying "get latest time from doc files" + "is latest time more than today" And it's going "what's latest time?!?!" as it's never got it. At least it's sorted haha Monday fun! Steve
Garacesh Posted June 1, 2015 Author Posted June 1, 2015 (edited) I don't follow.. To me, it logically reads "Find files in this location, matching this name, newer than this date." (Test-Path "\\Path\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy"))) should retern $False, therefore (!(Test-Path "\\Path\*.docx" -NewerThan ((Get-Date).ToString("dd/MM/yyyy")))) should return $True, and execute the following script block (Write-Host ".doc file not found") - at least, that was my thinking when writing this script.. The script basically checks for two files (or more specifically, checks for NOT two files) IF NOT EXIST [File] { Error message } ELSEIF NOT EXIST [File] { Error message } ELSE { Do a bunch of stuff with the two files } Bit of a kludge but has worked so far... But I guess my logic was wrong.. Edited June 1, 2015 by Garacesh
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now