|
| 1 | +Function TestComputerIsPhysicalServerChassisUsingComputerSystemAndSystemEnclosureInstances(ByRef boolIsPhysicalServerChassis, ByVal arrComputerSystemInstances, ByVal arrSystemEnclosureInstances) |
| 2 | + 'region FunctionMetadata #################################################### |
| 3 | + ' Assuming that arrComputerSystemInstances represents an array / collection of the |
| 4 | + ' available computer system instances (of type Win32_ComputerSystem) and |
| 5 | + ' arrSystemEnclosureInstances is an array/collection of Win32_SystemEnclosure objects, this |
| 6 | + ' function determines if the computer is a physical server chassis (i.e., rackmount chassis |
| 7 | + ' or blade chassis) |
| 8 | + ' |
| 9 | + ' The function takes three positional arguments: |
| 10 | + ' - The first argument (boolIsPhysicalServerChassis) is populated upon success with a |
| 11 | + ' boolean value: True when the computer was determined to be a physical server chassis |
| 12 | + ' (i.e., a rackmount chassis or blade chassis), False otherwise |
| 13 | + ' - The second argument (arrComputerSystemInstances) is a WMI collection/array that must |
| 14 | + ' be pre-populated with a collection of Win32_ComputerSystem objects |
| 15 | + ' - The third argument (arrSystemEnclosureInstances) is a WMI collection/array that must |
| 16 | + ' be pre-populated with a collection of Win32_SystemEnclosure objects |
| 17 | + ' |
| 18 | + ' The function returns a 0 when the function successfully evaluated whether the computer is |
| 19 | + ' a physical server chassis (i.e., a rackmount chassis or blade chassis). The function |
| 20 | + ' returns a negative integer if an error occurred. |
| 21 | + ' |
| 22 | + ' Example: |
| 23 | + ' intReturnCode = ConnectLocalWMINamespace(objSWbemServicesWMINamespace, Null, Null) |
| 24 | + ' If intReturnCode = 0 Then |
| 25 | + ' ' Successfully connected to the local computer's root\CIMv2 WMI Namespace |
| 26 | + ' intReturnCode = GetComputerSystemInstancesUsingWMINamespace(arrComputerSystemInstances, objSWbemServicesWMINamespace) |
| 27 | + ' If intReturnCode >= 0 Then |
| 28 | + ' ' At least one Win32_ComputerSystem instance was retrieved successfully |
| 29 | + ' intReturnCode = GetSystemEnclosureInstancesUsingWMINamespace(arrSystemEnclosureInstances, objSWbemServicesWMINamespace) |
| 30 | + ' If intReturnCode > 0 Then |
| 31 | + ' ' One or more Win32_SystemEnclosure instances were retrieved. The first |
| 32 | + ' ' instance is available at arrSystemEnclosureInstances.ItemIndex(0) and the |
| 33 | + ' ' number of instances is available at arrSystemEnclosureInstances.Count. In |
| 34 | + ' ' other words, the upper array boundary/index is |
| 35 | + ' ' (arrSystemEnclosureInstances.Count - 1). |
| 36 | + ' intReturnCode = TestComputerIsPhysicalServerChassisUsingComputerSystemAndSystemEnclosureInstances(boolIsPhysicalServerChassis, arrComputerSystemInstances, arrSystemEnclosureInstances) |
| 37 | + ' If intReturnCode = 0 Then |
| 38 | + ' ' Successfully tested whether this system is a physical server chassis |
| 39 | + ' If boolIsPhysicalServerChassis = True Then |
| 40 | + ' ' Computer is a physical server chassis (i.e., rackmount chassis or |
| 41 | + ' ' blade chassis) |
| 42 | + ' Else |
| 43 | + ' ' Computer is not a physical server chassis, i.e., it is a |
| 44 | + ' ' stationary, non-server physical computer (e.g., a desktop), a |
| 45 | + ' ' physical portable computer (e.g., laptop or tablet), or it is a |
| 46 | + ' ' virtual machine |
| 47 | + ' End If |
| 48 | + ' End If |
| 49 | + ' End If |
| 50 | + ' End If |
| 51 | + ' End If |
| 52 | + ' |
| 53 | + ' Version: 1.0.20210629.0 |
| 54 | + 'endregion FunctionMetadata #################################################### |
| 55 | + |
| 56 | + 'region License #################################################### |
| 57 | + ' Copyright 2021 Frank Lesniak |
| 58 | + ' |
| 59 | + ' Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 60 | + ' software and associated documentation files (the "Software"), to deal in the Software |
| 61 | + ' without restriction, including without limitation the rights to use, copy, modify, merge, |
| 62 | + ' publish, distribute, sublicense, and/or sell copies of the Software, and to permit |
| 63 | + ' persons to whom the Software is furnished to do so, subject to the following conditions: |
| 64 | + ' |
| 65 | + ' The above copyright notice and this permission notice shall be included in all copies or |
| 66 | + ' substantial portions of the Software. |
| 67 | + ' |
| 68 | + ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 69 | + ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 70 | + ' PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| 71 | + ' FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 72 | + ' OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 73 | + ' DEALINGS IN THE SOFTWARE. |
| 74 | + 'endregion License #################################################### |
| 75 | + |
| 76 | + 'region DownloadLocationNotice #################################################### |
| 77 | + ' The most up-to-date version of this script can be found on the author's GitHub repository |
| 78 | + ' at https://github.com/franklesniak/sysadmin-accelerator |
| 79 | + 'endregion DownloadLocationNotice #################################################### |
| 80 | + |
| 81 | + 'region Acknowledgements #################################################### |
| 82 | + ' None! |
| 83 | + 'endregion Acknowledgements #################################################### |
| 84 | + |
| 85 | + 'region DependsOn #################################################### |
| 86 | + ' TestObjectForData() |
| 87 | + ' GetComputerManufacturerUsingComputerSystemInstances() |
| 88 | + ' GetComputerModelUsingComputerSystemInstances() |
| 89 | + ' TestComputerIsPhysicalServerChassisUsingManufacturerModelAndSystemEnclosureInstances() |
| 90 | + 'endregion DependsOn #################################################### |
| 91 | + |
| 92 | + Dim intFunctionReturn |
| 93 | + Dim intReturnMultiplier |
| 94 | + Dim intReturnCode |
| 95 | + Dim intOffset |
| 96 | + Dim boolInterimResult |
| 97 | + Dim strComputerManufacturer |
| 98 | + Dim strComputerModel |
| 99 | + |
| 100 | + intFunctionReturn = 0 |
| 101 | + intReturnMultiplier = 131072 |
| 102 | + intOffset = 0 |
| 103 | + |
| 104 | + boolInterimResult = False |
| 105 | + |
| 106 | + If TestObjectForData(arrComputerSystemInstances) <> True Then |
| 107 | + intFunctionReturn = intFunctionReturn + (-1 * intReturnMultiplier) + intOffset |
| 108 | + Else |
| 109 | + intFunctionReturn = intFunctionReturn * 2 |
| 110 | + intReturnCode = GetComputerManufacturerUsingComputerSystemInstances(strComputerManufacturer, arrComputerSystemInstances) |
| 111 | + If intReturnCode < 0 Then |
| 112 | + ' Error occurred |
| 113 | + intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier) + intOffset |
| 114 | + Else |
| 115 | + ' intReturnCode >= 0 |
| 116 | + ' The computer manufacturer was retrieved successfully and is stored in |
| 117 | + ' strComputerManufacturer |
| 118 | + intOffset = 536870912 |
| 119 | + intReturnCode = GetComputerModelUsingComputerSystemInstances(strComputerModel, arrComputerSystemInstances) |
| 120 | + If intReturnCode < 0 Then |
| 121 | + ' Error occurred |
| 122 | + intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier) + intOffset |
| 123 | + Else |
| 124 | + intReturnMultiplier = 1 |
| 125 | + intOffset = 0 |
| 126 | + intReturnCode = TestComputerIsPhysicalServerChassisUsingManufacturerModelAndSystemEnclosureInstances(boolInterimResult, strComputerManufacturer, strComputerModel, arrSystemEnclosureInstances) |
| 127 | + If intReturnCode <> 0 Then |
| 128 | + ' Error occurred |
| 129 | + intFunctionReturn = intFunctionReturn + (intReturnCode * intReturnMultiplier) |
| 130 | + Else |
| 131 | + 'Success |
| 132 | + End If |
| 133 | + End If |
| 134 | + End If |
| 135 | + End If |
| 136 | + |
| 137 | + If intFunctionReturn = 0 Then |
| 138 | + boolIsPhysicalServerChassis = boolInterimResult |
| 139 | + End If |
| 140 | + |
| 141 | + TestComputerIsPhysicalServerChassisUsingComputerSystemAndSystemEnclosureInstances = intFunctionReturn |
| 142 | +End Function |
0 commit comments