---
title: "Tips: How to automate retrieving Folder GUIDs for multiple users"
url: "https://dm0bkdes5q7a2ls.productfruits.help/en/article/c279aa18-920a-46be-8cfa-2a885289d280"
language: "en"
last_updated: "2026-05-06T03:36:55.035Z"
---

# Tips: How to automate retrieving Folder GUIDs for multiple users

Yes, you can automate the retrieval of Folder GUIDs for multiple users. Since these GUIDs are stored within the Exchange/Office 365 environment, the most efficient way to do this at scale is using PowerShell.

Depending on your environment (On-Premise Exchange vs. Exchange Online/Office 365), you can use the following methods to generate a list of GUIDs that you can then paste into your Spirion scan policies.

### 1\. For Exchange Online (Office 365)

You need the `ExchangeOnlineManagement` PowerShell module. This script iterates through a list of users and pulls the IDs for specific folders (like "Inbox" and "Sent Items").

```
# Connect to Exchange Online
Connect-ExchangeOnline

# Define the users you want to target (or pull from a CSV/Group)
$UserList = @("user1@company.com", "user2@company.com") 

# Loop through users and get Folder IDs
foreach ($User in $UserList) {
    Write-Host "Retrieving IDs for $User..." -ForegroundColor Cyan
    Get-MailboxFolderStatistics -Identity $User | Where-Object { $_.Name -eq "Inbox" -or $_.Name -eq "Sent Items" } | Select-Object Identity, FolderId
}
```

*Note: The* `FolderId` returned by this command is the unique string Spirion needs.

### 2\. Exporting to a "Spirion-Ready" Format

If you need to gather GUIDs for hundreds of users to paste into a single policy, you can export them directly to a text file where each GUID is on its own line (matching Spirion's required format).

```
$TargetFolders = @("Inbox", "Finance", "HR")
$Results = Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics | Where-Object { $TargetFolders -contains $_.Name }

# Export only the FolderId strings to a text file
$Results.FolderId | Out-File "C:\Spirion_GUID_List.txt"
```

### 3\. Using the Spirion "Discovery" Method (Automated via Console)

If you don't have Exchange Admin rights, you can use Spirion itself to "auto-discover" these IDs:

1.  **Create a "Discovery Only" Scan:** Target the group of users but uncheck all sensitive data types.
2.  **Run the Scan:** The Agents crawl the mailboxes and report back every folder they find.
3.  **Export Results:** From the Spirion Console, go to the **Locations** or **Results** tab and export the list to CSV. The CSV contains a column for the "Location ID" or "Path," which includes the GUIDs in brackets. You can then use Excel to "Clean" the data and extract just the GUID strings for your final policy.

### Important Considerations for Automation:

-   **GUID Consistency:** In Exchange Online, Folder GUIDs are generally static. However, if a mailbox is migrated from On-Premise to the Cloud, the GUIDs **will change**. You must re-run your automation after any major mailbox migration.
-   **Permissions:** To run these PowerShell commands, your admin account must have the **View-Only Configuration** or **Mail Recipients** role in Exchange.
-   **Throttling:** If you are running `Get-MailboxFolderStatistics` against thousands of users, Exchange Online may throttle your session. It is best to run these scripts in batches of 100-200 users.

### SME Recommendation:

If your goal is to scan specific folders across the *entire* company (for example, everyone's "Finance" folder), automation is the only viable path. Use the **PowerShell method** to generate a master list of GUIDs, then use a text editor like **Notepad++** to remove duplicates before pasting the final list into the Spirion "Insert Outlook Folder GUIDs" field.

**Summary:** Use **PowerShell** (`Get-MailboxFolderStatistics`) to pull the `FolderId` property. This enables you to quickly gather IDs for thousands of folders and format them into the "one-per-line" list required by the Spirion wizard.
