# Finding SSNs with PowerShell, FSRM or regex: where DIY stops

> Windows can find Social Security numbers in text files with Select-String or File Classification Infrastructure. Working code, and the places where it stops.

Page: https://vellumsoft.net/blog/find-ssn-with-powershell  
Updated: 2026-11-16  
Publisher: VellumSoft (Titan Grand Ventures LLC)

Windows already has two ways to find Social Security numbers in files. PowerShell's Select-String searches text files for a pattern. Microsoft File Classification Infrastructure (FCI), part of File Server Resource Manager (FSRM), tags files on a Windows file server that contain one. Both are built in, and both work well on plain text. Both stop in the same places: mailbox archives, scanned pages, and numbers that need arithmetic to confirm.

## Start from SSA's own rules

A good pattern begins with what the Social Security Administration says about the number. An SSN is nine digits in three groups separated by hyphens [1]. Since June 25, 2011, SSA assigns all SSNs randomly, so the first three digits no longer point to a state [3].

SSA also says which numbers it never assigned. Its manual calls these invalid or impossible SSNs and identifies them by [2]:

- the first three digits being 000, 666 or in the 900 series [2]
- the middle two digits being 00 [2]
- the last four digits being 0000 [2].

Those three rules are all a pattern can check. Nothing in SSA's description of the structure mentions a check digit [1].

## Route one: Select-String

Microsoft describes Select-String as a command that "uses regular expression matching to search for text patterns in input strings and files", much like grep on Unix [4]. Paired with Get-ChildItem, which walks a folder and everything below it, it can sweep a share [5].

The script below is read-only. It opens files for reading, prints the path and line number of each match, and shows only the last four digits. The pattern was checked against made-up numbers. Run the whole script on a test folder of your own before pointing it at a share.

```powershell
$pattern = '\b(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}\b'   # hyphenated SSNs, minus SSA's never-assigned ranges [2][4]
Get-ChildItem -Path 'S:\Finance' -Recurse -File -Include *.txt, *.csv, *.log -ErrorAction SilentlyContinue |
    Select-String -Pattern $pattern -AllMatches |
    ForEach-Object {
        foreach ($m in $_.Matches) {
            [pscustomobject]@{
                Path  = $_.Path
                Line  = $_.LineNumber
                Match = 'XXX-XX-' + $m.Value.Substring($m.Value.Length - 4)
            }
        }
    }
```

A few notes on using it:

1. Change the path and the list of extensions to suit. Keep to text formats.
2. Run it under an account that is allowed to read the folder. Folders it cannot list are skipped without a message, because of the SilentlyContinue setting on Get-ChildItem, so a quiet run is not proof of a clean folder.
3. Treat the output as sensitive. NIST says partial identifiers such as the last few digits of SSNs "are also often considered PII" [13]. Do not save the list to the share you just searched.

The pattern looks only for the hyphenated form. Dropping the hyphens would match every nine-digit number in every file, which sweeps in invoice and order numbers.

## Route two: FSRM and File Classification Infrastructure

FSRM is "a role service in Windows Server that enables you to manage and classify data stored on file servers" [6]. Its File Classification Infrastructure lets an administrator classify files by rule and then act on the classification, for example by restricting access, encrypting or expiring files [6]. Microsoft lists this very job among its examples: "Create a file classification rule that tags any file that contains at least 10 social security numbers as having customer content" [6].

The steps, from Microsoft's documentation:

1. Install the FSRM role service on the file server.
2. Create a classification property, such as a yes or no flag for personal information.
3. Create a classification rule. Give it a scope of folders, choose the Content Classifier as the mechanism, and enter a regular expression [7][8].
4. Run classification, then use a storage report or a file management task to act on the tagged files [6].

Three properties of FCI shape what you get. It tags whole files. Microsoft says "Each rule sets the value for a single property", so the result is a flag on the file, with no list of the matches inside it [7]. It covers NTFS volumes only [6]. And reports have size limits: the ReportLimitMaxFile setting "Specifies the maximum number of files to include in a storage report" [9].

## Check any pattern you copy, including Microsoft's

Read a published pattern against SSA's rules before using it. Microsoft's demonstration steps for a classification rule use this expression for an SSN: `^(?!000)([0-7]\d{2}|7([0-7]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$` [8]

It accepts a first group beginning with any digit from 0 to 7, so it rejects every number whose first digit is eight or nine [8]. SSA's list of numbers it never assigned names 000, 666 and the 900 series, and says nothing against numbers that begin with eight [2]. The same expression lets 666 through, which SSA lists as never assigned [2][8]. A rule built on it can miss valid numbers issued since SSA began assigning randomly [3].

The same check applies to a vendor walkthrough. Netwrix's FCI walkthrough says its expression "will search files for Social Security numbers in the format XXX-XXX-XXX" [10]. SSA's format is three digits, two digits, then four [1].

None of this is a reason to avoid regular expressions. It is a reason to test a pattern on made-up numbers before trusting a quiet result.

## Where the do-it-yourself route stops

| What you need to find | Why Select-String and FCI stop | Source |
|---|---|---|
| An SSN in an email attachment inside a PST | Select-String "is based on lines of text" [4], and a mailbox archive is not lines of text | Microsoft |
| An SSN on a scanned form or a photo | The page is a picture, with no text until it has been through OCR | |
| A real Social Insurance Number among nine-digit numbers | Microsoft's own SIN detector relies on a checksum, which a pattern cannot compute [12] | Microsoft |
| A real SSN among nine-digit numbers | Microsoft's SSN detector has no checksum to use, so it asks for a keyword within 300 characters [11] | Microsoft |
| A masked report for someone else to act on | The script prints matches to the screen; FCI sets a flag on the file [7] | Microsoft |
| Workstations and NAS boxes | Netwrix notes that FCI "works with Windows-based file servers only" [10] | Netwrix |

Lepide, which sells a platform of its own, puts the FSRM case fairly: it "is not a comprehensive data discovery platform", though it can help locate regulated data on Windows file servers [14].

## When DIY is enough

This part is opinion. We think the script above is the right first move for a small job: a folder of text and CSV exports, a one-off question, numbers written with hyphens. It costs nothing and takes an afternoon to understand.

We think it stops being enough when any of three things is true. The files include mail archives or scans. The identifiers include ones with check digits, such as Canadian SINs or card numbers, where arithmetic separates real numbers from noise. Or someone outside IT needs a report that shows where the data is without showing the data.

## What a dedicated scanner adds

VellumSoft reads PST, OST and MSG mail files with their attachments, and reads scanned PDF pages and images by OCR when OCR is on. SINs and payment card numbers are Tier 1 detectors that must pass the Luhn check, and Tier 2 identifiers are reported only with a supporting keyword or field name. Findings are masked by default, and the PDF audit report holds no raw values.

It shares one gap with the script. Version 2.0.2 does not read Word (DOCX), Excel (XLSX), ZIP or 7z files, and lists them on the Coverage tab after a scan. No scanner finds everything. The identifiers it covers are on [finding Social Security numbers](https://vellumsoft.net/detect/ssn), and the steps of a scan are on [how a scan works](https://vellumsoft.net/how-it-works).

Related reading: [how to find sensitive data on your network](https://vellumsoft.net/blog/how-to-find-pii-on-your-network), [what to do after finding employee SSNs on a shared drive](https://vellumsoft.net/blog/ssns-in-plain-text), [whether Microsoft 365 is HIPAA compliant](https://vellumsoft.net/blog/is-microsoft-365-hipaa-compliant) and what Microsoft 365 DLP does not find ([Microsoft 365 DLP limits](https://vellumsoft.net/blog/microsoft-365-dlp-limits)).

Whichever route you take, test it first on a file of numbers SSA never assigned, and confirm the pattern ignores them.

This page explains the law in general terms and is not legal advice.

## Questions

### What is Microsoft File Classification Infrastructure?

File Classification Infrastructure is a feature of File Server Resource Manager, a role service in Windows Server. Microsoft says it automates classification so that files can be tagged by rule and policies applied to them, such as access restrictions, encryption and expiration. A rule can look inside files for a string or a regular expression.

### Is there a native Microsoft tool to find SSNs on a file server?

Two. PowerShell's Select-String searches text files for a pattern and prints the file and line number of each match. File Server Resource Manager can run a classification rule that tags files containing a pattern. Microsoft's own example is a rule that tags any file with at least 10 Social Security numbers.

### Does FSRM limit how many files a report lists?

Storage reports have configurable limits. Microsoft documents a ReportLimitMaxFile setting, changed with the Set-FsrmSetting command, that sets the maximum number of files to include in a storage report. A report that looks short may have reached that limit, so check the setting before treating the list as complete.

### Can a regular expression confirm that a number is a real SSN?

No. A regular expression checks shape. The Social Security Administration's rules let a pattern rule out numbers that were never assigned, such as those starting with 000 or 666, but an SSN has no check digit, so any other nine digits in the right shape still match.

## Sources

1. [Social Security Administration, POMS RM 10201.030, Structure of the Social Security Number (SSN)](https://secure.ssa.gov/POMS.NSF/lnx/0110201030)
2. [Social Security Administration, POMS RM 10201.035, Invalid Social Security Numbers (SSNs)](https://secure.ssa.gov/POMS.NSF/lnx/0110201035)
3. [Social Security Administration, POMS RM 10201.050, Social Security Number (SSN) Assignment and Card Issuance](https://secure.ssa.gov/POMS.nsf/lnx/0110201050)
4. [Microsoft Learn, Select-String (Microsoft.PowerShell.Utility)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string)
5. [Microsoft Learn, Get-ChildItem (Microsoft.PowerShell.Management)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem)
6. [Microsoft Learn, File Server Resource Manager (FSRM) overview](https://learn.microsoft.com/en-us/windows-server/storage/fsrm/fsrm-overview)
7. [Microsoft Learn, Create an Automatic Classification Rule](https://learn.microsoft.com/en-us/windows-server/storage/fsrm/create-automatic-classification-rule)
8. [Microsoft Learn, Deploy Automatic File Classification (Demonstration Steps)](https://learn.microsoft.com/en-us/windows-server/identity/solution-guides/deploy-automatic-file-classification--demonstration-steps-)
9. [Microsoft Learn, Set-FsrmSetting (FileServerResourceManager)](https://learn.microsoft.com/en-us/powershell/module/fileserverresourcemanager/set-fsrmsetting)
10. [Netwrix, Microsoft File Classification Infrastructure (FCI) Explained](https://netwrix.com/en/resources/blog/microsoft-file-classification-infrastructure-fci-explained/)
11. [Microsoft Learn, U.S. social security number (SSN) entity definition](https://learn.microsoft.com/en-us/purview/sit-defn-us-social-security-number)
12. [Microsoft Learn, Canada social insurance number entity definition](https://learn.microsoft.com/en-us/purview/sit-defn-canada-social-insurance-number)
13. [NIST, SP 800-122, Guide to Protecting the Confidentiality of Personally Identifiable Information (PII)](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-122.pdf)
14. [Lepide, How to Find Files Containing PII, PHI, or Financial Data](https://www.lepide.com/blog/how-to-find-files-containing-pii-phi-or-financial-data/)
