Category filter

PowerShell script to detect idle folders on Windows

In a corporate environment, employees frequently access, create, and manage large volumes of data, resulting in numerous open folders in their devices. If the folders remain open, it can create a significant security vulnerability, potentially exposing sensitive company data to unauthorized access. Moreover, open but idle folders may result in corporate devices suffering from decreased performance, higher cost of maintenance, and disrupted data management. Identifying the idle time or the time for which the system folders were left open without usage can help administrators archive such folders, increasing security.

This document provides PowerShell scripts to recognize open folders for all local user accounts and further archive folders that have been idle beyond a specified time limit. The Execute Custom Script remote action can help execute these PowerShell scripts on the target Windows devices.

Warning


The sample scripts provided below are adapted from third-party open-source sites.

Note:


The script is supported for execution on the following Windows versions:

  • Windows 10 v1803+
  • Windows 10 v1703 to Windows 10 v1709 (if .NET Framework v4.7.1+ is installed on the device)
  • Windows 11 (Pro, Enterprise, Education)

Detect Open Folders for all User Accounts

The following PowerShell script recurrently checks the last activity time of all the subfolders in the root paths (the C:\ and D:\ drives) of the device and calculates the idle time. The function used for this purpose is the Get-FolderIdleTime function, which performs the scan. The scanning progress is logged and can be viewed in the Show Output button of the Action History. It lists a table containing the folder path, last activity, time and idle days.

The output of the script listing the detected open folders can be viewed in the Show Output button from Manage > Your Windows device > Action History.

Idle folders detected on Windows devices.

Archive Open Folders for all Users beyond a specified duration

The following PowerShell script recursively checks the last activity time of all the subfolders in the root paths and calculates the idle time, like the previous script. The threshold value is set at 3 days, beyond which the folder is considered idle. The idle folders are then archived to a designated archive location (C:\Data\Archive), preserving the internal folder structure (if subfolders are present) and the original user details associated with the folder (user who created the folder, user who last modified, etc.).

A summary of the archived idle folders (open idly beyond 3 days) can be accessed from the Show Output button in the Hexnode UEM console. Navigate to Manage > Your device > Action History > Execute Custom Script action status.

Archiving idle folders on Windows devices.

List of idle folders detected and archived on Windows.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.