以下是我正在使用的代码:
$directory = Read-Host "Directory?"
$outPutFile = [Environment]::GetFolderPath("Desktop")+"\test.csv"
Get-ChildItem -path $directory -Recurse | where { $_.lastaccesstime -ge [datetime]$startDate -and $_.lastaccesstime -lt [datetime]$endDate} | select fullname | Export-CSV -Path $outPutFile
我收到的错误:
Cannot convert null to type "System.DateTime".
我的问题是为什么这个值为空?我使用了错误的命令吗?
答案 0 :(得分:1)
您没有定义$startDate
或$endDate
。以下内容适用:
$startDate = (get-date).addDays(-5)
$endDate = (get-date).addDays(-3)
$directory = Read-Host "Directory?"
$outPutFile = [Environment]::GetFolderPath("Desktop")+"\test.csv"
Get-ChildItem -path $directory -Recurse | where { $_.LastAccessTime -ge [datetime]$startDate -and $_.LastAccessTime -lt [datetime]$endDate} | select FullName | Export-CSV -Path $outPutFile