-
Notifications
You must be signed in to change notification settings - Fork 45
/
DocumentCMCB.ps1
9520 lines (9114 loc) · 554 KB
/
DocumentCMCB.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
#Requires -Version 4.0
#region help text
<#
.SYNOPSIS
Script attempts to fully document a Microsoft Configuration Manager environment.
.DESCRIPTION
This script will fully document a Configuration Manager environment. The original
script developed several years ago by David O'Brien required Microsoft Word to create
the documentation. This updated script is more detailed and outputs the documentation
in pure HTML. If you so desire, you can import this HTML report into Word for easier
editing.
.PARAMETER Title
The title you would like to use for this documentation. default is "Configuration Manager Site Documentation".
.PARAMETER FilePath
This is the path of the documentation file. By default, the file will be created in the same directory as the
where the script is currently located. And named CMDocumentation.html
.PARAMETER AddDateTime
Adds a date time stamp to the end of the file name.
Time stamp is in the format of yyyy-MM-dd_HHmm.
June 1, 2014 at 6PM is 2014-06-01_1800.
Output filename will be ReportName_2014-06-01_1800.html.
.PARAMETER CompanyName
This is the name of the company or organization that the documentation will be created for.
.PARAMETER CompanyLogo
This is a UNC or URL path to a image file jpg, or png to embed into the document on the title page. By default,
the Cyber Advisors logo will display.
.PARAMETER Author
This is the report author. Their name appears in the lower right corner of the title page.
.PARAMETER Vendor
This displays a company name in the lower right corner of the title page.
.PARAMETER ListAllInformation
Specifies whether the script should only output an overview of what is configured (like count of collections) or
a full output with verbose information. This includes: User & Device collections, Application, Packages, ADR Deployments,
Drivers in Driver packages, Task Squence Details
.PARAMETER ListAppDetails
Like ListAllInformation, but instead of all details, lists only Application Details.
.PARAMETER NoSqlDetail
Skip additional details from the SQL server. Useful when you do not have full database access to the SQL server (Normally requires access via SQL to the Master and CM database).
.PARAMETER SMSProvider
Some information rely on WMI queries that need to be executed against the SMS Provider directly.
Please specify as FQDN.
If not specified, it assumes localhost.
.PARAMETER UnknownClientSettings
With new releases of CM come new client settings. If this parameter is added, it will display raw
information for these client settings.
.PARAMETER SQLTimeout
The amount of time we should wait for a sql query to time out. Default is 300 seconds (5 minutes)
.PARAMETER MaskAccounts
This will mask about half of the account name in the documentation
.PARAMETER SQLCredential
If The SQL server is on a remote system, you can pass SQL credentials here.
.PARAMETER SkipRemoteServerDetails
Skip connecting directly to each remote site system server for hardware and OS details since this can take a long time on sites with many site systems
.PARAMETER RemoteDetailsSource
[WMI | HardwareInventory] The source of the details for the remote server. This can be either querying WMI on the remote server or by retrieving the details from the most recent hardware inventory.
.PARAMETER StyleSheet
This is the path to an external CSS file that will allow you to style the report in your own way. The style sheet will be embedded into the report.
.EXAMPLE
DocumentCMCB.ps1 -ListAllInformation
.EXAMPLE
DocumentCMCB.ps1 -CompanyLogo 'http://www.contoso.com/logo.jpg' -ListAllInformation
.EXAMPLE
DocumentCMCB.ps1 -CompanyLogo 'http://www.contoso.com/logo.jpg' -Author "Bugs Bunny" -Vendor "Acme" -ListAllInformation
.INPUTS
None. You cannot pipe objects to this script.
.OUTPUTS
No objects are output from this script.
This script creates a HTML document.
.NOTES
NAME: DocumentCMCB.ps1
VERSION: 4.1.3
AUTHOR: Paul Wetter
Based on original script developed by David O'Brien
CONTRIBUTOR: Florian Valente (BlackCatDeployment), Skatterbrainz, ChadSimmons, elgrunt0, CometCom1
LASTEDIT: May 11, 2022
#>
#endregion
#region script parameters
[CmdletBinding()]
Param(
[parameter(Mandatory=$False)]
[string]$CompanyName,
[parameter(Mandatory=$False)]
[string]$CompanyLogo = "https://wetterssource.com/sites/default/files/logo4_72.png",
[parameter(Mandatory=$False)]
[Switch]$ListAllInformation,
[parameter(Mandatory=$False)]
[Switch]$ListAppDetails,
[parameter(Mandatory=$False)]
[string]$Author="Paul Wetter",
[parameter(Mandatory=$False)]
[string]$Vendor = "Wetter's Source",
[parameter(Mandatory=$False)]
[String]$Title = "Configuration Manager Site Documentation",
[parameter(Mandatory=$False)]
[ValidateScript({$_ -match '\.html$'})]
[String]$FilePath = "CMDocumentation.html",
[parameter(Mandatory=$False)]
[string]$SMSProvider='localhost',
[parameter(Mandatory=$False)]
[Switch]$AddDateTime,
[parameter(Mandatory=$False)]
[switch]$UnknownClientSettings,
[parameter(Mandatory=$False)]
[switch]$NoSqlDetail,
[parameter(Mandatory=$False)]
[int]$SQLTimeout = 300,
[parameter(Mandatory=$False)]
[switch]$MaskAccounts,
#[parameter(Mandatory=$False)]
#[System.Management.Automation.PSCredential]$SQLCredential = [System.Management.Automation.PSCredential]::Empty,
[parameter(Mandatory=$False,HelpMessage="Skip connecting directly to each site system server for hardware and OS details")]
[switch]$SkipRemoteServerDetails,
[parameter(Mandatory=$False,HelpMessage="Defines the source for collecting the hardware details on the site servers. [WMI|HardwareInventory] HardwareInventory is the default")]
[ValidateSet("WMI","HardwareInventory")]
[string]$RemoteDetailsSource = 'HardwareInventory',
[parameter(Mandatory=$False,HelpMessage="CSS file path")]
[string]$StyleSheet = ""
)
#endregion script parameters
$DocumenationScriptVersion = '4.1.3'
If ([string]::IsNullOrEmpty($CompanyName)){
$ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition
function Get-DocumentCMCBUI {
param ()
$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MinWidth="450"
Width="575" SizeToContent="Height" Title="DocumentCMCB UI" Topmost="True">
<Grid Margin="10,10,3,10" HorizontalAlignment="center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="550"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Margin="0,0,0,10" Orientation="Vertical">
<Grid HorizontalAlignment="center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" TextAlignment="Center" FontWeight="UltraBold" FontSize="18">DocumentCMCB</TextBlock>
</Grid>
<TextBlock TextWrapping="Wrap" Width="Auto" Margin="5">
<Run>This is a front end to DocumentCMCB.ps1 and allows you to more easily make your documentation selections.</Run>
</TextBlock>
</StackPanel>
<Grid Grid.Row="1" Grid.Column="0" Margin="10,0,10,0" HorizontalAlignment="center" x:Name="Questions" Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"/>
<ColumnDefinition Width="425"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="Right">Title:</TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Name="StringTitle" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="300"/>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="right">Company Name:</TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" Name="StringCompanyName" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="220"/>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="right">Company Logo:</TextBlock>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
<TextBox Name="StringCompanyLogo" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="300"/>
<Button Name="BrowseLogo" MinWidth="50" Height="18" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalAlignment="center">Browse</Button>
</StackPanel>
<TextBlock Grid.Row="3" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="Right">Author:</TextBlock>
<TextBox Grid.Row="3" Grid.Column="1" Name="StringAuthor" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="150"/>
<TextBlock Grid.Row="4" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="Right">Vendor:</TextBlock>
<TextBox Grid.Row="4" Grid.Column="1" Name="StringVendor" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="150"/>
<TextBlock Grid.Row="5" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="right">Save File:</TextBlock>
<StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal">
<TextBox Name="StringSaveFile" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="300"/>
<Button Name="BrowseSave" MinWidth="50" Height="18" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalAlignment="center">Browse</Button>
</StackPanel>
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="Right">SMS Provider:</TextBlock>
<TextBox Grid.Row="6" Grid.Column="1" Name="SMSProvider" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="150"/>
</Grid>
<Grid Grid.Row="2" Grid.Column="0" Margin="10,0,10,10" HorizontalAlignment="center" x:Name="SwitchParams" Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="250"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Name="ListAllInformation" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="This provides deeper details on all settings within the site">Document Detailed Information</CheckBox>
<CheckBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Name="ListAppDetails" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="This will document full details on the applications in the site">Document details on application</CheckBox>
<CheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="UnknownClientSettings" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="If there are client settings that are not accounted for, checking this box will list the details on the unknown client settings.">Document unknown Client Settings</CheckBox>
<CheckBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Name="NoSqlDetail" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="Skips the data that is collected by querying the SQL database directly. Check this if you do not have full access to the SQL database.">Skip SQL queries</CheckBox>
<CheckBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Name="AddDateTime" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="Check this to append a timestamp to the end of the filename specified above">Add Data/Time to File name</CheckBox>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" ToolTip="Maximum amount of time that the script will allow queries to run">
<TextBlock Margin="30,10,0,2" HorizontalAlignment="right">SQL Timeout:</TextBlock>
<TextBox Name="SQLTimeout" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="50"/>
</StackPanel>
<CheckBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="SkipRemoteServerDetails" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="This can speed up the documentation process as this will skip reaching out to remote WMI on each site server for collecting additional details for the machine. It also helps if you do not have remote access to some of these machines.">Skip Remote Server Details</CheckBox>
<CheckBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Name="MaskAccounts" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalContentAlignment="center" IsChecked="false" ToolTip="Check this to mask the names of user accounts that are used in your CM site">Mask user accounts</CheckBox>
<ComboBox Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Name="ComboServerDetailType" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="150" ToolTip="Choosing the Source of HardwareInventory will significantly increase the time to collect this data but, will be limited to the accuracy of hardware inventory."></ComboBox>
</Grid>
<Grid Grid.Row="3" Grid.Column="0" Margin="10,0,10,0" HorizontalAlignment="center" x:Name="StyleSheet" Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"/>
<ColumnDefinition Width="425"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,10,0,2" HorizontalAlignment="right">Custom Style Sheet:</TextBlock>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<TextBox Name="StringStyleSheet" Margin="5,10,10,2" HorizontalAlignment="left" VerticalContentAlignment="center" Width="300"/>
<Button Name="BrowseStyleSheet" MinWidth="50" Height="18" Margin="5,10,10,2" HorizontalAlignment="Left" VerticalAlignment="center">Browse</Button>
</StackPanel>
</Grid>
<StackPanel Grid.Row="4" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0">
<Grid Margin="10,0,10,10" HorizontalAlignment="center" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"/>
<ColumnDefinition Width="125"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Row="2" Grid.Column="0" Name="ButCancel" IsCancel="True" MinWidth="80" Height="22" Margin="5" HorizontalAlignment="Right" Background="#ff9999">Exit</Button>
<Button Grid.Row="2" Grid.Column="2" Name="ButStart" IsCancel="False" MinWidth="100" Height="22" Margin="5" HorizontalAlignment="Left" Background="#33ff99">Start Documenting!</Button>
</Grid>
</StackPanel>
<Grid Grid.Row="5" Grid.Column="0" Margin="10,0,10,0" HorizontalAlignment="center" x:Name="Version" Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="530"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0" HorizontalAlignment="right" FontSize="10">Version: $DocumenationScriptVersion</TextBlock>
</Grid>
</Grid>
</Window>
"@
function Convert-XAMLtoWindow {
param
(
[Parameter(Mandatory=$true)]
[string]
$XAML
)
Add-Type -AssemblyName PresentationFramework
$reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
$result = [Windows.Markup.XAMLReader]::Load($reader)
$reader.Close()
$reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
while ($reader.Read())
{
$name=$reader.GetAttribute('Name')
if (!$name) { $name=$reader.GetAttribute('x:Name') }
if($name)
{$result | Add-Member NoteProperty -Name $name -Value $result.FindName($name) -Force}
}
$reader.Close()
$result
}
function Show-WPFWindow {
param
(
[Parameter(Mandatory)]
[Windows.Window]
$Window
)
$result = $null
$null = $window.Dispatcher.InvokeAsync{
$result = $window.ShowDialog()
Set-Variable -Name result -Value $result -Scope 1
}.Wait()
$result
}
function Get-FileName {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[System.IO.FileInfo]
$InitialDirectory = "$([environment]::getfolderpath("MyPictures"))",
[Parameter(Mandatory = $false)]
[String]
$Title = "Browse to company logo file:",
[Parameter(Mandatory = $false)]
[string]
$Filter = "Image Files|*.jpg;*.jpeg;*.png;"
)
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $InitialDirectory
$OpenFileDialog.filter = $Filter
$OpenFileDialog.Title = $Title
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
function New-FileName {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[System.IO.FileInfo]
$InitialDirectory = "$([environment]::getfolderpath("MyDocuments"))",
[Parameter(Mandatory = $false)]
[String]
$Title = "Browse to save HTML File:"
)
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
$SaveFileDialog.initialDirectory = $InitialDirectory
$SaveFileDialog.FileName = "CMDocumentation";
$SaveFileDialog.DefaultExt = "html";
$SaveFileDialog.filter = "HTML|*.html;"
$SaveFileDialog.Title = $Title
$SaveFileDialog.ShowDialog() | Out-Null
$SaveFileDialog.filename
}
$window = Convert-XAMLtoWindow -XAML $xaml
$window.StringTitle.Text = "Configuration Manager Site Documentation"
$window.StringVendor.Text = "Wetter's Source"
$window.StringAuthor.Text = "Paul Wetter"
$Window.StringSaveFile.Text = "$ScriptPath\CMDocumentation.html"
$Window.SMSProvider.Text = "localhost"
$Window.SQLTimeout.Text = "300"
$window.ComboServerDetailType.ItemsSource = @([PSCustomObject]@{Type = 'WMI'},[PSCustomObject]@{Type = 'HardwareInventory'})
$window.ComboServerDetailType.DisplayMemberPath = 'Type'
$window.ComboServerDetailType.SelectedValuePath = 'Type'
$window.ComboServerDetailType.SelectedValue = "$RemoteDetailsSource"
$window.SkipRemoteServerDetails.add_Click{
IF ($window.SkipRemoteServerDetails.IsChecked -eq $true) {
$window.ComboServerDetailType.IsEnabled = $false
#$window.ComboServerDetailType.SelectedValue = 'WMI'
} else {
$window.ComboServerDetailType.IsEnabled = $true
}
}
$window.BrowseLogo.add_Click{
$window.StringCompanyLogo.Text = Get-FileName -InitialDirectory "$([environment]::getfolderpath("MyPictures"))" -Title "Browse to company logo file:" -Filter "Image Files|*.jpg;*.jpeg;*.png;"
}
$window.BrowseStyleSheet.add_Click{
$window.StringStyleSheet.Text = Get-FileName -InitialDirectory "$([environment]::getfolderpath("MyDocuments"))" -Title "Browse to custom style sheet:" -Filter "Style Files|*.css;*.txt;"
}
$window.BrowseSave.add_Click{
$window.StringSaveFile.Text = New-FileName
}
$window.ListAllInformation.add_Click{
If ($window.ListAllInformation.IsChecked -eq $true){
$window.ListAppDetails.IsEnabled = $false
$window.ListAppDetails.IsChecked = $true
} else {
$window.ListAppDetails.IsEnabled = $true
}
}
$window.NoSqlDetail.add_Click{
If ($window.NoSqlDetail.IsChecked -eq $true){
$window.SQLTimeout.IsEnabled = $false
} else {
$window.SQLTimeout.IsEnabled = $true
}
}
$window.ButStart.add_Click{
if ([string]::IsNullOrEmpty($window.StringCompanyName.Text)){
$window.StringCompanyName.Background = "#ff9999"
write-host "EMPTY"
} else {
$window.StringCompanyName.Background = "white"
$script:Stuff = [ordered]@{
"CompanyName" = "$($window.StringCompanyName.Text)"
"CompanyLogo" = $(if ([string]::IsNullOrEmpty("$($window.StringCompanyLogo.Text)")){"https://wetterssource.com/sites/default/files/logo4_72.png"}else{"$($window.StringCompanyLogo.Text)"})
"ListAllInformation" = $Window.ListAllInformation.IsChecked
"ListAppDetails" = $Window.ListAppDetails.IsChecked
"Author" = "$($window.StringAuthor.Text)"
"Vendor" = "$($window.StringVendor.Text)"
"Title" = "$($window.StringTitle.Text)"
"FilePath" = "$($Window.StringSaveFile.Text)"
"SMSProvider" = "$($Window.SMSProvider.Text)"
"AddDateTime" = $Window.AddDateTime.IsChecked
"UnknownClientSettings" = $Window.UnknownClientSettings.IsChecked
"NoSqlDetail" = $Window.NoSqlDetail.IsChecked
"SQLTimeout" = "$($Window.SQLTimeout.Text)"
"MaskAccounts" = $Window.MaskAccounts.IsChecked
"SkipRemoteServerDetails" = $Window.SkipRemoteServerDetails.IsChecked
"RemoteDetailsSource" = $window.ComboServerDetailType.SelectedValue
"StyleSheet" = "$($window.StringStyleSheet.Text)"
}
$window.DialogResult = $false
}
}
$null = Show-WPFWindow -Window $window
}
Get-DocumentCMCBUI
If([string]::IsNullOrEmpty($Stuff)){break}
$Stuff.keys | ForEach-Object { Set-Variable -Name $_ -Value $Stuff["$_"]}
$Stuff.keys | ForEach-Object {"Variable [$_]: $((get-variable $_).value)"}
}
$CMPSSuppressFastNotUsedCheck = $true
Write-Verbose "CMPSSuppressFastNotUsedCheck set to $CMPSSuppressFastNotUsedCheck"
$Global:DocTOC = @()
$ScriptStartTime = Get-date
Write-host "Beginning Execution of version $DocumenationScriptVersion at: $($ScriptStartTime.ToShortTimeString())"
Write-Verbose "Beginning Execution of version $DocumenationScriptVersion at: $($ScriptStartTime.ToShortTimeString())"
#region HTML Writing Functions
Function Write-HTMLTable{
<#
.SYNOPSIS
This will take an input array of objects and turn it into an HTML table. Optionally, you can set a border for the table as well.
.PARAMETER InputObject
This is an array of objects that will be built into a HTML table.
.PARAMETER Padding
This is the amount of space in each field between the border and the text.
.PARAMETER Spacing
This is the amount of space between the borders of each field. Rarely anything other than zero (0).
.PARAMETER Level
This is the amount of space that the table will indented by.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLTable -InputObject $folders -Border 1
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is an array of objects that will be built into a HTML table.")]
$InputObject,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="If this table has a border, select the thickness here. Default:1")]
[int]$Border=1,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space in each field between the border and the text. Default:3")]
[int]$Padding=3,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space between the borders of each field. Rarely anything other than zero (0).")]
[int]$Spacing=0,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space that the table will indent by")]
[ValidateRange(0,6)]
[int]$Level=0,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the file that the HTML will be written to")]
[string]$File
)
$IndentClass = "Level$Level"
If ($InputObject) {
$table = $InputObject|ConvertTo-Html -Fragment
$table[0] = "<table cellpadding=$Padding cellspacing=$Spacing border=$Border class=`"$IndentClass`">"
$table = Convert-HTMLTags -InputString $table
} Else {
Write-Verbose 'Input object was empty outputting empty object paragraph text...'
Write-HTMLParagraph -Text 'There was no data to output from this query.' -Level $Level -File $file
}
If ($File) {$table | Out-File -filepath $File -Append}
Else {Return $table}
}
Function Write-HtmlList{
<#
.SYNOPSIS
This will take an input array of strings and turn them into an HTML list. This can be an ordered or unordered list (Numbered or bulleted).
.PARAMETER InputObject
This is an array of strings that will be made into the list.
.PARAMETER Title
This is the title text for the list.
.PARAMETER Description
This is html formatted test that will appear as a description or paragraph between the Title and actual list.
.PARAMETER Level
This is the amount of space that the list will indented by.
.PARAMETER Type
Choose ordered (OL) or unordered (UL) list. Unordered or bulleted is the default
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HtmlList -InputObject @('Red','Blue','Green','Yellow') -Title "Colors of the Rainbow" -Description "This is a <i>list</i> of colors in the rainbow." -level 1
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is an array of strings that will be made into the list.")]
$InputObject,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the title text for the list")]
$Title,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is html formatted test that will appear as a description or paragraph between the Title and actual list")]
$Description,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space that the list will indent by")]
[ValidateRange(0,6)]
[int]$Level=0,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="Choose ordered (OL) or unordered (UL) list. Unordered or bulleted is the default")]
[ValidateSet("OL","UL")]
[string]$Type="UL",
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the file that the HTML will be written to")]
[string]$File
)
$IndentClass = "Level$Level"
$IndentSubClass = "Level$($Level)Sub"
if ($Title)
{
$ListHTML = "<P class=`"$IndentClass`"><B>$($Title)</B>"
}Else{
$ListHTML = "<P class=`"$IndentClass`">"
}
if ($Description)
{
$ListHTML = $ListHTML + "<Div class=`"$IndentSubClass`">$Description</div>"
}
$GroupList = "<$Type class=`"$IndentClass`" style=`"margin-top:0px;`">"
If ($InputObject){
foreach ($Item in $InputObject)
{
$GroupList = $GroupList + "<LI>$Item</LI>"
}
}
$GroupList = $GroupList + "</$Type>"
$ListHTML = $ListHTML + $GroupList + "</P>"
If ($File) {$ListHTML | Out-File -filepath $File -Append}
Else {Return $ListHTML}
}
Function Write-HTMLHeading{
<#
.SYNOPSIS
This will format text as a heading in HTML. Optionally, it will add a page break to the heading so that when printing, it will appear on a new page.
.PARAMETER Text
This is the text that will appear inside the heading <H#`> tag
.PARAMETER Level
This is the level of the heading. 1,2,3,4,5,6 are valid options.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLHeading -Text "Test Heading 1"
.EXAMPLE
Write-HTMLHeading -Text "Test Heading 2" -Level 2
.EXAMPLE
Write-HTMLHeading -Text "Test Heading 3" -Level 3 -PageBreak
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the text that will appear inside the heading <H#`> tag")]
[string]$Text,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the level of the heading. 1,2,3,4,5,6 are valid options")]
[ValidateRange(1,6)]
[int]$Level=1,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This will style the HTML so it will print a page break")]
[switch]$PageBreak,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This will exclude the heading from the Table of Contents")]
[switch]$ExcludeTOC,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the file that the HTML will be written to")]
[string]$File
)
$PropertyID = $Text.Replace(' ','')
If(-not $ExcludeTOC){
$Global:DocTOC += New-Object -TypeName PSObject -Property @{'Level'=$level; 'Title'="$Text"; 'Id'=$PropertyID}
}
If ($PageBreak) {$HtmlClass = " Class=`"pagebreak`""}
$HeadLine = "<H$Level$HtmlClass id=`"$PropertyID`">$Text</H$Level>"
If ($File) {$HeadLine | Out-File -filepath $File -Append}
Else {Return $HeadLine}
}
Function Write-HTMLParagraph{
<#
.SYNOPSIS
This will format text as a paragraph in HTML. Optionally, it will allow you to indent the text to match the headings.
.PARAMETER Text
This is the text that will appear inside the heading <P> tag.
.PARAMETER Level
This is the amount of space that the paragraph will indent by. This is equivelent to the heading level indent +5.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLParagraph -Text "This is a bunch of text. It is a lot to go into the paragraph."
.EXAMPLE
Write-HTMLParagraph -Text "This is also a bunch of text. It is a lot to go into the paragraph as well." -Indent
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the text that will appear inside the <P> tag")]
[string]$Text,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the indent level of the paragraph")]
[ValidateRange(0,6)]
[int]$Level=0,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space that the table will indent by")]
[string]$File
)
$IndentClass = "Level$Level"
$Paragraph = "<P class=`"$IndentClass`">$(Convert-HTMLTags -InputString $Text)</p>"
If ($File) {$Paragraph | Out-File -filepath $File -Append}
Else {Return $Paragraph}
}
Function Write-HTMLHeader{
<#
.SYNOPSIS
This will write the header for the document/HTML. This also resets the document to no text (does not append to the document).
.PARAMETER Title
This is the title for the document.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLHeader -Title "This is a bunch of text for the title"
.EXAMPLE
Write-HTMLHeader -Title "This is also a bunch of text for the title" -file "C:\test.html"
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the text that will appear in title tag of the header")]
[string]$Title,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="Custom Style sheet to apply to the domcumenation")]
[string]$CssStyleFile,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the amount of space that the table will indent by")]
[string]$File
)
$Header = @()
$Header += "<html>"
$Header += "<Head>"
$Header += "<Title>$Title</Title>"
# if custom stylesheet parameter is invoked, apply to output, otherwise use hard-coded style
##Default Style
$DefaultStyle = @()
$DefaultStyle += "<Style>"
$DefaultStyle += 'H1 {background-color:royalblue; border-top: 1px solid black;}'
$DefaultStyle += 'H2 {margin-left:10px;background-color:steelblue; border-top: 1px solid black;}'
$DefaultStyle += 'H3 {margin-left:20px;background-color:lightblue; border-top: 1px solid black;}'
$DefaultStyle += 'H4 {margin-left:30px;background-color:lightsteelblue; border-top: 1px solid black;}'
$DefaultStyle += 'H5 {margin-left:40px;background-color:lightcyan; border-top: 1px solid black;}'
$DefaultStyle += 'H6 {margin-left:50px;background-color:lavender; border-top: 1px solid black;}'
$DefaultStyle += ".pagebreak { page-break-before: always; }"
$DefaultStyle += "TH {background-color:LightBlue;padding: 3px; border: 2px solid black;}"
$DefaultStyle += "TD {padding: 3px; border: 1px solid black;}"
$DefaultStyle += "TABLE {border-collapse: collapse;}"
$DefaultStyle += ""
$DefaultStyle += "/*Cover Styles*/"
$DefaultStyle += "TABLE.Cover TR {background-color:white}"
$DefaultStyle += ".Cover {width:100%;border: 0px}"
$DefaultStyle += ".CoverImage {width:auto; max-width:auto}"
$DefaultStyle += ".CoverImage {width:auto; max-width:auto}"
$DefaultStyle += ".CoverTitle {border: 0px;font-size:48pt}"
$DefaultStyle += ".CoverOrg {border: 0px;font-size:24pt;padding-left:10px}"
$DefaultStyle += ".CoverAuthor {border: 0px;font-size:18pt}"
$DefaultStyle += ".CoverVendor {border: 0px;font-size:24pt}"
$DefaultStyle += ".CoverVersion {border: 0px;font-size:11pt;padding-left:10px}"
$DefaultStyle += ""
$DefaultStyle += "/* These are the indent levels within the document */"
$DefaultStyle += ".Level0 {margin-left:0px;}"
$DefaultStyle += ".Level1 {margin-left:5px;}"
$DefaultStyle += ".Level2 {margin-left:15px;}"
$DefaultStyle += ".Level3 {margin-left:25px;}"
$DefaultStyle += ".Level4 {margin-left:35px;}"
$DefaultStyle += ".Level5 {margin-left:45px;}"
$DefaultStyle += ".Level6 {margin-left:55px;}"
$DefaultStyle += ".Level0Sub {margin-left:5px;}"
$DefaultStyle += ".Level1Sub {margin-left:10px;}"
$DefaultStyle += ".Level2Sub {margin-left:20px;}"
$DefaultStyle += ".Level3Sub {margin-left:30px;}"
$DefaultStyle += ".Level4Sub {margin-left:40px;}"
$DefaultStyle += ".Level5Sub {margin-left:50px;}"
$DefaultStyle += ".Level6Sub {margin-left:60px;}"
$DefaultStyle += "/* Color Coding the Detection Methods */"
$DefaultStyle += ".EdmOr{"
$DefaultStyle += "display: inline-block;"
$DefaultStyle += "font-weight: bolder;"
$DefaultStyle += "border-width: 1px;"
$DefaultStyle += "border-style: solid;"
$DefaultStyle += "padding: 5px;"
$DefaultStyle += "margin: 3px;"
$DefaultStyle += "background-color:rgb(195, 224, 241);"
$DefaultStyle += "}"
$DefaultStyle += ".EdmAnd{"
$DefaultStyle += "display: inline-block;"
$DefaultStyle += "font-weight: bolder;"
$DefaultStyle += "border-width: 1px;"
$DefaultStyle += "border-style: solid;"
$DefaultStyle += "padding: 5px;"
$DefaultStyle += "margin: 3px;"
$DefaultStyle += "background-color:rgb(195, 199, 202);"
$DefaultStyle += "}"
$DefaultStyle += ".EdmSetting{"
$DefaultStyle += "display: inline-block;"
$DefaultStyle += "font-weight:normal;"
$DefaultStyle += "border-width: 1px;"
$DefaultStyle += "border-style: dotted;"
$DefaultStyle += "padding: 5px;"
$DefaultStyle += "margin: 3px;"
$DefaultStyle += "background-color: rgb(198, 220, 228);"
$DefaultStyle += "}"
$DefaultStyle += "/* END Color Coding the Detection Methods */"
$DefaultStyle += ".ScriptDetectionMethod{"
$DefaultStyle += "display: inline-block;"
$DefaultStyle += "margin-left:95px;"
$DefaultStyle += "background-color:#eeeeee;"
$DefaultStyle += "border-width: 1px;"
$DefaultStyle += "border-style: solid;"
$DefaultStyle += "padding: 3px;"
$DefaultStyle += 'font-family: Consolas,"courier new";'
$DefaultStyle += "}"
$DefaultStyle += "</Style>"
##End Default Style
If($CssStyleFile){
If(Test-Path -Path $CssStyleFile) {
$StyleContent = Get-Content "$CssStyleFile"
Write-Verbose "Applying custom style sheet to document: $CssStyleFile"
$Header += "<Style>"
$Header += $StyleContent
$Header += "</Style>"
}
else {
Write-Verbose "Custom style sheet not found [$CssStyleFile]. Using default style."
$Header += $DefaultStyle
}
}Else{
$Header += $DefaultStyle
}
$Header += "</Head>"
$Header += "<Body>"
If ($File) {IF (Test-Path -Path $File) {Remove-Item -Path $File -Force}}
If ($File) {$header | Out-File -filepath $File -Append}
Else {Return $Header}
}
Function Write-HTMLFooter{
<#
.SYNOPSIS
This will write the end of the file for the document/HTML.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLFooter
.EXAMPLE
Write-HTMLFooter -file "C:\test.html"
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="The path to the file that we will write to.")]
[string]$File
)
$Footer += "</body></html>"
If ($File) {$Footer | Out-File -filepath $File -Append}
Else {Return $Footer}
}
Function Write-HTMLCoverPage{
<#
.SYNOPSIS
This will write the title/cover page for the document.
.PARAMETER Title
This is the title for the document.
.PARAMETER Author
This is the name of the person that is creating the document.
.PARAMETER Vendor
This is the name of the vendor that is creating the document.
.PARAMETER Org
This is the organization that the documentation was created for. Typically, they are the owner of the CM environment.
.PARAMETER ImagePath
This is the path to an optional image to put on the cover page. It will appear in the lower left of the body of the page.
.PARAMETER File
This is the file that the HTML will be written to.
.EXAMPLE
Write-HTMLCoverPage -Text "This is a bunch of text. It is a lot to go into the paragraph."
.EXAMPLE
Write-HTMLCoverPage -Text "This is also a bunch of text. It is a lot to go into the paragraph as well." -Indent
.NOTES
Author: Paul Wetter
Website:
Email: tellwetter[at]gmail.com
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the text that will appear in title tag of the header")]
[string]$Title,
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the text that will appear in the lower right by line")]
[string]$Author,
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This text will also appear in to lower right by line, below")]
[string]$Vendor,
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="Will apprear in the top left, below the title.")]
[string]$Org,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is an image logo that will be embedded in the title page")]
[string]$ImagePath,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the file that the HTML text will be written to")]
[string]$File
)
$Cover = @()
$Cover += "<Table border=0 cellspacing=0 cellpadding=0 class=`"Cover`">"
$Cover += "<TR><TD Height=50 VAlign=`"top`" align=`"left`" class=`"CoverTitle`">$Title</TD></TR>"
$Cover += "<TR><TD Height=20 VAlign=`"top`" align=`"left`" class=`"CoverOrg`">Report Prepared for: $Org</TD></TR>"
If ($ImagePath){
$ImageData=Convert-Image2Base64 -Path $ImagePath
}
If ($ImageData){
$Cover += "<TR><TD Height=680 VAlign=`"bottom`" align=`"right`" style=`"border: 0px`"><img class=`"CoverImage`" src=`"$ImageData`"></TD></TR>"
}Else{
$Cover += "<TR><TD Height=680 VAlign=`"top`" style=`"border: 0px`"> </TD></TR>"
}
$Cover += "<TR><TD Height=30 VAlign=`"top`" Align=`"right`" Class=`"CoverAuthor`">Report Prepared By: $Author</TD></TR>"
If ($Vendor) {$Cover += "<TR><TD Height=30 VAlign=`"top`" Align=`"right`" Class=`"CoverVendor`">$Vendor</TD></TR>"}
$Cover += "<TR><TD Height=20 VAlign=`"top`" align=`"right`" Class=`"CoverVersion`">Executed with script version: $DocumenationScriptVersion</TD></TR>"
$Cover += "</Table>"
If ($File) {$Cover | Out-File -filepath $File -Append}
Else {Return $Cover}
}
Function Convert-Image2Base64{
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName=$false,Mandatory=$true,ValueFromPipeline=$True,
HelpMessage="this is a path to either a file on the web or locally on the network to convert")]
[string]$Path
)
If (($Path -match '^[A-z]:\\.*(\.png|\.jpg)$') -or ($Path -match '^\\\\*\\.*(\.png|\.jpg)$')){
If (Test-Path -Path "filesystem::$Path"){
$EncodedImage = [convert]::ToBase64String((get-content $Path -encoding byte))
}else{
Write-Error "Path not found: $path"
Return $false
}
}
ElseIf ($Path -match '^http[s]://.*(\.png|\.jpg)$'){
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ext=$Path.Substring($Path.Length-4)
$tempfile = "${env:TEMP}\logo31337$ext"
if (Test-Path $tempfile) {Remove-Item -Path $tempfile -Force}
Try{Invoke-WebRequest -Uri $Path -OutFile $tempfile}
Catch{
Write-Host -ForegroundColor Yellow "Image for title page not found. Building title page without image."
Return $false
}
$EncodedImage = [convert]::ToBase64String((get-content $tempfile -encoding byte))
}else{
Write-Error "Path does not match pattern: $path"
Return $false
}
if($path.EndsWith(".jpg")){$imgtype = "jpg"}
elseif($path.EndsWith(".png")){$imgtype = "png"}
"data:image/$imgtype;base64,$EncodedImage"
}
function Write-HTMLTOC {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the array of texts that will make up the table of contents")]
$InputObject,
[Parameter(Mandatory=$true,ValueFromPipeline=$false,
HelpMessage="This is the file that the table of contents text will be written to")]
[string]$File,
[Parameter(Mandatory=$false,ValueFromPipeline=$false,
HelpMessage="This is the key text that the table of contents will be inserted after. Each line of the HTML file is searched to find this text. On each find, it will begin the insert.")]
[string]$InsertPoint = "TOC_Insert_Point"
)
$TOC = @()
foreach ($heading in $InputObject){
If ($heading.level -le 4){
Switch ($heading.level){
1{$Style = "Margin-left:10;Font-Size:16pt"}
2{$Style = "Margin-left:30"}
3{$Style = "Margin-left:50"}
4{$Style = "Margin-left:70"}
}
$TOC += "<DIV style=`"$Style`"><a href=`"`#$($heading.Id)`" style=`"color:blue`">$($heading.Title)</a></DIV>"
}
}
(Get-Content $File) |
Foreach-Object {
$_ # send the current line to output
if ($_ -match $InsertPoint)
{
#Add Lines after the selected pattern
$TOC
}
} | Set-Content $File