我正在构建PS脚本,以仅从特定日期开始从IIS smtp中继中选择死信(.bad)文件...
有了这部分代码,我得到了...
%_。LastWriteTime:术语'%_。LastWriteTime'不被识别为cmdlet,函数,脚本文件或可运行程序的名称。检查名称的拼写,或者是否包含路径,请确认路径正确,然后重试。
获取子项$ SourceFolder * .bad |哪里对象{$ _。LastWriteTime -eq 1/23/2019}
答案 0 :(得分:0)
我不认为Get-Childitem可与Regex一起使用。您可能需要将结果与类似的内容链接在一起
Get-childitem $SourceFolder| where-object{$_.Name -match "*.bad"}| where-object{$_.Lastwritetime...}
答案 1 :(得分:0)
以这种方式尝试您的用例,而不是如何设置日期字符串。
Clear-Host
Get-ChildItem -Path 'd:\temp\certs'
<#
# Results
Directory: D:\temp\certs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/24/2019 7:39 PM 0 New Text Document.cer
-a---- 1/24/2019 7:39 PM 0 New Text Document.crt
-a---- 1/24/2019 7:39 PM 0 New Text Document.pfx
#>
(Get-ChildItem -Path 'd:\temp\certs') -match '.cer|.crt'
<#
# Results
Directory: D:\temp\certs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/24/2019 7:39 PM 0 New Text Document.cer
-a---- 1/24/2019 7:39 PM 0 New Text Document.crt
#>
Clear-Host
Get-ChildItem -Path 'd:\temp\certs' |
Where-Object -FilterScript {$_.Name -match '.cer|.crt'}
<#
# Results
Directory: D:\temp\certs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/24/2019 7:39 PM 0 New Text Document.cer
-a---- 1/24/2019 7:39 PM 0 New Text Document.crt
#>
Clear-Host
Get-Childitem 'D:\temp' -Filter '*.txt' |
Where-Object {$_.LastWriteTime -like '10/18/2018*'}
<#
# Results
Directory: D:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/18/2018 8:46 PM 313 DataSet.txt
#>
Clear-Host
Get-Childitem 'D:\temp' -Filter '*.txt' |
Where-Object {$_.LastWriteTime -match '10/18/2018'}
<#
# Results
Directory: D:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/18/2018 8:46 PM 313 DataSet.txt
#>
答案 2 :(得分:0)
$path = 'your\path\'
$Time = (Get-date).AddDays(-6)
$pasttime = Get-Date $Time -Format MM/dd/yyy
(Get-ChildItem -Path $path -Filter *.bad).LastWriteTime | Where-Object {$_.LastWriteTime -eq $pasttime }
或尝试:
(Get-Item -Path $path).LastWriteTime | Where-Object {$_.LastWriteTime -le $pasttime}
或者也许:
(Get-ItemProperty -Path $path).LastWriteTime | Where-Object {$_.LastWriteTime -le $pasttime}