You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Automate OpenXML. Excel, Word, and PowerPoint automation in PowerShell.
3
+
4
+
OpenXML is the standard used for Office documents.
5
+
6
+
You can think of it as a .zip in a trenchcoat.
7
+
8
+
Every part of an Excel, PowerPoint, or Word document is saved into an archive.
9
+
10
+
You can prove this to yourself by renaming any .docx file to .zip.
11
+
12
+
I sometimes call this the "zip epiphany", because it helps you understand how much technology is really a "zip in a trenchcoat".
13
+
14
+
(hint: it's _much_ more than just OpenXML files)
15
+
16
+
This module is here to help you automate, inspect, and understand OpenXML files.
17
+
### Installing and Importing
18
+
You can install OpenXML from the PowerShell gallery
19
+
20
+
~~~PowerShell
21
+
Install-Module OpenXML -Scope CurrentUser -Force
22
+
~~~
23
+
24
+
Once installed, you can simply `Import-Module`
25
+
~~~PowerShell
26
+
Import-Module OpenXML
27
+
~~~
28
+
29
+
### Commands
30
+
* Export-OpenXML
31
+
* Get-OpenXML
32
+
* Import-OpenXML
33
+
* Set-OpenXML
34
+
### Demos
35
+
~~~PowerShell
36
+
37
+
38
+
# Get text from a word document
39
+
Get-OpenXML ./Examples/HelloWorld.docx |
40
+
Select-Object -ExpandProperty Text
41
+
42
+
43
+
~~~
44
+
~~~PowerShell
45
+
46
+
47
+
# Get modification times
48
+
Get-OpenXML ./Examples/HelloWorld.docx |
49
+
Select-Object -Property Created, Modified
50
+
51
+
52
+
~~~
53
+
~~~PowerShell
54
+
55
+
# Get PowerPoint slides
56
+
Get-OpenXML ./Examples/ASlideDeck.pptx |
57
+
Select-Object -ExpandProperty Slides
58
+
59
+
~~~
60
+
~~~PowerShell
61
+
62
+
63
+
# Get text from PowerPoint
64
+
Get-OpenXML ./Examples/ASlideDeck.pptx |
65
+
Select-Object -ExpandProperty Text
66
+
67
+
68
+
~~~
69
+
~~~PowerShell
70
+
71
+
72
+
# Get worksheets from Excel
73
+
74
+
Get-OpenXML ./Examples/Sample.xlsx |
75
+
Select-Object -ExpandProperty Worksheets
76
+
77
+
78
+
~~~
79
+
~~~PowerShell
80
+
81
+
82
+
# Get cells from Excel
83
+
84
+
Get-OpenXML ./Examples/Sample.xlsx |
85
+
Select-Object -ExpandProperty Worksheets |
86
+
Select-Object -ExpandProperty Cell
87
+
88
+
89
+
~~~
90
+
~~~PowerShell
91
+
92
+
93
+
# Get formulas from Excel
94
+
95
+
Get-OpenXML ./Examples/Sum.xlsx |
96
+
Select-Object -ExpandProperty Worksheets |
97
+
Select-Object -ExpandProperty Formula
98
+
99
+
~~~
100
+
### Roadmap
101
+
While OpenXML has been around since 2006, this module is considerably younger.
102
+
103
+
It has a large amount of room to grow.
104
+
105
+
The primary goal for the forseeable future is to increase coverage of office features. If you would like to help, please consider [contributing](CONTRIBUTING.md).
106
+
### Security
107
+
OpenXML presents some unique security challenges.
108
+
109
+
This module makes OpenXML documents easier to read and write, which can be useful to both red and blue teams. Please see the [security guide](SECURITY.md) for more information.
$thisModulesFunctions=$ThisModule.ExportedFunctions.Keys|Sort-Object Name
51
+
foreach ($commandin$thisModulesFunctions) {
52
+
"* $($command)"
53
+
}
54
+
55
+
"### Demos"
56
+
57
+
$quickDemos= {
58
+
59
+
# Get text from a word document
60
+
Get-OpenXML ./Examples/HelloWorld.docx |
61
+
Select-Object-ExpandProperty Text
62
+
63
+
}, {
64
+
65
+
# Get modification times
66
+
Get-OpenXML ./Examples/HelloWorld.docx |
67
+
Select-Object-Property Created, Modified
68
+
69
+
}, {
70
+
# Get PowerPoint slides
71
+
Get-OpenXML ./Examples/ASlideDeck.pptx |
72
+
Select-Object-ExpandProperty Slides
73
+
},{
74
+
75
+
# Get text from PowerPoint
76
+
Get-OpenXML ./Examples/ASlideDeck.pptx |
77
+
Select-Object-ExpandProperty Text
78
+
79
+
}, {
80
+
81
+
# Get worksheets from Excel
82
+
83
+
Get-OpenXML ./Examples/Sample.xlsx |
84
+
Select-Object-ExpandProperty Worksheets
85
+
86
+
},{
87
+
88
+
# Get cells from Excel
89
+
90
+
Get-OpenXML ./Examples/Sample.xlsx |
91
+
Select-Object-ExpandProperty Worksheets |
92
+
Select-Object-ExpandProperty Cell
93
+
94
+
},{
95
+
96
+
# Get formulas from Excel
97
+
98
+
Get-OpenXML ./Examples/Sum.xlsx |
99
+
Select-Object-ExpandProperty Worksheets |
100
+
Select-Object-ExpandProperty Formula
101
+
}
102
+
103
+
104
+
foreach ($demoin$quickDemos) {
105
+
"~~~PowerShell"
106
+
"$demo"
107
+
"~~~"
108
+
}
109
+
110
+
"### Roadmap"
111
+
112
+
$roadmap=@'
113
+
While OpenXML has been around since 2006, this module is considerably younger.
114
+
115
+
It has a large amount of room to grow.
116
+
117
+
The primary goal for the forseeable future is to increase coverage of office features. If you would like to help, please consider [contributing](CONTRIBUTING.md).
118
+
'@
119
+
120
+
$roadmap
121
+
122
+
"### Security"
123
+
124
+
@'
125
+
OpenXML presents some unique security challenges.
126
+
127
+
This module makes OpenXML documents easier to read and write, which can be useful to both red and blue teams. Please see the [security guide](SECURITY.md) for more information.
0 commit comments