-
Notifications
You must be signed in to change notification settings - Fork 0
/
piiScan.ps1
62 lines (51 loc) · 2.4 KB
/
piiScan.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function findInMSWord(){
$Word = New-Object -ComObject Word.Application
$Document = $Word.Documents.Open("C:\Users\exaybachay\Programming\FindPII\PII.docx")
$Document.Paragraphs | ForEach-Object {
$_.Range.Text
}
#clean up stuff
#[System.Runtime.InteropServices.Marshal]::ReleaseComObject($range) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($document) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null
Remove-Variable -Name word
Remove-Variable -Name Document
[gc]::collect()
[gc]::WaitForPendingFinalizers()
}
function findInMSExcel(){
$path = (pwd).path
$excelSheets = Get-Childitem -Path $path -Include *.xls,*.xlsx -Recurse
$file = "$pwd\pii.xlsx"
$SearchString = "March 5, 1999"
$Excel = New-Object -ComObject Excel.Application
#$Excel.visible = $false
$Workbook = $Excel.Workbooks.Open($file)
$Worksheets = $Workbooks.worksheets
$Worksheet = $workbook.Worksheets.Item(1)
$Range = $Worksheet.Range("A:Z")
$Search = $Range.find($SearchString)
$excel.quit | out-null
#write-output $search
}
#create some patterns to look for
$ssn = '\b[0-9]{3}\-[0-9]{2}\-[0-9]{4}\b'
$bday = '\b[0-9]{1,2}(-|\/)[0-9]{1,2}(-|\/)[0-9]{4}\b'
$eurobday = '\b[0-9]{4}(-|\/)[0-9]{1,2}(-|\/)[0-9]{1,2}\b'
$fullbday = '\b(January|February|March|April|May|June|July|August|September|October|November|December)\s[0-9]{1,2}.\s[0-9][0-9][0-9][0-9]\b'
$eurofullbday = '\b[0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|October|November|December).\s[0-9][0-9][0-9][0-9]\b'
$allmatches = '(\b[0-9]{4}(-|\/)[0-9]{1,2}(-|\/)[0-9]{1,2}\b)|(\b[0-9]{1,2}(-|\/)[0-9]{1,2}(-|\/)[0-9]{4}\b)|(\b[0-9]{3}\-[0-9]{2}\-[0-9]{4}\b)|(\b(January|February|March|April|May|June|July|August|September|October|November|December)\s[0-9]{1,2}.\s[0-9][0-9][0-9][0-9]\b)|(\b[0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|October|November|December).\s[0-9][0-9][0-9][0-9]\b)'
#look for matches in current directory and subdirectories
#Get-ChildItem -Recurse | Get-Content | where { $_ | Select-String -Pattern $allmatches }
#look for matches in current directory and subdirectories
$files = Get-ChildItem -Recurse
foreach ($file in $files){
$foundinfo = Get-Content $file | where {
$_ | Select-String -Pattern $allmatches
}
if($foundinfo){
write-output $file.name
write-output $foundinfo
write-output " "
}
}