-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-ExchangeOrganizationReport.ps1
4807 lines (3452 loc) · 154 KB
/
Get-ExchangeOrganizationReport.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
This script fetches Exchange organization configuration data and exports it as Word document.
Thomas Stensitzki
THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
Version 0.92, 2023-03-16
Please use the GitHub repository for comments and issues.
.LINK
http://scripts.granikos.eu
.DESCRIPTION
This script reads Exchange Organization data and creates a single Microsoft Word
document. A later version will support exporting to an Html file.
The script requires an Exchange Management Shell for Exchange Server 2016 or
newer. Older EMS versions are not tested.
A locally installed version of Word is required, as plain Html export is not available.
The default file name is 'Exchange-Org-Report [TIMESTAMP].docx'
Most of the script requires only Exchange admin read-only access for the Exchange
organization. Querying address list information requires a membership in the
RBAC role "Address Lists".
The script queries hardware information from the Exchange server systems and requires
local administrator access to the computer systems.
The script is based on the ADDS_Inventory.ps1 PowerScript by
Carl Webster (https://github.com/CarlWebster/ActiveDirectory)
.NOTES
Requirements
- Windows Server 2016+, Windows 10
- Exchange Server Management Shell
- Word 2016+
- Required Exchange Role Assignment: Address Lists
- PowerShell Script saved with UTF-8 encoding as it contains certain UTF-8 characters
Revision History
--------------------------------------------------------------------------------
0.9 | Initial community pre-release
0.91 | Information about processor cores, memory, and page file size added
.PARAMETER CompanyName
The company name to use on the cover page.
.PARAMETER ExportTo
Target output format for the report.
Valid values: MSWord, Html
Default: MSWord
Html is currently not implemented
.PARAMETER CoverPage
The cover page name for use by Microsoft Word.
Only Word 2010 or newer are supported.
The available cover pages depend on the type of Word setup and locale installed on the system.
The default cover page is Sideline.
.PARAMETER CompanyAddress
Company address to use on the cover page, if the cover page contains an Address field.
.PARAMETER CompanyEMail
Company email address to use on the cover page, if the cover page contains an Email field.
.PARAMETER CompanyFax
Company fax number to use on the cover page, if the cover page contains a Fax field.
.PARAMETER CompanyPhone
Company phone number to use on the cover page, if the cover page contains a Phone field.
.PARAMETER ViewEntireForest
ViewEntireForest switch to set the scope for all Exchange cmdlets to view the entire Exchange Org
.PARAMETER ADForest
Specifies the Active Directory forest object by providing the forest name.
Currently not implemented. Reserved for future use.
.PARAMETER ADDomain
Specifies the Active Directory domain object by providing the doamin name.
Currently not implemented. Reserved for future use.
.PARAMETER IncludedDetails
Switch to include object detail information in the genereted report.
Including detailed object information might add a large number of
additional pages to the report.
Detailed information is included for the following objects:
- User Role Assignments
- Outlook Web App Policies
- Retention Policy Tags
- Mobile Device Policies
- Address Lists
- Malware Policies
- Transport Rules
- Email Address Policies
- Receive Connectors
- Send Connectors
- Database Availability Groups
.PARAMETER IncludePublicFolders
Switch to include detailed reporting on modern public folder hierarchy.
Using this switch results in an extended run of this scripts depending on
the size of public folder hierarchy.
Partially implemented.
.PARAMETER IncludeIntroduction
Switch to include an introductory text at the beginning of the report.
.PARAMETER SendMail
Switch to automatically send the generated report by email.
Currently not implemented.
.PARAMETER MailFrom
Email address of the report sender.
.PARAMETER MailTo
Email address of the report recipient.
.PARAMETER MailServer
Fully qualified domain name (FQDN) of the mail server for sending the report email.
.EXAMPLE
.\Get-ExchangeOrganizationReport.ps1 -ViewEntireForest:$true
Creates a Word report for the local Exchange Organization using the default values
defined on the parameters section of the PowerShell script.
.EXAMPLE
.\Get-ExchangeOrganizationReport.ps1 -Verbose
Creates a Microsoft Word report for the local Exchange Organization with a verbose output
to the current PowerShell session.
#>
[CmdletBinding()]
param(
[string]$CompanyName = 'ACME Inc.',
[ValidateSet('MSWord','Html')]
[string]$ExportTo = 'MSWord',
[string]$CoverPage = 'Sideline',
[string]$CompanyAddress = 'ACME Street, ACME City, 55555',
[string]$CompanyEmail = '[email protected]',
[string]$CompanyFax = '+XX FAX',
[string]$CompanyPhone = '+XX PHONE',
[switch]$ViewEntireForest,
[string]$ADForest = $Env:USERDNSDOMAIN,
[string]$ADDomain = '',
[switch]$IncludeDetails,
[switch]$IncludePublicFolders,
[switch]$IncludeIntroduction,
[string]$FolderPath = '',
[switch]$SendMail,
[string]$MailFrom = '[email protected]',
[string]$MailTo = '',
[string]$MailServer = ''
)
# Some variables to declare
$ScriptDir = Split-Path -Path $script:MyInvocation.MyCommand.Path
$ScriptName = $MyInvocation.MyCommand.Name
[Diagnostics.Stopwatch]$StopWatch = [Diagnostics.Stopwatch]::StartNew()
[string]$FileName = 'Exchange-Org-Report'
# Save current error action preference to restore the setting when script finishes
$SavedErrerActionPreference = $ErrorActionPreference
# Set error action preference
$ErrorActionPreference = 'SilentlyContinue'
# Default values
$NA = 'N/A'
$NotExported = 'Not yet exported to Word'
$GeneratedOn = (Get-Date -Format yyyy-MM-dd)
$ReportCulture = 'de-DE'
#region Type Definition
try {
Add-Type -TypeDefinition @"
using System.Collections;
namespace OrgReport {
public class ExchangeServerObject {
public string Name;
public OperatingSystemObject OperatingSystem;
}
public class OperatingSystemObject {
public OSVersionName OSVersion;
public string OSVersionBuild;
public string OSName;
public object OperatingSystem;
public string BootUpTimeInDays;
public string BootUpTimeInHours;
public string BootUpTimeInMinutes;
public string BootUpTimeInSeconds;
public string TimeZone;
public bool PendingReboot;
public System.Array TLSSettings;
public int ProcessorCores;
public double MemorySizeInBytes;
public double MemorySizeInGB;
public double PageFileSizeInMB;
}
public class ExchangeCertificateObject {
public string Server;
public string Subject;
public string Thumbprint;
public string CertifiateDomains;
public string Issuer;
public string PublicKeySize;
public string NotBeforeString;
//public DateTime NotBefore;
public string NotAfterString;
//public DateTime NotAfter;
public bool IsSelfSigned;
}
//enum for OSVersion
public enum OSVersionName {
Unknown,
Windows2008,
Windows2008R2,
Windows2012,
Windows2012R2,
Windows2016,
Windows2019
}
//enum Exchange Server CU Level
public enum ExchangeCULevel {
Unknown,
Preview,
RTM,
CU1,
CU2,
CU3,
CU4,
CU5,
CU6,
CU7,
CU8,
CU9,
CU10,
CU11,
CU12,
CU13,
CU14,
CU15,
CU16,
CU17,
CU18,
CU19,
CU20,
CU21,
CU22,
CU23
}
}
"@
}
catch {
# oops
Write-Warning -Message 'The script was unable to add custom classes to this PowerShell session. Please close this PowerShell session and open a new session.'
exit
}
finally {
# restore saved preferred error action
$ErrorActionPreference = $SavedErrerActionPreference
}
#end region
function Stop-Script {
if($ExportTo -eq 'MSWord') {
# Cleanup ComObject
$Script:Word.Quit()
Write-Verbose -Message ('{0}: System Cleanup' -f (Get-Date))
[Runtime.Interopservices.Marshal]::ReleaseComObject($Script:Word) | Out-Null
if(Test-Path -Path variable:global:word) {
Remove-Variable -Name Word -Scope Global -Force -Confirm:$false
}
}
# Call Garbage Collector
[gc]::Collect()
[gc]::WaitForPendingFinalizers()
Write-Verbose -Message ('{0}: Script has been aborted' -f (Get-Date))
$ErrorActionPreference = $SavedErrerActionPreference
Exit
}
function Show-ProgressBar {
[CmdletBinding()]
param(
[int]$PercentComplete,
[string]$Status = '',
[int]$Stage,
[string]$Activity = 'Get-ExchangeOrganizationReport'
)
$TotalStages = 5
Write-Progress -Id 1 -Activity $Activity -Status $Status -PercentComplete (($PercentComplete/$TotalStages)+(1/$TotalStages*$Stage*100))
}
#region registry functions
#http://stackoverflow.com/questions/5648931/test-if-registry-value-exists
# This Function just gets $True or $False
Function Test-RegistryValue {
[CmdletBinding()]
param(
[string]$Path,
[string]$Name
)
$key = Get-Item -LiteralPath $Path -ErrorAction SilentlyContinue
$key -and $Null -ne $key.GetValue($Name, $Null)
}
# Gets the specified local registry value or $Null if it is missing
Function Get-LocalRegistryValue {
[CmdletBinding()]
param (
[string]$Path,
[string]$Name
)
$key = Get-Item -LiteralPath $Path -ErrorAction SilentlyContinue
if($key) {
$key.GetValue($Name, $Null)
}
else {
$Null
}
}
function Test-CompanyName {
$RegistryPath = 'HKCU:\Software\Microsoft\Office\Common\UserInfo'
[bool]$Result = Test-RegistryValue -Path $RegistryPath -Name 'CompanyName'
if($Result) {
Return Get-LocalRegistryValue -Path $RegistryPath -Name 'CompanyName'
}
else {
$Result = Test-RegistryValue -Path $RegistryPath -Name 'Company'
if($Result) {
Return Get-LocalRegistryValue -Path $RegistryPath -Name 'Company'
}
else {
Return ''
}
}
}
Function Get-RegistryValue {
[CmdletBinding()]
Param(
[string]$Path,
[string]$Name,
[string]$ComputerName
)
# Gets the specified registry value or $Null if it is missing
if($ComputerName -eq $env:COMPUTERNAME -or $ComputerName -eq 'LocalHost') {
$key = Get-Item -LiteralPath $path -ErrorAction SilentlyContinue
if($key) {
Return $key.GetValue($Name, $Null)
}
else {
Return $Null
}
}
else {
#path needed here is different for remote registry access
$path1 = $Path.SubString(6)
$path2 = $Path1.Replace('\','\\')
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ComputerName)
$RegKey= $Reg.OpenSubKey($path2)
$Results = $RegKey.GetValue($Name)
if($Null -ne $Results) {
Return $Results
}
else {
Return $Null
}
}
}
#endregion
#region Word functions
function Test-WordPrerequisites {
if(!(Test-Path -Path REGISTRY::HKEY_CLASSES_ROOT\Word.Application)) {
# Word is not installed
$ErrorActionPreference = $SavedErrerActionPreference
Write-Warning -Message 'This script uses Microsoft Word, please install Microsoft Word or run the script on a computer with Microsoft Word installed.'
# exit script
Exit
}
else {
# get current session id
$SessionID = (Get-Process -Id $PID).SessionId
[bool]$IsRunning = ($null -ne ((Get-Process -Name 'WinWord' -ErrorAction SilentlyContinue) | Where-Object {$_.SessionId -eq $SessionID}) )
if($IsRunning) {
# There is an active Word instance
$ErrorActionPreference = $SavedErrerActionPreference
Write-Warning -Message 'Please close all running instances of Microsoft Word and restart the PowerShell script'
# exit script
Exit
}
}
}
function Set-WordHashTable {
[CmdletBinding()]
Param([string]$CultureCode)
#optimized by Michael B. SMith
# DE and FR translations for Word 2010 by Vladimir Radojevic
# DA translations for Word 2010 by Thomas Daugaard
# Citrix Infrastructure Specialist at edgemo A/S
# CA translations by Javier Sanchez
# CEO & Founder 101 Consulting
#ca - Catalan
#da - Danish
#de - German
#en - English
#es - Spanish
#fi - Finnish
#fr - French
#nb - Norwegian
#nl - Dutch
#pt - Portuguese
#sv - Swedish
#zh - Chinese
[string]$toc = $(
Switch ($CultureCode)
{
'ca-' { 'Taula automática 2'; Break }
'da-' { 'Automatisk tabel 2'; Break }
'de-' { 'Automatische Tabelle 2'; Break }
'en-' { 'Automatic Table 2'; Break }
'es-' { 'Tabla automática 2'; Break }
'fi-' { 'Automaattinen taulukko 2'; Break }
'fr-' { 'Table automatique 2'; Break } #changed 13-feb-2017 david roquier and samuel legrand
'nb-' { 'Automatisk tabell 2'; Break }
'nl-' { 'Automatische inhoudsopgave 2'; Break }
'pt-' { 'Sumário Automático 2'; Break }
'sv-' { 'Automatisk innehållsförteckning2'; Break }
'zh-' { '自动目录 2'; Break }
}
)
$Script:myHash = @{}
$Script:myHash.Word_TableOfContents = $toc
$Script:myHash.Word_NoSpacing = $wdStyleNoSpacing
$Script:myHash.Word_Heading1 = $wdStyleheading1
$Script:myHash.Word_Heading2 = $wdStyleheading2
$Script:myHash.Word_Heading3 = $wdStyleheading3
$Script:myHash.Word_Heading4 = $wdStyleheading4
$Script:myHash.Word_TableGrid = $wdTableGrid
}
Function Write-WordLine
#Function created by Ryan Revord
#@rsrevord on Twitter
#Function created to make output to Word easy in this script
#updated 27-Mar-2014 to include font name, font size, italics and bold options
{
[CmdletBinding()]
Param(
[int]$Style=0,
[int]$Tabs = 0,
[string]$Name = '',
[string]$Value = '',
[string]$FontName=$Null,
[int]$FontSize=0,
[bool]$Italics=$False,
[bool]$Boldface=$False,
[Switch]$NoNewLine)
#Build output style
[string]$output = ''
Switch ($style) {
0 {$Script:Selection.Style = $Script:MyHash.Word_NoSpacing; Break}
1 {$Script:Selection.Style = $Script:MyHash.Word_Heading1; Break}
2 {$Script:Selection.Style = $Script:MyHash.Word_Heading2; Break}
3 {$Script:Selection.Style = $Script:MyHash.Word_Heading3; Break}
4 {$Script:Selection.Style = $Script:MyHash.Word_Heading4; Break}
Default {$Script:Selection.Style = $Script:MyHash.Word_NoSpacing; Break}
}
#build # of tabs
While($tabs -gt 0) {
$output += "`t"
$tabs--
}
if(![String]::IsNullOrEmpty($fontName)) {
$Script:Selection.Font.name = $fontName
}
if($fontSize -ne 0) {
$Script:Selection.Font.size = $fontSize
}
if($italics -eq $True) {
$Script:Selection.Font.Italic = $True
}
if($boldface -eq $True) {
$Script:Selection.Font.Bold = $True
}
#output the rest of the parameters.
$output += $name + $value
$Script:Selection.TypeText($output)
#test for new WriteWordLine 0.
if(!($nonewline)) {
$Script:Selection.TypeParagraph()
}
}
function Test-WordCoverPage {
[CmdletBinding()]
Param(
[int]$WordVersion,
[string]$CoverPage,
[string]$CultureCode
)
$CoverPageArray = ''
Switch ($CultureCode) {
'ca-' {
if($WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'En bandes', 'Faceta', 'Filigrana',
'Integral', 'Ió (clar)', 'Ió (fosc)', 'Línia lateral',
'Moviment', 'Quadrícula', 'Retrospectiu', 'Sector (clar)',
'Sector (fosc)', 'Semàfor', 'Visualització principal', 'Whisp')
}
elseif($WordVersion -eq $wdWord2013) {
$CoverPageArray = ('Austin', 'En bandes', 'Faceta', 'Filigrana',
'Integral', 'Ió (clar)', 'Ió (fosc)', 'Línia lateral',
'Moviment', 'Quadrícula', 'Retrospectiu', 'Sector (clar)',
'Sector (fosc)', 'Semàfor', 'Visualització', 'Whisp')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alfabet', 'Anual', 'Austin', 'Conservador',
'Contrast', 'Cubicles', 'Diplomàtic', 'Exposició',
'Línia lateral', 'Mod', 'Mosiac', 'Moviment', 'Paper de diari',
'Perspectiva', 'Piles', 'Quadrícula', 'Sobri',
'Transcendir', 'Trencaclosques')
}
}
'da-' {
if($WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Bevægelse', 'Brusen', 'Facet', 'Filigran',
'Gitter', 'Integral', 'Ion (lys)', 'Ion (mørk)',
'Retro', 'Semafor', 'Sidelinje', 'Stribet',
'Udsnit (lys)', 'Udsnit (mørk)', 'Visningsmaster')
}
elseif($WordVersion -eq $wdWord2013) {
$CoverPageArray = ('Bevægelse', 'Brusen', 'Ion (lys)', 'Filigran',
'Retro', 'Semafor', 'Visningsmaster', 'Integral',
'Facet', 'Gitter', 'Stribet', 'Sidelinje', 'Udsnit (lys)',
'Udsnit (mørk)', 'Ion (mørk)', 'Austin')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Bevægelse', 'Moderat', 'Perspektiv', 'Firkanter',
'Overskrid', 'Alfabet', 'Kontrast', 'Stakke', 'Fliser', 'Gåde',
'Gitter', 'Austin', 'Eksponering', 'Sidelinje', 'Enkel',
'Nålestribet', 'Årlig', 'Avispapir', 'Tradionel')
}
}
'de-' {
if($WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Bewegung', 'Facette', 'Filigran',
'Gebändert', 'Integral', 'Ion (dunkel)', 'Ion (hell)',
'Pfiff', 'Randlinie', 'Raster', 'Rückblick',
'Segment (dunkel)', 'Segment (hell)', 'Semaphor',
'ViewMaster')
}
elseif($WordVersion -eq $wdWord2013) {
$CoverPageArray = ('Semaphor', 'Segment (hell)', 'Ion (hell)',
'Raster', 'Ion (dunkel)', 'Filigran', 'Rückblick', 'Pfiff',
'ViewMaster', 'Segment (dunkel)', 'Verbunden', 'Bewegung',
'Randlinie', 'Austin', 'Integral', 'Facette')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alphabet', 'Austin', 'Bewegung', 'Durchscheinend',
'Herausgestellt', 'Jährlich', 'Kacheln', 'Kontrast', 'Kubistisch',
'Modern', 'Nadelstreifen', 'Perspektive', 'Puzzle', 'Randlinie',
'Raster', 'Schlicht', 'Stapel', 'Traditionell', 'Zeitungspapier')
}
}
'en-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Banded', 'Facet', 'Filigree', 'Grid',
'Integral', 'Ion (Dark)', 'Ion (Light)', 'Motion', 'Retrospect',
'Semaphore', 'Sideline', 'Slice (Dark)', 'Slice (Light)', 'ViewMaster',
'Whisp')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alphabet', 'Annual', 'Austere', 'Austin', 'Conservative',
'Contrast', 'Cubicles', 'Exposure', 'Grid', 'Mod', 'Motion', 'Newsprint',
'Perspective', 'Pinstripes', 'Puzzle', 'Sideline', 'Stacks', 'Tiles', 'Transcend')
}
}
'es-' {
if($WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Con bandas', 'Cortar (oscuro)', 'Cuadrícula',
'Whisp', 'Faceta', 'Filigrana', 'Integral', 'Ion (claro)',
'Ion (oscuro)', 'Línea lateral', 'Movimiento', 'Retrospectiva',
'Semáforo', 'Slice (luz)', 'Vista principal', 'Whisp')
}
elseif($WordVersion -eq $wdWord2013) {
$CoverPageArray = ('Whisp', 'Vista principal', 'Filigrana', 'Austin',
'Slice (luz)', 'Faceta', 'Semáforo', 'Retrospectiva', 'Cuadrícula',
'Movimiento', 'Cortar (oscuro)', 'Línea lateral', 'Ion (oscuro)',
'Ion (claro)', 'Integral', 'Con bandas')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alfabeto', 'Anual', 'Austero', 'Austin', 'Conservador',
'Contraste', 'Cuadrícula', 'Cubículos', 'Exposición', 'Línea lateral',
'Moderno', 'Mosaicos', 'Movimiento', 'Papel periódico',
'Perspectiva', 'Pilas', 'Puzzle', 'Rayas', 'Sobrepasar')
}
}
'fi-' {
if($WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Filigraani', 'Integraali', 'Ioni (tumma)',
'Ioni (vaalea)', 'Opastin', 'Pinta', 'Retro', 'Sektori (tumma)',
'Sektori (vaalea)', 'Vaihtuvavärinen', 'ViewMaster', 'Austin',
'Kuiskaus', 'Liike', 'Ruudukko', 'Sivussa')
}
elseif($WordVersion -eq $wdWord2013) {
$CoverPageArray = ('Filigraani', 'Integraali', 'Ioni (tumma)',
'Ioni (vaalea)', 'Opastin', 'Pinta', 'Retro', 'Sektori (tumma)',
'Sektori (vaalea)', 'Vaihtuvavärinen', 'ViewMaster', 'Austin',
'Kiehkura', 'Liike', 'Ruudukko', 'Sivussa')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Aakkoset', 'Askeettinen', 'Austin', 'Kontrasti',
'Laatikot', 'Liike', 'Liituraita', 'Mod', 'Osittain peitossa',
'Palapeli', 'Perinteinen', 'Perspektiivi', 'Pinot', 'Ruudukko',
'Ruudut', 'Sanomalehtipaperi', 'Sivussa', 'Vuotuinen', 'Ylitys')
}
}
'fr-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('À bandes', 'Austin', 'Facette', 'Filigrane',
'Guide', 'Intégrale', 'Ion (clair)', 'Ion (foncé)',
'Lignes latérales', 'Quadrillage', 'Rétrospective', 'Secteur (clair)',
'Secteur (foncé)', 'Sémaphore', 'ViewMaster', 'Whisp')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alphabet', 'Annuel', 'Austère', 'Austin',
'Blocs empilés', 'Classique', 'Contraste', 'Emplacements de bureau',
'Exposition', 'Guide', 'Ligne latérale', 'Moderne',
'Mosaïques', 'Mots croisés', 'Papier journal', 'Perspective',
'Quadrillage', 'Rayures fines', 'Transcendant')
}
}
'nb-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Bevegelse', 'Dempet', 'Fasett', 'Filigran',
'Integral', 'Ion (lys)', 'Ion (mørk)', 'Retrospekt', 'Rutenett',
'Sektor (lys)', 'Sektor (mørk)', 'Semafor', 'Sidelinje', 'Stripet',
'ViewMaster')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alfabet', 'Årlig', 'Avistrykk', 'Austin', 'Avlukker',
'Bevegelse', 'Engasjement', 'Enkel', 'Fliser', 'Konservativ',
'Kontrast', 'Mod', 'Perspektiv', 'Puslespill', 'Rutenett', 'Sidelinje',
'Smale striper', 'Stabler', 'Transcenderende')
}
}
'nl-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Beweging', 'Facet', 'Filigraan', 'Gestreept',
'Integraal', 'Ion (donker)', 'Ion (licht)', 'Raster',
'Segment (Light)', 'Semafoor', 'Slice (donker)', 'Spriet',
'Terugblik', 'Terzijde', 'ViewMaster')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Aantrekkelijk', 'Alfabet', 'Austin', 'Bescheiden',
'Beweging', 'Blikvanger', 'Contrast', 'Eenvoudig', 'Jaarlijks',
'Krantenpapier', 'Krijtstreep', 'Kubussen', 'Mod', 'Perspectief',
'Puzzel', 'Raster', 'Stapels',
'Tegels', 'Terzijde')
}
}
'pt-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Animação', 'Austin', 'Em Tiras', 'Exibição Mestra',
'Faceta', 'Fatia (Clara)', 'Fatia (Escura)', 'Filete', 'Filigrana',
'Grade', 'Integral', 'Íon (Claro)', 'Íon (Escuro)', 'Linha Lateral',
'Retrospectiva', 'Semáforo')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alfabeto', 'Animação', 'Anual', 'Austero', 'Austin', 'Baias',
'Conservador', 'Contraste', 'Exposição', 'Grade', 'Ladrilhos',
'Linha Lateral', 'Listras', 'Mod', 'Papel Jornal', 'Perspectiva', 'Pilhas',
'Quebra-cabeça', 'Transcend')
}
}
'sv-' {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016) {
$CoverPageArray = ('Austin', 'Band', 'Fasett', 'Filigran', 'Integrerad', 'Jon (ljust)',
'Jon (mörkt)', 'Knippe', 'Rutnät', 'Rörelse', 'Sektor (ljus)', 'Sektor (mörk)',
'Semafor', 'Sidlinje', 'VisaHuvudsida', 'Återblick')
}
elseif($WordVersion -eq $wdWord2010) {
$CoverPageArray = ('Alfabetmönster', 'Austin', 'Enkelt', 'Exponering', 'Konservativt',
'Kontrast', 'Kritstreck', 'Kuber', 'Perspektiv', 'Plattor', 'Pussel', 'Rutnät',
'Rörelse', 'Sidlinje', 'Sobert', 'Staplat', 'Tidningspapper', 'Årligt',
'Övergående')
}
}
'zh-' {
if($WordVersion -eq $wdWord2010 -or $WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016)
{
$CoverPageArray = ('奥斯汀', '边线型', '花丝', '怀旧', '积分',
'离子(浅色)', '离子(深色)', '母版型', '平面', '切片(浅色)',
'切片(深色)', '丝状', '网格', '镶边', '信号灯',
'运动型')
}
}
Default {
if($WordVersion -eq $wdWord2013 -or $WordVersion -eq $wdWord2016)
{
$CoverPageArray = ('Austin', 'Banded', 'Facet', 'Filigree', 'Grid',
'Integral', 'Ion (Dark)', 'Ion (Light)', 'Motion', 'Retrospect',
'Semaphore', 'Sideline', 'Slice (Dark)', 'Slice (Light)', 'ViewMaster',
'Whisp')
}
elseif($WordVersion -eq $wdWord2010)
{
$CoverPageArray = ('Alphabet', 'Annual', 'Austere', 'Austin', 'Conservative',
'Contrast', 'Cubicles', 'Exposure', 'Grid', 'Mod', 'Motion', 'Newsprint',
'Perspective', 'Pinstripes', 'Puzzle', 'Sideline', 'Stacks', 'Tiles', 'Transcend')
}
}
}
if($CoverPageArray -contains $CoverPage)
{
$CoverPageArray = $Null
Return $True
}
else
{
$CoverPageArray = $Null
Return $False
}
}
Function Get-WordCultureCode {
[CmdletBinding()]
Param(
[int]$WordValue
)
#codes obtained from http://support.microsoft.com/kb/221435
#http://msdn.microsoft.com/en-us/library/bb213877(v=office.12).aspx
$CatalanArray = 1027
$ChineseArray = 2052,3076,5124,4100
$DanishArray = 1030
$DutchArray = 2067, 1043
$EnglishArray = 3081, 10249, 4105, 9225, 6153, 8201, 5129, 13321, 7177, 11273, 2057, 1033, 12297
$FinnishArray = 1035
$FrenchArray = 2060, 1036, 11276, 3084, 12300, 5132, 13324, 6156, 8204, 10252, 7180, 9228, 4108
$GermanArray = 1031, 3079, 5127, 4103, 2055
$NorwegianArray = 1044, 2068
$PortugueseArray = 1046, 2070
$SpanishArray = 1034, 11274, 16394, 13322, 9226, 5130, 7178, 12298, 17418, 4106, 18442, 19466, 6154, 15370, 10250, 20490, 3082, 14346, 8202
$SwedishArray = 1053, 2077
#ca - Catalan
#da - Danish
#de - German
#en - English
#es - Spanish
#fi - Finnish
#fr - French
#nb - Norwegian
#nl - Dutch
#pt - Portuguese
#sv - Swedish
#zh - Chinese
Switch ($WordValue)
{
{$CatalanArray -contains $_} {$CultureCode = 'ca-'}
{$ChineseArray -contains $_} {$CultureCode = 'zh-'}
{$DanishArray -contains $_} {$CultureCode = 'da-'}
{$DutchArray -contains $_} {$CultureCode = 'nl-'}
{$EnglishArray -contains $_} {$CultureCode = 'en-'}
{$FinnishArray -contains $_} {$CultureCode = 'fi-'}
{$FrenchArray -contains $_} {$CultureCode = 'fr-'}
{$GermanArray -contains $_} {$CultureCode = 'de-'}
{$NorwegianArray -contains $_} {$CultureCode = 'nb-'}
{$PortugueseArray -contains $_} {$CultureCode = 'pt-'}
{$SpanishArray -contains $_} {$CultureCode = 'es-'}
{$SwedishArray -contains $_} {$CultureCode = 'sv-'}
Default {$CultureCode = 'en-'}
}
Return $CultureCode
}
function Set-SectionTitle {
[CmdletBinding()]
param (
[string]$SectionTitle = '',
[int]$Style = 3,
[switch]$NewPage
)
if($NewPage) {
# Insert page break
$Script:Selection.InsertNewPage()
}
Write-WordLine -Style $Style -Tabs 0 -Name $SectionTitle
}
function Get-CompanyName {
[bool]$xResult = Test-RegistryValue -Path 'HKCU:\Software\Microsoft\Office\Common\UserInfo' -Name 'CompanyName'
if($xResult) {
Return Get-LocalRegistryValue -Path 'HKCU:\Software\Microsoft\Office\Common\UserInfo' -Name 'CompanyName'
}
else {
$xResult = Test-RegistryValue -Path 'HKCU:\Software\Microsoft\Office\Common\UserInfo' -Name 'Company'
if($xResult) {
Return Get-LocalRegistryValue -Path 'HKCU:\Software\Microsoft\Office\Common\UserInfo' -Name 'Company'
}
else {
Return ''
}
}
}
function Close-WordDocument {
# Reset Grammar and Spelling options back to their original settings befor closing Word
$Script:Word.Options.CheckGrammarAsYouType = $Script:CurrentGrammarOption
$Script:Word.Options.CheckSpellingAsYouType = $Script:CurrentSpellingOption
# Pepare file name
[string]$Script:FileName = ('{0}-{1}.docx' -f $FileName, (Get-Date -Format yyyy-MM-dd))
# default save in script folder
[string]$Script:FileNameWord = ('{0}' -f (Join-Path -Path $ScriptDir -ChildPath $Script:FileName))
if($FolderPath -ne '') {
# test custom folder path
if(Test-Path -Path $FolderPath) {
[string]$Script:FileNameWord = ('{0}' -f (Join-Path -Path $FolderPath -ChildPath $Script:FileName))
}
else {
Write-Warning -Message ('Custom folder path {0} does not exist. Script will save the report in the current script folder.' -f $FolderPath)
}
}
Write-Verbose -Message ('{0}: Saving Word file as: {1}' -f (Get-Date), $Script:FileNameWord)
if($Script:WordVersion -eq $wdWord2010) {
# Set default document type
$SaveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 'wdFormatDocumentDefault')
# Save Word document
$Script:WordDocument.SaveAs([REF]$Script:FileNameWord, [ref]$SaveFormat)
}
elseif($Script:WordVersion -eq $wdWord2013 -or $Script:WordVersion -eq $wdWord2016) {
# Save as Word Default document
$Script:WordDocument.SaveAs2([REF]$Script:FileNameWord, [ref]$wdFormatDocumentDefault)
}
# Close document
$Script:WordDocument.Close()
# Quit Word
$Script:Word.Quit()
# Finally, cleanup Word variable
[Runtime.Interopservices.Marshal]::ReleaseComObject($Script:Word) | Out-Null
if(Test-Path -Path variable:global:word) {
Remove-Variable -Name word -Scope Global 4>$Null
}
$SaveFormat = $Null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
}
function Select-WordEndOfDocument {
# Return focus to main document
$Script:WordDocument.ActiveWindow.ActivePane.view.SeekView = $wdSeekMainDocument
# Move to the end of the current document
$Script:Selection.EndKey($wdStory,$wdMove) | Out-Null
}
function New-MicrosoftWordDocument {
# Create a new ComObject instance of Microsoft Word
Write-Verbose -Message ('{0}: Creating Word ComObject' -f (Get-Date))
$Script:Word = New-Object -ComObject 'Word.Application' -ErrorAction SilentlyContinue 4>$Null
if(!$? -or $Null -eq $Script:Word) {
# Ooops, something went wrong
Write-Warning -Message 'The Word ComObject could not be created. You may need to install Word or repair an existing installation.'
$ErrorActionPreference = $SavedErrerActionPreference
Exit
}
# As we have a Word ComObject, we can continue
# Let's determine the language version
if((Get-ValidStateProp -Object $Script:Word -TopLevel Language -SecondLevel Value__ )) {
[int]$Script:WordLanguageValue = [int]$Script:Word.Language.Value__
}
else {
[int]$Script:WordLanguageValue = [int]$Script:Word.Language
}
Write-Verbose -Message ('{0}: Word language value is {1}' -f (Get-Date), $Script:WordLanguageValue)
$Script:WordCultureCode = Get-WordCultureCode -WordValue $Script:WordLanguageValue
Set-WordHashTable -CultureCode $Script:WordCultureCode
# Check Word product version
# Supported versions Word 2010 or newer
[int]$Script:WordVersion = [int]$Script:Word.Version
if($Script:WordVersion -eq $wdWord2016) {
$Script:WordProduct = 'Word 2016'
}
elseif($Script:WordVersion -eq $wdWord2013) {