-
Notifications
You must be signed in to change notification settings - Fork 0
/
iis-server-info-collector.vbs
1075 lines (852 loc) · 38.3 KB
/
iis-server-info-collector.vbs
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
Option Explicit
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const HKEY_LOCAL_MACHINE = &H80000002
Const CIMV2_NAMESPACE = "\ROOT\CIMV2"
Const WEB_ADMINISTRATION_NAMESPACE = "\ROOT\WebAdministration"
Const MICROSOFT_IISV2_NAMESPACE = "\ROOT\MicrosoftIISv2"
'SWbemSecurity Impersonation Level
'https://docs.microsoft.com/en-us/windows/win32/api/wbemdisp/ne-wbemdisp-wbemimpersonationlevelenum
Const wbemImpersonationLevelImpersonate = 3
'SWbemSecurity Authentication Level
'https://docs.microsoft.com/en-us/windows/win32/api/wbemdisp/ne-wbemdisp-wbemauthenticationlevelenum
Const wbemAuthenticationLevelPktPrivacy = 6
Dim strComputer
Dim strUser
Dim strPassword
Dim bolInSameDomain
bolInSameDomain = False
If (WScript.Arguments.Count > 0) Then
strComputer = WScript.Arguments.Item(0)
strUser = WScript.Arguments.Item(1)
strPassword = WScript.Arguments.Item(2)
If (StrComp(WScript.Arguments.Item(3), "y", 1) = 0) Then
bolInSameDomain = True
End If
Else
strComputer = "localhost"
End If
' ------------------ Collect Basic Computer Information ----------------------------
WScript.StdOut.WriteLine "------------------------------"
WScript.StdOut.WriteLine "| Basic Computer Information |"
WScript.StdOut.WriteLine "------------------------------"
Dim objComputerInfo : Set objComputerInfo = CollectBasicComputerInfo()
' ------------------ Collect .NET Framework Information ----------------------------
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine "| .NET Framework Installation |"
WScript.StdOut.WriteLine "-------------------------------"
CollectDotNetInfo()
' ------------------ Collect IIS Server Information --------------------------------
WScript.StdOut.WriteLine "-------------------"
WScript.StdOut.WriteLine "| IIS Information |"
WScript.StdOut.WriteLine "-------------------"
If (IsIISInstalled(objComputerInfo.OSName)) Then
Dim strIISProduct
strIISProduct = CollectIISServerInfo()
' ------------------ Collect IIS Application Pool Information ----------------------
WScript.StdOut.WriteLine "------------------------"
WScript.StdOut.WriteLine "| IIS Application Pool |"
WScript.StdOut.WriteLine "------------------------"
CollectIISApplicationPoolInfo(strIISProduct)
' ------------------ Collect Website and Web Application Information ---------------
WScript.StdOut.WriteLine "-------------------------------------------"
WScript.StdOut.WriteLine "| Website and Web Application Information |"
WScript.StdOut.WriteLine "-------------------------------------------"
Dim arrWebsiteAndAppList : Set arrWebsiteAndAppList = CollectWebSiteAndWebApplicationInfo(strIISProduct)
WriteCsvOutputFile True, strIISProduct, arrWebsiteAndAppList
Else
WScript.StdOut.WriteLine "IIS is not installed on this server."
WriteCsvOutputFile False, "", Nothing
End If
' ------------------ Write CSV output file -----------------------------------------
'
' ----------------------------------------------------------------------------------
' Functions
' ----------------------------------------------------------------------------------
Function WriteCsvOutputFile(bolIsIISInstalled, strIISVersion, arrWebsiteList)
Const ForWriting = 2
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objCsvFile : Set objCsvFile = objFSO.CreateTextFile("C:\iis-info\" & LCase(objComputerInfo.DNSHostName) & "_output.csv", ForWriting, True, False)
Dim obj
Dim strCsvOut
strCsvOut = "Host Name,OS Name,IIS Version,Website ID,Website Name,Website State,Website Physical Path,Website Binding," & _
"Website Application Pool,Website Application Pool State,Website CLR Version,Web App Name," & _
"Web App Physical Path,Web App Application Pool,Web App Application Pool State,Web App CLR Version"
objCsvFile.WriteLine strCsvOut
if (bolIsIISInstalled = False) Then
strCsvOut = objComputerInfo.DNSHostName & "," & objComputerInfo.OSName & ",Not Installed,,,,,,,,,,,,,"
objCsvFile.WriteLine strCsvOut
ElseIf (bolIsIISInstalled And (IsNull(arrWebsiteList) Or arrWebsiteList.Count = 0)) Then
Dim strIISValue
strIISValue = strIISProduct & " is installed but there isn't any website"
strCsvOut = objComputerInfo.DNSHostName & "," & objComputerInfo.OSName & "," & strIISValue & ",,,,,,,,,,,,,"
objCsvFile.WriteLine strCsvOut
Else
Dim objWebsite
For Each objWebsite In arrWebsiteList
strCsvOut = ""
strCsvOut = objComputerInfo.DNSHostName & "," & _
objComputerInfo.OSName & "," & _
strIISVersion & "," & _
objWebsite.ID & "," & _
objWebsite.Name & "," & _
objWebsite.State & "," & _
objWebsite.PhysicalPath & "," & _
objWebsite.Binding & "," & _
objWebsite.ApplicationPool.Name & "," & _
objWebsite.ApplicationPool.State & "," & _
objWebsite.ApplicationPool.ManagedRuntimeVersion
If (objWebsite.WebApplication Is Nothing) Then
strCsvOut = strCsvOut & ",,,,,"
Else
strCsvOut = strCsvOut & "," & _
objWebsite.WebApplication.Name & "," & _
objWebsite.WebApplication.PhysicalPath & "," & _
objWebsite.WebApplication.ApplicationPool.Name & "," & _
objWebsite.WebApplication.ApplicationPool.State & "," & _
objWebsite.WebApplication.ApplicationPool.ManagedRuntimeVersion
End If
objCsvFile.WriteLine strCsvOut
Next
End If
End Function
Function CollectWebSiteAndWebApplicationInfo(strIISProduct)
Dim arrWebsiteList : Set arrWebsiteList = CreateObject("System.Collections.ArrayList")
Dim strQuery
Dim objItem, colItems
Dim objWebsite
If (Instr(strIISProduct, "6.0")) Then
' Server State. Ref: https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524905(v=vs.90)
Dim dicServerState : Set dicServerState = CreateObject("Scripting.Dictionary")
dicServerState.Add 1, "Starting"
dicServerState.Add 2, "Started"
dicServerState.Add 3, "Stopping"
dicServerState.Add 4, "Stopped"
dicServerState.Add 5, "Pausing"
dicServerState.Add 6, "Paused"
dicServerState.Add 7, "Continuing"
Dim objSWbemServices: Set objSWbemServices = GetSWbemServices(MICROSOFT_IISV2_NAMESPACE)
strQuery = "SELECT Name, ServerState FROM IISWebServer"
Set colItems = objSWbemServices.ExecQuery(strQuery)
For Each objItem In colItems
Set objWebsite = New WebSiteInfo
Dim objWebServerSetting : Set objWebServerSetting = objSWbemServices.Get("IIsWebServerSetting='" & objItem.Name & "'")
Dim objWebVirtualDirSetting : Set objWebVirtualDirSetting = objSWbemServices.Get("IIsWebVirtualDirSetting='" & objItem.Name & "/ROOT'")
Dim objSvrBinding
Dim objScriptMap
Dim strSvrBinding
Dim strClrVersion
For Each objSvrBinding In objWebServerSetting.ServerBindings
strSvrBinding = objSvrBinding.Hostname & ":" & _
objSvrBinding.IP & ":" & _
objSvrBinding.Port & ";"
Next
For Each objScriptMap In objWebVirtualDirSetting.Properties_("ScriptMaps").Value
Dim strExtensions
Dim strScriptProcessor
strExtensions = objScriptMap.Extensions
strScriptProcessor = objScriptMap.ScriptProcessor
If (StrComp(strExtensions, ".aspx", 1) = 0) Then
If (Instr(strScriptProcessor, "v1.1")) Then
strClrVersion = "v1.1"
ElseIf (Instr(strScriptProcessor, "v2.0") Or Instr(strScriptProcessor, "v3.0") Or Instr(strScriptProcessor, "v3.5")) Then
strClrVersion = "v2.0"
ElseIf (Instr(strScriptProcessor, "v4.0") Or Instr(strScriptProcessor, "v4.5")) Then
strClrVersion = "v4.0"
End If
Exit For
End If
Next
With objWebsite
.ID = objItem.Name
.Name = objWebServerSetting.ServerComment
.State = dicServerState(objItem.ServerState)
.Binding = Left(strSvrBinding, Len(strSvrBinding) - 1)
.PhysicalPath = objWebVirtualDirSetting.Properties_("Path").Value
Set .ApplicationPool = GetApplicationPool(strIISProduct, "W3SVC/AppPools/" & objWebVirtualDirSetting.AppPoolId)(0)
' Hack!! In IIS6, .NET Runtime is set at website level but the ApplicationPool.ManagedRuntimeVersion
' is used for both display and export to CSV so just set its value here
.ApplicationPool.ManagedRuntimeVersion = strClrVersion
End With
'Note. There is no concept of web application under website in IIS6
'so no need to query for web application
arrWebsiteList.Add objWebsite
Next
Else
Dim dicSiteState : Set dicSiteState = CreateObject("Scripting.Dictionary")
dicSiteState.Add 0, "Starting"
dicSiteState.Add 1, "Started"
dicSiteState.Add 2, "Stopping"
dicSiteState.Add 3, "Stopped"
dicSiteState.Add 4, "Unknown"
strQuery = "SELECT * FROM Site"
Set colItems = ExecuteWMIQuery(WEB_ADMINISTRATION_NAMESPACE, strQuery)
For Each objItem In colItems
Set objWebsite = New WebsiteInfo
Dim strBinding
Dim objBinding
strBinding = ""
For Each objBinding In objItem.Bindings
strBinding = strBinding & objBinding.Protocol & " " & objBinding.BindingInformation & ";"
Next
With objWebsite
.ID = objItem.ID
.Name = objItem.Name
.State = dicSiteState(objItem.GetState)
.PhysicalPath = GetPhysicalPath(objItem.Name, "/", "/", strIISProduct)
.Binding = Left(strBinding, Len(strBinding) - 1)
Set .ApplicationPool = GetApplicationPoolBySiteNameAndPath(objItem.Name, "/", strIISProduct)
End With
arrWebsiteList.Add objWebsite
Dim colApps : Set colApps = objItem.Associators_("SiteContainsApplication")
Dim objApp
For Each objApp In colApps
If (StrComp(objApp.Path, "/", 1) <> 0) Then 'Ignore the Website itself
Dim objParentWebsite : Set objParentWebsite = New WebsiteInfo
Dim objWebApplication : Set objWebApplication = New WebApplicationInfo
With objParentWebsite
.ID = objWebsite.ID
.Name = objWebsite.Name
.State = objWebsite.State
.PhysicalPath = objWebsite.PhysicalPath
.Binding = objWebsite.Binding
Set .ApplicationPool = objWebsite.ApplicationPool
End With
With objWebApplication
.Name = Mid(objApp.Path, 2)
.PhysicalPath = GetPhysicalPath(objWebsite.Name, "/", objApp.Path, strIISProduct)
Set .ApplicationPool = GetApplicationPoolBySiteNameAndPath(objItem.Name, objApp.Path, strIISProduct)
End With
Set objParentWebsite.WebApplication = objWebApplication
arrWebsiteList.Add objParentWebsite
End If
Next
Next
End If
' Prepare and Display Output
Dim arrWebsiteIdList : Set arrWebsiteIdList = CreateObject("System.Collections.ArrayList")
Dim arrWebsiteNameList : Set arrWebsiteNameList = CreateObject("System.Collections.ArrayList")
Dim arrWebsiteStateList : Set arrWebsiteStateList = CreateObject("System.Collections.ArrayList")
Dim arrWebsitePhysicalPathList : Set arrWebsitePhysicalPathList = CreateObject("System.Collections.ArrayList")
Dim arrWebsiteBindingList : Set arrWebsiteBindingList = CreateObject("System.Collections.ArrayList")
Dim arrAppPoolList : Set arrAppPoolList = CreateObject("System.Collections.ArrayList")
Dim arrAppStateList : Set arrAppStateList = CreateObject("System.Collections.ArrayList")
Dim arrCLRVersionList : Set arrCLRVersionList = CreateObject("System.Collections.ArrayList")
Dim arrWebAppNameList : Set arrWebAppNameList = CreateObject("System.Collections.ArrayList")
Dim arrWebAppPhysicalPathList : Set arrWebAppPhysicalPathList = CreateObject("System.Collections.ArrayList")
Dim arrWebAppAppPoolList : Set arrWebAppAppPoolList = CreateObject("System.Collections.ArrayList")
Dim arrWebAppAppPoolStateList : Set arrWebAppAppPoolStateList = CreateObject("System.Collections.ArrayList")
Dim arrWebAppCLRVersionList : Set arrWebAppCLRVersionList = CreateObject("System.Collections.ArrayList")
Dim dicOutput : Set dicOutput = CreateObject("Scripting.Dictionary")
For Each objWebsite In arrWebsiteList
arrWebsiteIdList.Add objWebsite.ID
arrWebsiteNameList.Add objWebsite.Name
arrWebsiteStateList.Add objWebsite.State
arrWebsitePhysicalPathList.Add objWebsite.PhysicalPath
arrWebsiteBindingList.Add objWebsite.Binding
arrAppPoolList.Add objWebsite.ApplicationPool.Name
arrAppStateList.Add objWebsite.ApplicationPool.State
arrCLRVersionList.Add objWebsite.ApplicationPool.ManagedRuntimeVersion
If (objWebsite.WebApplication Is Nothing) Then
arrWebAppNameList.Add ""
arrWebAppPhysicalPathList.Add ""
arrWebAppAppPoolList.Add ""
arrWebAppAppPoolStateList.Add ""
arrWebAppCLRVersionList.Add ""
Else
arrWebAppNameList.Add objWebsite.WebApplication.Name
arrWebAppPhysicalPathList.Add objWebsite.WebApplication.PhysicalPath
arrWebAppAppPoolList.Add objWebsite.WebApplication.ApplicationPool.Name
arrWebAppAppPoolStateList.Add objWebsite.WebApplication.ApplicationPool.State
arrWebAppCLRVersionList.Add objWebsite.WebApplication.ApplicationPool.ManagedRuntimeVersion
End If
Next
dicOutput.Add "Website ID", arrWebsiteIdList
dicOutput.Add "Website Name", arrWebsiteNameList
dicOutput.Add "Website State", arrWebsiteStateList
dicOutput.Add "Website Physical Path", arrWebsitePhysicalPathList
dicOutput.Add "Website Binding", arrWebsiteBindingList
dicOutput.Add "Application Pool", arrAppPoolList
dicOutput.Add "CLR Version", arrCLRVersionList
dicOutput.Add "Web App Name", arrWebAppNameList
dicOutput.Add "Web App Physical Path", arrWebAppPhysicalPathList
dicOutput.Add "Web App Application Pool", arrWebAppAppPoolList
dicOutput.Add "Web App CLR Version", arrWebAppCLRVersionList
WriteMultipleOutputTable(dicOutput)
Set CollectWebSiteAndWebApplicationInfo = arrWebsiteList
End Function
Function GetApplicationPoolBySiteNameAndPath(strSiteName, strPath, strIISProduct)
Dim strQuery
Dim objItem, colItems
Dim strAppPoolName
strQuery = "SELECT ApplicationPool FROM Application WHERE SiteName='" & strSiteName & "' AND Path='" & strPath & "'"
Set colItems = ExecuteWMIQuery(WEB_ADMINISTRATION_NAMESPACE, strQuery)
For Each objItem In colItems
strAppPoolName = objItem.ApplicationPool
Next
Set GetApplicationPoolBySiteNameAndPath = GetApplicationPool(strIISProduct, strAppPoolName)(0)
End function
Function GetPhysicalPath(strSiteName, strPath, strAppPath, strIISProduct)
Dim strQuery, strRet
Dim objItem, colItems
If (Instr(strIISProduct, "6.0")) Then
strQuery = "SELECT * FROM IIsWebVirtualDirSetting WHERE SiteName='" & strSiteName & "'"
Set colItems = ExecuteWMIQuery(MICROSOFT_IISV2_NAMESPACE, strQuery)
Else
strQuery = "SELECT PhysicalPath FROM VirtualDirectory WHERE SiteName='" & _
strSiteName & "' AND ApplicationPath='" & strAppPath & "' AND Path='" &_
strPath & "'"
Set colItems = ExecuteWMIQuery(WEB_ADMINISTRATION_NAMESPACE, strQuery)
For Each objItem In colItems
strRet = objItem.PhysicalPath
Next
End If
GetPhysicalPath = strRet
End Function
Function CollectIISApplicationPoolInfo(strIISProduct)
Dim arrAppPoolList : Set arrAppPoolList = GetApplicationPool(strIISProduct, Null)
' Prepare and Display Output
Dim arrAppPoolNameList : Set arrAppPoolNameList = CreateObject("System.Collections.ArrayList")
Dim arrAppPoolStateList : Set arrAppPoolStateList = CreateObject("System.Collections.ArrayList")
Dim arrAppPoolStartModeList : Set arrAppPoolStartModeList = CreateObject("System.Collections.ArrayList")
Dim arrAppPoolPipelineModeList : Set arrAppPoolPipelineModeList = CreateObject("System.Collections.ArrayList")
Dim arrAppPoolRuntimeVersionList : Set arrAppPoolRuntimeVersionList = CreateObject("System.Collections.ArrayList")
Dim dicOutput : Set dicOutput = CreateObject("Scripting.Dictionary")
Dim objAppPool
For Each objAppPool In arrAppPoolList
arrAppPoolNameList.Add objAppPool.Name
arrAppPoolStateList.Add objAppPool.State
' Application Pool's StartMode is available in IIS 7.5 onward
If (Instr(strIISProduct, "6.0") Or Instr(strIISProduct, "7.0")) Then
arrAppPoolStartModeList.Add "N/A"
Else
arrAppPoolStartModeList.Add objAppPool.StartMode
End If
' Application Pool's ManagedPipelineMode and ManagedRuntimeVersion is available in IIS 7 onward
' (Managed) RuntimeVersion in IIS 6 is set at Web Site level
If (Instr(strIISProduct, "6.0")) Then
arrAppPoolPipelineModeList.Add "N/A"
arrAppPoolRuntimeVersionList.Add "N/A"
Else
arrAppPoolPipelineModeList.Add objAppPool.ManagedPipelineMode
arrAppPoolRuntimeVersionList.Add objAppPool.ManagedRuntimeVersion
End If
Next
dicOutput.Add "Name", arrAppPoolNameList
dicOutput.Add "Runtime Version", arrAppPoolRuntimeVersionList
dicOutput.Add "Status", arrAppPoolStateList
dicOutput.Add "Start Mode", arrAppPoolStartModeList
dicOutput.Add "Pipeline Mode", arrAppPoolPipelineModeList
WriteMultipleOutputTable(dicOutput)
End Function
Function GetApplicationPool(strIISProduct, strPoolName)
Dim dicStartMode : Set dicStartMode = CreateObject("Scripting.Dictionary")
Dim dicPoolState : Set dicPoolState = CreateObject("Scripting.Dictionary")
Dim dicIIS6PoolState : Set dicIIS6PoolState = CreateObject("Scripting.Dictionary")
Dim dicManagedPipelineMode : Set dicManagedPipelineMode = CreateObject("Scripting.Dictionary")
dicStartMode.Add 0, "OnDemand"
dicStartMode.Add 1, "AlwaysRunning"
dicPoolState.Add 0, "Starting"
dicPoolState.Add 1, "Started"
dicPoolState.Add 2, "Stopping"
dicPoolState.Add 3, "Stopped"
dicPoolState.Add 4, "Unknown"
' The document here doesn't tell values mapping. These mapping came up from testing and observed
' https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms525967(v=vs.90)
dicIIS6PoolState.Add 2, "Running"
dicIIS6PoolState.Add 4, "Stopped"
dicManagedPipelineMode.Add 0, "Integrated"
dicManagedPipelineMode.Add 1, "Classic"
Dim strQuery
Dim colItems
Dim objItem
Dim objAppPool
Dim arrAppPoolList : Set arrAppPoolList = CreateObject("System.Collections.ArrayList")
If (Instr(strIISProduct, "6.0")) Then
strQuery = "SELECT * FROM IIsApplicationPoolSetting"
If (Not IsNull(strPoolName)) Then
strQuery = strQuery & " WHERE NAME='" & strPoolName & "'"
End If
Set colItems = ExecuteWMIQuery(MICROSOFT_IISV2_NAMESPACE, strQuery)
For Each objItem In colItems
Set objAppPool = New ApplicationPoolInfo
Dim arrPoolName
arrPoolName = Split(objItem.Name, "/")
With objAppPool
.Name = arrPoolName(Ubound(arrPoolName))
.State = dicIIS6PoolState.Item(objItem.AppPoolState)
End With
arrAppPoolList.Add objAppPool
Next
Else
strQuery = "SELECT * FROM ApplicationPool"
If (Not IsNull(strPoolName)) Then
strQuery = strQuery & " WHERE NAME='" & strPoolName & "'"
End If
Set colItems = ExecuteWMIQuery(WEB_ADMINISTRATION_NAMESPACE, strQuery)
For Each objItem In colItems
Set objAppPool = New ApplicationPoolInfo
On Error Resume Next
With objAppPool
.Name = objItem.Name
.State = dicPoolState.Item(objItem.GetState())
.StartMode = dicStartMode.Item(objItem.StartMode) ' Available in IIS 7.5 onward
.ManagedPipelineMode = dicManagedPipelineMode.Item(objItem.ManagedPipelineMode)
.ManagedRuntimeVersion = objItem.ManagedRuntimeVersion
End With
Err.Clear
arrAppPoolList.Add objAppPool
Next
End If
Set GetApplicationPool = arrAppPoolList
End Function
Function CollectBasicComputerInfo()
Dim objComputerInfo : Set objComputerInfo = New ComputerInfo
Dim strQuery
Dim colItems
Dim objItem
strQuery = "SELECT * FROM Win32_ComputerSystem"
Set colItems = ExecuteWMIQuery(CIMV2_NAMESPACE, strQuery)
For Each objItem In colItems
objComputerInfo.Name = objItem.Name
objComputerInfo.DNSHostName = objItem.DNSHostName
objComputerInfo.Domain = objItem.Domain
Exit For
Next
strQuery = "SELECT * FROM Win32_OperatingSystem"
Set colItems = ExecuteWMIQuery(CIMV2_NAMESPACE, strQuery)
For Each objItem In colItems
objComputerInfo.OSName = objItem.Caption
objComputerInfo.OSVersion = objItem.Version
objComputerInfo.OSBuildNumber = objItem.BuildNumber
' The WMI object in Windows Server 2003 doesn't have OSArchitecture attribute
If (InStr(objItem.Caption, "2003")) Then
objComputerInfo.OSArchitecture = "N/A"
Else
objComputerInfo.OSArchitecture = objItem.OSArchitecture
End If
Exit For
Next
Dim objOutput : Set objOutput = CreateObject("Scripting.Dictionary")
objOutput.Add "Computer Name", objComputerInfo.Name
objOutput.Add "DNS Host Name", objComputerInfo.DNSHostName
objOutput.Add "Domain", objComputerInfo.Domain
objOutput.Add "OS Name", objComputerInfo.OSName
objOutput.Add "OS Version", objComputerInfo.OSVersion
objOutput.Add "OS Build Number", objComputerInfo.OSBuildNumber
objOutput.Add "OS Architecture", objComputerInfo.OSArchitecture
WriteSingleOutputTable(objOutput)
Set CollectBasicComputerInfo = objComputerInfo
End Function
Function CollectIISServerInfo()
Dim strKeyPath
Dim strfileVersion
Dim strProduct
Dim strInstallPath
Dim strVersion
Dim objReg
Dim objOutput
strKeyPath = "SOFTWARE\Microsoft\InetStp"
Set objReg = GetStdRegProvObject()
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, "SetupString", strProduct
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, "InstallPath", strInstallPath
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, "VersionString", strVersion
strFileVersion = CreateObject("Scripting.FileSystemObject").GetFileVersion(strInstallPath & "\w3wp.exe")
Set objOutput = CreateObject("Scripting.Dictionary")
objOutput.Add "Product", strProduct
objOutput.Add "Product Version", strFileVersion
objOutput.Add "Version String", strVersion
objOutput.Add "Install Path", strInstallPath
WriteSingleOutputTable(objOutput)
CollectIISServerInfo = strProduct
End Function
Function CollectDotNetInfo()
Dim strKeyPath
strKeyPath = "SOFTWARE\Microsoft\NET Framework Setup\NDP"
Dim objReg : Set objReg = GetStdRegProvObject()
Dim colDotNetVersionItems : Set colDotNetVersionItems = CreateObject("Scripting.Dictionary")
Dim arrDotNetVersionList : Set arrDotNetVersionList = CreateObject("System.Collections.ArrayList")
Dim objRegExp : Set objRegExp = New RegExp
With objRegExp
.Pattern = "^[vCFW]"
.IgnoreCase = False
.Global = False
End With
GetAllDotNetVersion objReg, objRegExp, strKeyPath, arrDotNetVersionList
' Prepare and Display Output
Dim dicOutput : Set dicOutput = CreateObject("Scripting.Dictionary")
Dim arrNameList : Set arrNameList = CreateObject("System.Collections.ArrayList")
Dim arrVersionList : Set arrVersionList = CreateObject("System.Collections.ArrayList")
Dim objDotNet
For Each objDotNet In arrDotNetVersionList
arrNameList.Add objDotNet.Name
arrVersionList.Add objDotNet.Version
Next
dicOutput.Add ".NET Framework", arrNameList
dicOutput.Add "Version", arrVersionList
WriteMultipleOutputTable(dicOutput)
End Function
Function GetAllDotNetVersion(objReg, objRegExp, strKeyPath, arrDotNetVersionList)
Dim arrSubKeys
Dim strSubKey, strFullPath, strValue
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
If (Not IsNull(arrSubKeys)) Then
For Each strSubKey In arrSubKeys
strFullPath = strKeyPath & "\" & strSubkey
If (objRegExp.Test(strSubkey)) Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, strFullPath, "Version", strValue
If Not IsNull(strValue) Then
Dim objDotNet : Set objDotNet = New DotNetFrameworkInfo
objDotNet.Name = strSubKey
objDotNet.Version = strValue
arrDotNetVersionList.Add objDotNet
End If
End If
GetAllDotNetVersion objReg, objRegExp, strFullPath, arrDotNetVersionList
Next
End If
End Function
Function IsIISInstalled(strOSName)
Dim bolRet
Dim strQuery
Dim strKeyPath
Dim strValue
bolRet = False
' Win32_ServerFeature class is not available in ROOT\CIMV2 namespace in Windows Server 2003
' Need to check from Registry instead
If (InStr(strOSName, "2003") > 0) Then
strKeyPath = "SOFTWARE\Microsoft\InetStp"
Dim objReg : Set objReg = GetStdRegProvObject()
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, "InstallPath", strValue
If (Not IsNull(strValue)) Then
bolRet = True
End If
Else
strQuery = "SELECT * FROM Win32_ServerFeature WHERE Name LIKE 'Web Server%'"
Dim colItems : Set colItems = ExecuteWMIQuery(CIMV2_NAMESPACE, strQuery)
' It's weird that an error occurred when use colItems.Count
' Microsoft VBScript runtime error: Object doesn't support this property or method: 'colItems.Count'
' While the Doc says 'Count' is there (https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemobjectset)
' So this is bad code but no choice though
Dim objItem
For Each objItem in colItems
bolRet = True
Next
End If
IsIISInstalled = bolRet
End Function
Function ExecuteWMIQuery(strNamespace, strQueryStatement)
Set ExecuteWMIQuery = GetSWbemServices(strNamespace).ExecQuery(strQueryStatement, "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
End Function
Function GetStdRegProvObject()
SET GetStdRegProvObject = GetSWbemServices("\ROOT\DEFAULT").Get("StdRegProv")
End Function
Function GetSWbemServices(strNamespace)
Dim objSWbemServices
If (StrComp(strComputer, "localhost", 1) = 0 Or bolInSameDomain) Then
Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & strComputer & strNamespace)
Else
'Remote connection example https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemlocator-connectserver#examples
Dim objSWbemLocator : Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, strNamespace, strUser, strPassword)
objSWbemServices.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objSWbemServices.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
End If
Set GetSWbemServices = objSWbemServices
End Function
Function WriteSingleOutputTable(objOutput)
Dim strColumnHeader, strColumnHeaderLine, strColumnValue, strOut
Dim iColumnHeaderLength, iColumnValueLength, iColumnHeaderWidth, iColumnValueWidth
strColumnHeader = ""
strColumnHeaderLine = ""
strColumnValue = ""
Dim strKey
Dim iSpace
iSpace = 2
For Each strKey In objOutput.Keys
iColumnHeaderLength = Len(strKey)
iColumnValueLength = Len(objOutput.Item(strKey))
iColumnHeaderWidth = 0
iColumnValueWidth = 0
If (iColumnValueLength > iColumnHeaderLength) Then
iColumnHeaderWidth = (iColumnValueLength - iColumnHeaderLength) + iSpace
iColumnValueWidth = iSpace
ElseIf (iColumnValueLength = iColumnHeaderLength) Then
iColumnHeaderWidth = iSpace
iColumnValueWidth = iSpace
Else
iColumnHeaderWidth = iSpace
iColumnValueWidth = (iColumnHeaderLength - iColumnValueLength) + iSpace
End If
strColumnHeader = strColumnHeader & LeftJustified(strKey, iColumnHeaderWidth)
strColumnHeaderLine = strColumnHeaderLine & LeftJustified(GenerateDashLine(Len(strKey)), iColumnHeaderWidth)
strColumnValue = strColumnValue & LeftJustified(objOutput.Item(strKey), iColumnValueWidth)
Next
strOut = vbCrLf & strColumnHeader & vbCrLf & strColumnHeaderLine & vbCrLf & strColumnValue & vbCrLf
WScript.StdOut.WriteLine strOut
End Function
Function WriteMultipleOutputTable(dicOutput)
Dim strColumnHeader
Dim strColumnHeaderLine
Dim strColumnValue
Dim strColHeaderKey
Dim iColumnHeaderLength
Dim iColumnValueLength
Dim iColumnHeaderWidth
Dim iColumnValueWidth
Dim iMaxColumnValueLength
Dim iMaxValueCount
Dim iSpace
iSpace = 2
strColumnHeader = ""
strColumnHeaderLine = ""
strColumnValue = ""
For Each strColHeaderKey In dicOutput.Keys
iColumnHeaderLength = Len(strColHeaderKey)
iMaxColumnValueLength = GetMaxValueLength(dicOutput.Item(strColHeaderKey))
iMaxValueCount = dicOutput.Item(strColHeaderKey).Count
iColumnHeaderWidth = 0
If (iMaxColumnValueLength > iColumnHeaderLength) Then
iColumnHeaderWidth = (iMaxColumnValueLength - iColumnHeaderLength) + iSpace
ElseIf (iMaxColumnValueLength = iColumnHeaderLength) Then
iColumnHeaderWidth = iSpace
Else
iColumnHeaderWidth = iSpace
End If
strColumnHeader = strColumnHeader & LeftJustified(strColHeaderKey, iColumnHeaderWidth)
strColumnHeaderLine = strColumnHeaderLine & LeftJustified(GenerateDashLine(Len(strColHeaderKey)), iColumnHeaderWidth)
Next
Dim strOut
Dim iIndex
For iIndex = 0 To (iMaxValueCount - 1) Step 1
For Each strColHeaderKey In dicOutput.Keys
Dim strValue
iMaxColumnValueLength = GetMaxValueLength(dicOutput.Item(strColHeaderKey))
if (iMaxColumnValueLength < Len(strColHeaderKey)) Then
iMaxColumnValueLength = Len(strColHeaderKey)
End If
strValue = dicOutput.Item(strColHeaderKey)(iIndex)
iColumnValueLength = Len(strValue)
iColumnValueWidth = iMaxColumnValueLength - iColumnValueLength + iSpace
strColumnValue = strColumnValue & LeftJustified(strValue, iColumnValueWidth)
Next
strColumnValue = strColumnValue & vbCrLf
Next
strOut = vbCrLf & strColumnHeader & vbCrLf & strColumnHeaderLine & vbCrLf & strColumnValue & vbCrLf
WScript.StdOut.WriteLine strOut
End Function
Function GetMaxValueLength(colValues)
Dim strValue
Dim iMaxValueLength
Dim iValueLength
For Each strValue In colValues
iValueLength = Len(strValue)
If (iValueLength > iMaxValueLength) Then
iMaxValueLength = iValueLength
End If
Next
GetMaxValueLength = iMaxValueLength
End Function
Function LeftJustified(ColumnValue, ColumnWidth)
LeftJustified = ColumnValue & Space(ColumnWidth)
End Function
Function RightJustified(ColumnValue, ColumnWidth)
RightJustified = Space(ColumnWidth - Len(ColumnValue)) & ColumnValue
End Function
Function GenerateDashLine(length)
Dim strRet
Dim i
strRet = ""
For i = 1 To length Step 1
strRet = strRet & "-"
Next
GenerateDashLine = strRet
End Function
' ----------------------------------------------------------------------------------
' Classes
' ----------------------------------------------------------------------------------
Class ApplicationPoolInfo
Private strName
Private strState
Private strStartMode
Private strManagedPipelineMode
Private strManagedRuntimeVersion
Public Property Get Name()
Name = strName
End Property
Public Property Let Name(strNameParam)
strName = strNameParam
End Property
Public Property Get State()
State = strState
End Property
Public Property Let State(strStateParam)
strState = strStateParam
End Property
Public Property Get StartMode()
StartMode = strStartMode
End Property
Public Property Let StartMode(strStartModeParam)
strStartMode = strStartModeParam
End Property
Public Property Get ManagedPipelineMode()
ManagedPipelineMode = strManagedPipelineMode
End Property
Public Property Let ManagedPipelineMode(strManagedPipelineModeParam)
strManagedPipelineMode = strManagedPipelineModeParam
End Property
Public Property Get ManagedRuntimeVersion()
ManagedRuntimeVersion = strManagedRuntimeVersion
End Property
Public Property Let ManagedRuntimeVersion(strManagedRuntimeVersionParam)
strManagedRuntimeVersion = strManagedRuntimeVersionParam
End Property
End Class
Class DotNetFrameworkInfo
Private strName
Private strVersion
Public Property Get Name()
Name = strName
End Property
Public Property Let Name(strNameParam)
strName = strNameParam
End Property
Public Property Get Version()
Version = strVersion
End Property
Public Property Let Version(strVersionParam)
strVersion = strVersionParam
End Property
End Class
Class ComputerInfo
Private strName
Private strDNSHostName
Private strDomain
Private strOSName
Private strOSVersion
Private strOSBuildNumber
Private strOSArchitecture
Public Property Get Name()
Name = strName
End Property
Public Property Let Name(strNameParam)
strName = strNameParam
End Property
Public Property Get DNSHostName()
DNSHostName = strDNSHostName
End Property
Public Property Let DNSHostName(strDNSHostNameParam)
strDNSHostName = strDNSHostNameParam
End Property
Public Property Get Domain()
Domain = strDomain
End Property
Public Property Let Domain(strDomainParam)
strDomain = strDomainParam
End Property
Public Property Get OSName()
OSName = strOSName
End Property
Public Property Let OSName(strOSNameParam)
strOSName = strOSNameParam
End Property
Public Property Get OSVersion()
OSVersion = strOSVersion
End Property
Public Property Let OSVersion(strOSVersionParam)
strOSVersion = strOSVersionParam
End Property
Public Property Get OSBuildNumber()
OSBuildNumber = strOSBuildNumber
End Property
Public Property Let OSBuildNumber(strOSBuildNumberParam)
strOSBuildNumber = strOSBuildNumberParam
End Property
Public Property Get OSArchitecture()
OSArchitecture = strOSArchitecture
End Property
Public Property Let OSArchitecture(strOSArchitectureParam)
strOSArchitecture = strOSArchitectureParam
End Property
End Class
Class WebSiteInfo
Private strId
Private strName
Private strState
Private strPhysicalPath
Private strBinding
Private objAppPool
Private objWebApp
Private Sub Class_Initialize()
Set ApplicationPool = Nothing
Set WebApplication = Nothing
End Sub
Public Property Get ID()
ID = strId
End Property
Public Property Let ID(strIdParam)
strId = strIdParam
End Property
Public Property Get Name()
Name = strName
End Property
Public Property Let Name(strNameParam)
strName = strNameParam
End Property