-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFind-InDocx.ps1
More file actions
61 lines (52 loc) · 1.44 KB
/
Find-InDocx.ps1
File metadata and controls
61 lines (52 loc) · 1.44 KB
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
<#
.SYNOPSIS
Searches Doc for words in (Parentheses)
.DESCRIPTION
Opens the file, searches for words, filters, outputs
.NOTES
File Name: Find-InDocx.ps1
Author: Jay Berkovitz
Link: github.com/heuricane/InfoSecTools/blob/master/Find-InDocx.ps1
.REQUIREMENTS
PS Version 5
Input Word Doc
#>
$list = @()
$output = @()
# -- Target the file -- #
$filePath = "C:\tmp\WSMIS_SAM_V6 0 5.4 SSP_V5_RMF_05172018_RWR.DOCX"
$doc = Get-ChildItem -path $filePath
# -- Open the File -- #
$application = New-Object -comobject word.application
$document = $application.documents.open("$doc", $false, $true)
$application.visible = $False
$matchCase = $false
$matchWholeWord = $false
$matchWildCards = $true
$matchSoundsLike = $false
$matchAllWordForms = $false
$forward = $true
$wrap = 1
$range = $document.content
$null = $range.movestart()
$string = $document.Content.Text
# -- Search for all words for words in Parentheses -- #
$count = ($string | Measure-Object -word).Words
1..$count | Foreach {
'(' + $String.Split('()')[$_] + ')'
$list += $String.Split('()')[$_]
}
# -- Remove blank entries and sentences in Parenthesis -- #
Foreach ($line in $list){
If ($line -ne ""){
If($line.length -lt 16){
$output += $line
}
}
}
# -- Saves the Output -- #
$save = (Get-Date).tostring("yyyyMMddhhmmss")
$outputPath = "C:\tmp\list-" +$save+ ".csv"
$output | Sort -Unique > $outputPath
$document.close()
$application.quit()