我想创建一个脚本来帮助复制在某个时间范围内修改的文件。我要离开$EndDate
参数作为可选,在这种情况下,我希望脚本使用今天的日期作为默认日期。
下面是脚本:
param (
[Parameter(Mandatory=$True)]
[string]$Path,
[Parameter(Mandatory=$True)]
[string]$targetDir,
[Parameter(Mandatory=$True)]
[string]$BeginDate,
[Parameter(Mandatory=$False)]
[string]$EndDate,
[switch]$force
)
Get-ChildItem -Path $Path -Recurse | Where-Object {$_.LastWriteTime -gt $BeginDate -and $_.LastWriteTime -lt $EndDate }| cp -Destination $targetDir -Force
最佳答案
[Parameter(Mandatory=$False)][string]$enddate = Get-Date,
给它一个像这样的默认值,你可能还想格式化它:
[Parameter(Mandatory=$False)][string]$enddate = (Get-Date -f dd\MM\yy)
关于powershell - 如何将今天的日期作为 powershell 中参数的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45060435/