Skip to content

Document -OlderThan/-NewerThan parameter updates for Test-Path cmdlet #10742

@ArmaanMcleod

Description

@ArmaanMcleod

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Document new Get-Foo cmdlet" instead of "New cmdlet."

Summary

Including examples for -OlderThan/-NewerThan parameters when using Test-Path cmdlet. I've included fixes in linked pull request and realised we need some more documentation for usage using these two parameters since usage is currently undocumented and the linked PR included new functionality on how to use both parameters to test if path exists in date range.

Details

Examples

Check if file is older than one day

> Test-Path -Path $file -OlderThan (Get-Date).AddDays(-1)
True

Check if file is newer than one hour

> Test-Path -Path $file -NewerThan (Get-Date).AddHours(-1)
True

Check if file is newer than two days and older than today - date range

> Test-Path -Path $file -NewerThan  (Get-Date).AddDays(-2) -OlderThan (Get-Date)
True

Can also include similar examples for using these parameters with -PathType as that is also supported in PR changes. There was an existing restriction with dynamic parameters which only allowed -OlderThan/-NewerThan to be used with TestPathType.Any.

Check if file (Leaf) is older than on day

> Test-Path -Path $file -OlderThan (Get-Date).AddDays(-1) -PathType Leaf
True

Check if directory (Container) is older than on day

> Test-Path -Path $dir -OlderThan (Get-Date).AddDays(-1) -PathType Container
True

Articles

  • reference/7.4/Microsoft.PowerShell.Management/Test-Path.md

Related Source Pull Requests

Related Source Issues

Metadata

Metadata

Labels

area-managementArea - Microsoft.PowerShell.Management moduleissue-doc-ideaIssue - request for new content

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions