-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindPII.ps1
37 lines (30 loc) · 1.52 KB
/
FindPII.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$SSN = '^(?!(000|666|9))\d{3}-(?!00)\d{2}-(?!0000)\d{4}$'
$Amex = " ^3[47][0-9]{13}$"
$MC = "^(?: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}$"
$Visa = '^4[0-9]{12}(?:[0-9]{3})?$'
$Din = "^3(?:0[0-5]|[68][0-9])[0-9]{11}$"
$Disc = "^6(?:011|5[0-9]{2})[0-9]{12}$"
$JCB = "^(?:2131|1800|35\d{3})\d{11}$"
$pattern = "$Amex|$Din|$Disc|$JCB|$MC|$SSN|$Visa"
$Folder = "C:\PII"
$smtp = "mail.contoso.com"
$port = "<enter port number>"
$to = "[email protected]"
$from = "[email protected]"
$subject = "PII Report"
$attach = "$Folder\$env:COMPUTERNAME.csv"
New-Item -Path $Folder -ItemType Directory
Get-ChildItem -Path 'C:\Users\' -Recurse |
Where-Object {( ($_| Select-String -Pattern ($SSN) -SimpleMatch) -or
($_| Select-String -Pattern ($Visa) -SimpleMatch) -or
($_| Select-String -Pattern ($MC) -SimpleMatch) -or
($_| Select-String -Pattern ($Amex) -SimpleMatch) -or
($_| Select-String -Pattern ($Din) -SimpleMatch) -or
($_| Select-String -Pattern ($Disc) -SimpleMatch) -or
($_| Select-String -Pattern ($JCB) -SimpleMatch) )} | Select-Object $env:COMPUTERNAME,path | Export-Csv $Folder\$env:COMPUTERNAME.csv
# $visa -or $MC -or $Amex -or $Din -or $Disc -or $JCB)
#Send-MailMessage -SmtpServer $smtp -Port $port -To $to -From $from -Subject $subject -Attachments $attach
Where-Object {$_ -match $pattern} |
Select-Object $env:COMPUTERNAME,path |
Export-Csv $Folder\$env:COMPUTERNAME.csv
#Remove-Item -Path $Folder -Recurse -Force