How can I give today’s date as default value for a parameter in powershell

Question:

I’d like to create a script that helps to copy files modified in a time range. I would like to leave the $EndDate parameter as optional and in such-case, I’d like the script to use today’s date as Default.

Below is the Script:

Answer:


give it a default value like so, you may also want to format it:

Source:

How can I give today’s date as default value for a parameter in powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply