PowerShell Script SSN and CC

Stephen Ruberti 1 Reputation point
2022-09-23T21:30:28.66+00:00

I am looking for a PowerShell script that will search mapped drives for files that contain CC and SSN info.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 44,766 Reputation points
    2022-09-27T09:02:05.737+00:00

    Hello there,

    Found this script online and might be useful for you,

    Install-Module PSExcel
    Import-Module PSExcel

    $cardRegex = "(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)"

    Get-ChildItem -Recurse -File "*.xlsx" | ForEach-Object {Search-CellValue -Path $.FullName -FilterScript {if($ -match "-"){$.replace("-","") -match $cardRegex}else{$ -match $cardRegex}}}

    I hope this information helps. If you have any questions please let me know and I will be glad to help you out.

    -----------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    1 person found this answer helpful.

  2. Dillon Silzer 57,831 Reputation points Volunteer Moderator
    2022-09-24T20:53:19.937+00:00

    Hi @Stephen Ruberti

    You can use this guide to search for CC and SSN info (inside of files):

    Use an Easy PowerShell Command to Search Files for Information

    https://devblogs.microsoft.com/scripting/use-an-easy-powershell-command-to-search-files-for-information/

    --------------------------------------

    If this is helpful please accept answer.

    0 comments No comments

  3. Rich Matheisen 47,901 Reputation points
    2022-09-25T02:29:55.167+00:00

    A regex that works for SSN is $SSNRegex = "^(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$".

    A regex to detect credit card numbers? Good luck! Which cards? Are you going to be able to keep up with new cards, cards that go out of business, and new number patterns that are introduced?

    You should start with a web search for "regex to find credit card number". You'll find examples and explanations of some of the difficulties in making sure you aren't find numbers that look like a credit card number.

    I remember doing something like this years ago and found thousands credit card numbers that just happened to be part numbers from manufacturers and equipment suppliers!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.