Jump to content

A parameter cannot be found that matches parameter name 'NewerThan' - WTH?!


Recommended Posts

Posted

} 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.

Posted

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

Posted
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.
Posted

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

Posted (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 by Garacesh
Posted

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 :D Monday fun!

 

Steve

Posted (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 by Garacesh

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...