写一个powershell 脚本,要求列出C盘下边五天内创建的文件夹
时间: 2024-04-11 10:26:19 浏览: 114
一个按日期备份文件夹的脚本,windows下适用
3星 · 编辑精心推荐
Sure! Here's a PowerShell script that lists the folders created within the last five days under the C drive:
```powershell
$startDate = (Get-Date).AddDays(-5)
$endDate = Get-Date
Get-ChildItem -Path "C:\" -Directory |
Where-Object { $_.CreationTime -ge $startDate -and $_.CreationTime -le $endDate } |
Select-Object Name, CreationTime
```
This script sets the `$startDate` variable to five days ago and the `$endDate` variable to the current date. It then uses the `Get-ChildItem` cmdlet to retrieve all the folders under the C drive (`C:\`). The `Where-Object` cmdlet filters the folders based on their creation time, ensuring they are within the specified date range. Finally, the `Select-Object` cmdlet selects and displays the folder names and their creation times.
Please note that this script assumes you have sufficient permissions to access the folders under the C drive.
阅读全文