forked from cameronjeff/OfficeMetadataRemove
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathword_Excel_remove.ps1
More file actions
149 lines (119 loc) · 3.91 KB
/
word_Excel_remove.ps1
File metadata and controls
149 lines (119 loc) · 3.91 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
##Script for removing metadata on Excel/Word data files
##Cameron McCoy / Jeff Flagg
##Computer Forensics Tool Project May 3 2013
##
##Sourced from Ed Wilson (Microsoft 8/10/2008)
## Scriptingguy1 (technet.com 9/7/2010)
####################################################
#enter selection
#ask user location of files to be sanitized
$path = Read-Host 'Enter folder location'
while ($continue -eq 100)
{
$continue = 100
#Adds microsoft office excel/word assembly
Add-Type -AssemblyName Microsoft.Office.Interop.Excel
Add-Type -AssemblyName Microsoft.Office.Interop.Word
# start variable declarations
$xlRemoveDocType = "Microsoft.Office.Interop.Excel.XlRemoveDocInfoType" -as [type]
$wrdRemoveDocType = "Microsoft.Office.Interop.Word.WdRemoveDocInfoType" -as [type]
#Find all files in chosen path
$excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse
$wordFiles = Get-ChildItem -Path $path -include *.doc, *.docx -recurse
#creates object to open
$objExcel = New-Object -ComObject excel.application
$objWord = New-Object -ComObject word.application
#makes sure new application does not appear on screen
$objExcel.visible = $false
$objWord.visible = $false
###Function Section#############################################
#Creates different colored lines for better readablity
Function funLine($strIN)
{
$strLine = "=" * $strIn.length
Write-Host -ForegroundColor Yellow "`n$strIN"
Write-Host -ForegroundColor Cyan $strLine
}
#Print function for options menu
Function funMetaData()
{
foreach($sFolder in $path)
{
$a = 0
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($sFolder)
foreach ($strFileName in $objFolder.items())
{ FunLine( "$($strFileName.name)")
for ($a ; $a -le 266; $a++)
{
if($objFolder.getDetailsOf($strFileName, $a))
{
$hash += @{ `
$($objFolder.getDetailsOf($objFolder.items, $a)) =`
$($objFolder.getDetailsOf($strFileName, $a))
} #end hash
$hash
$hash.clear()
} #end if
} #end for
$a=0
} #end foreach
} #end foreach
}
##############################################################################
#Print out Menu
$removal = Read-Host "
Are the files Excel Documents? type 1
Are the files Word Documents? type 2
Show all metadata associated with found files 3
Change path 4
To quit type 5
Please enter a selection number"
#What data should be deleted
if ($removal -eq 3)
{
funMetaData
continue
}
#Excel Option
if ($removal -eq 1)
{
#recursive loop to check evrey excel file
foreach($wb in $excelFiles)
{
$workbook = $objExcel.workbooks.open($wb.fullname)
"About to remove document information from $wb"
#to change what metadata is deleted, update "xlRDIALL" parameter (17 options)
$workbook.RemoveDocumentInformation($xlRemoveDocType::xlRDIAll)
$workbook.Save()
$objExcel.Workbooks.close()
}
$objExcel.Quit()
}
#Word Option
if ($removal -eq 2)
{#recursive loop to check evrey word file
foreach($wb in $WordFiles)
{
$document = $objWord.documents.open($wb.fullname)
"About to remove document information from $wb"
#to change what metadata is deleted, update "xlRDIALL" parameter (17 options)
$document.RemoveDocumentInformation($wrdRemoveDocType::wdRDIAll)
$document.Save()
$objWord.documents.close()
}
$objWord.Quit()
}
#Change $path option
if ($removal -eq 4)
{
$path = Read-Host 'Enter folder location'
continue
}
#Quit
if ($removal -eq 5)
{
$continue = 25
exit
}
}