-
Notifications
You must be signed in to change notification settings - Fork 1
/
Check-TBSupportedModels.ps1
140 lines (117 loc) · 5.05 KB
/
Check-TBSupportedModels.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
<#
.SYNOPSIS
Check Thnderbolt model support from list.
.DESCRIPTION
This script adds driver group to TS driver injection. This process should be ran in WINPE before driver injection.
.PARAMETER LogFileName
Set the name of the log file produced by the firmware.
.EXAMPLE
.NOTES
FileName: Check-TBSupportedModels.ps1
Author: Richard tracy
Contact: richard.j.tracy@gmail.com
Created: 2018-08-24
Version history:
1.0.0 - (2018-08-24) Script created
#>
##*===========================================================================
##* FUNCTIONS
##*===========================================================================
function Write-LogEntry {
param(
[parameter(Mandatory=$true, HelpMessage="Value added to the log file.")]
[ValidateNotNullOrEmpty()]
[Alias("Message")]
[string]$Value,
[parameter(Mandatory=$false)]
[ValidateSet(0,1,2,3)]
[int16]$Severity,
[parameter(Mandatory=$false, HelpMessage="Name of the log file that the entry will written to.")]
[ValidateNotNullOrEmpty()]
[string]$fileArgName = $LogFilePath,
[parameter(Mandatory=$false)]
[switch]$Outhost
)
[string]$LogTime = (Get-Date -Format 'HH:mm:ss.fff').ToString()
[string]$LogDate = (Get-Date -Format 'MM-dd-yyyy').ToString()
[int32]$script:LogTimeZoneBias = [timezone]::CurrentTimeZone.GetUtcOffset([datetime]::Now).TotalMinutes
[string]$LogTimePlusBias = $LogTime + $script:LogTimeZoneBias
# Get the file name of the source script
Try {
If ($script:MyInvocation.Value.ScriptName) {
[string]$ScriptSource = Split-Path -Path $script:MyInvocation.Value.ScriptName -Leaf -ErrorAction 'Stop'
}
Else {
[string]$ScriptSource = Split-Path -Path $script:MyInvocation.MyCommand.Definition -Leaf -ErrorAction 'Stop'
}
}
Catch {
$ScriptSource = ''
}
If(!$Severity){$Severity = 1}
$LogFormat = "<![LOG[$Value]LOG]!>" + "<time=`"$LogTimePlusBias`" " + "date=`"$LogDate`" " + "component=`"$ScriptSource`" " + "context=`"$([Security.Principal.WindowsIdentity]::GetCurrent().Name)`" " + "type=`"$Severity`" " + "thread=`"$PID`" " + "file=`"$ScriptSource`">"
# Add value to log file
try {
Out-File -InputObject $LogFormat -Append -NoClobber -Encoding Default -FilePath $LogFilePath -ErrorAction Stop
}
catch [System.Exception] {
Write-Host "Unable to append log entry to $LogFilePath file" -ForegroundColor Red
}
If($Outhost){
Switch($Severity){
0 {Write-Host $Value -ForegroundColor Gray}
1 {Write-Host $Value}
2 {Write-Warning $Value}
3 {Write-Host $Value -ForegroundColor Red}
default {Write-Host $Value}
}
}
}
##*===========================================================================
##* VARIABLES
##*===========================================================================
## Instead fo using $PSScriptRoot variable, use the custom InvocationInfo for ISE runs
If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
[string]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent
[string]$scriptPath = $InvocationInfo.MyCommand.Definition
[string]$scriptName = [IO.Path]::GetFileNameWithoutExtension($scriptPath)
Try
{
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
#$logPath = $tsenv.Value("LogPath")
$LogPath = $tsenv.Value("_SMSTSLogPath")
$tsenv.Value("SMSTS_TBSupported") = "False"
$inPE = $tsenv.Value("_SMSTSInWinPE")
}
Catch
{
Write-Warning "TS environment not detected. Assuming stand-alone mode."
$LogPath = $env:TEMP
}
[string]$FileName = $scriptName +'.log'
$LogFilePath = Join-Path -Path $LogPath -ChildPath $FileName
##*===========================================================================
##* MAIN
##*===========================================================================
#Get Supported Models from File
#https://www.dell.com/en-us/work/shop/dell-business-thunderbolt-dock-tb16-with-240w-adapter/apd/452-bcnu/pc-accessories
[array]$SupportedModels = Get-Content ModelsSupported.txt -ErrorAction SilentlyContinue
#Create Model Variable
$ComputerModel = Get-WmiObject -Class Win32_computersystem | Select-Object -ExpandProperty Model
if ($tsenv -and $inPE) {
Write-LogEntry "Script is running in Windows Preinstallation Environment (PE)" -Outhost
}
Else{
Write-LogEntry "Script is running in Windows Environment" -Outhost
}
#determine if model support thunderbolt
Write-LogEntry ("Comparing this model [{0}] with supported model list [{1}]" -f $ComputerModel,"ModelsSupported.txt") -Outhost
Foreach ($SupportedModel in $SupportedModels){
If($ComputerModel -eq $SupportedModel)
{
$tsenv.Value("SMSTS_TBSupported") = "True"
}
Else{
Write-LogEntry ("Model is not a [{0}]. Thunderbolt Docking Station is not supported, skipping drivers..." -f $SupportedModel) -Outhost
}
}