-
Notifications
You must be signed in to change notification settings - Fork 30
/
Get-TpmInfo.vbs
58 lines (57 loc) · 1.87 KB
/
Get-TpmInfo.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
If Wscript.Arguments.Count = 0 Then
aComputers = Array(".")
Else
Dim aComputers()
For i = 0 to Wscript.Arguments.Count - 1
Redim Preserve aComputers(i)
aComputers(i) = Wscript.Arguments(i)
Next
End If
For Each sComputer in aComputers
Wscript.echo GetTPMInfo(sComputer)
Next
Function GetTPMInfo(sComputer)
On Error Resume Next
Set oWMITPM = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & sComputer & "\root\cimv2\Security\MicrosoftTpm")
If sComputer = "." Then sComputer = "LocalHost"
If Err Then
GetTPMInfo = sComputer & ": Microsoft TPM Connection failed."
Exit Function
End If
Set colTPM = oWMITPM.InstancesOf("Win32_Tpm")
If colTPM.Count = 0 Then
GetTPMInfo = sComputer & ": No Win32_Tpm instances found."
Exit Function
End If
Set oTPM = oWMITPM.Get("Win32_Tpm=@")
If Err Then
GetTPMInfo = sComputer & ": Win32_Tpm instance connection failed."
Exit Function
End If
If Left(CStr(oTPM.SpecVersion),3) = 1.2 Then sSpecVersion = "TPM Version: 1.2" Else sSpecVersion = "TPM Version: " & oTPM.SpecVersion
ReturnCode = oTPM.IsEnabled(bIsEnabled)
If ReturnCode <> 0 Then
sIsEnabled = "IsEnabled: " & bIsEnabled & " (ERROR 0x" & Hex(ReturnCode) & ")"
ElseIf bIsEnabled Then
sIsEnabled = "Enabled"
Else
sIsEnabled = "Disabled"
End If
ReturnCode = oTPM.IsActivated(bIsActivated)
If ReturnCode <> 0 Then
sIsActivated = "IsActivated: " & bIsActivated & " (ERROR 0x" & Hex(ReturnCode) & ")"
ElseIf bIsActivated Then
sIsActivated = "Activated"
Else
sIsActivated = "Deactivated"
End If
ReturnCode = oTPM.IsOwned(bIsOwned)
If ReturnCode <> 0 Then
sIsOwned = "IsOwned: " & bIsOwned & " (ERROR 0x" & Hex(ReturnCode) & ")"
ElseIf bIsOwned Then
sIsOwned = "Owned"
Else
sIsOwned = "Unowned"
End If
GetTPMInfo = sComputer & ": " & sSpecVersion & " (" & sIsEnabled & ", " & sIsActivated & ", " & sIsOwned & ")"
End Function