You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell脚本需求:批量检查TEST文件夹修改日期并输出提示

PowerShell Script to Check Folder Last Modified Date

Hey there! Since you're new to PowerShell scripting, let's build this solution together in a way that's easy to understand and adapt. Your goal is to check specific TEST folders and alert if they weren't modified today—here's how to do it:

Full Working Script

# Define the list of TEST folder paths we need to check
$testFolders = @(
    "c:\folder\Folder1\TEST",
    "c:\folder\Folder2\TEST",
    "c:\folder\Folder3\TEST",
    "c:\folder\Folder4\TEST"
)

# Get today's date without the time component (we only care about the date part)
$today = (Get-Date).Date

# Loop through each folder in our list
foreach ($folder in $testFolders) {
    # First, check if the folder actually exists (avoids errors if the path is wrong)
    if (Test-Path -Path $folder -PathType Container) {
        # Grab the folder's last modified date (only the date part, not time)
        $folderLastModified = (Get-Item -Path $folder).LastWriteTime.Date

        # Compare the folder's date to today
        if ($folderLastModified -ne $today) {
            # Extract the "FolderX" part from the path to make our message clear
            $folderLabel = ($folder -split "\\")[2]
            Write-Host "$folderLabel not updated from yesterday"
        }
        # If the date matches today, we do nothing—just like you asked!
    } else {
        # Optional: Warn if a folder doesn't exist (helpful for debugging)
        Write-Host "⚠️ Warning: Folder '$folder' doesn't exist!"
    }
}

Breakdown of What Each Part Does

Let's walk through the script so you know exactly what's happening:

  • Define Folder Paths: We use an array ($testFolders) to store all the TEST folder locations. This keeps things organized and makes it easy to edit later if you need to add more folders.
  • Get Today's Date: (Get-Date).Date gives us today's date without any time (like hours/minutes). This is important because a folder's LastWriteTime includes time, and we only want to compare the date itself.
  • Loop Through Folders: The foreach loop goes through each folder in our list one by one.
  • Check if Folder Exists: Test-Path makes sure the folder actually exists before we try to check its date—this prevents annoying error messages if a path has a typo or is missing.
  • Compare Dates: We grab the folder's last modified date (again, just the date part) and compare it to today. If they don't match, we extract the "FolderX" part from the path and print your requested message.
  • Optional Warning: The script will alert you if a folder is missing—you can remove this part if you don't need it, but it's handy for troubleshooting.

How to Run the Script

  1. Open a text editor (like Notepad) and paste the code above.
  2. Save the file with a .ps1 extension (e.g., CheckFolderUpdates.ps1).
  3. Open PowerShell, navigate to the folder where you saved the script (use cd C:\path\to\your\script), then run:
    .\CheckFolderUpdates.ps1
    
    • If you get an execution policy error, you can temporarily bypass it with:
      powershell -ExecutionPolicy Bypass -File .\CheckFolderUpdates.ps1
      
    (Note: Execution policies are a security feature—only run scripts you trust!)

内容的提问来源于stack exchange,提问作者rohit kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:21:17