-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-WmiWwan.ps1
207 lines (194 loc) · 9.17 KB
/
Set-WmiWwan.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
#Requires -Version 2
<#
.SYNOPSIS
Exports cellular information to a WMI class
.DESCRIPTION
Writes mobile device information into WMI for ConfigMgr consumption
.NOTES
Release Date: 2021-05-07
Author: Bennett Blodinger
.EXAMPLE
Set-WmiWwan
#>
[CmdletBinding()]
PARAM ()
If ((Get-Service -Name "WwanSvc").Status -ne "Running") {
Write-Error -Exception 6 -Message "Mobile Broadband Service (wwansvc) is not running" -ErrorAction Stop
} Else {
$interfaceOutput = netsh mbn show interfaces
ForEach ($Line In $interfaceOutput) {
If (-not ([String]::IsNullOrEmpty($Line))) {
$Line = ($Line -split ":", 2).Trim()
Switch -Regex ($Line) {
"^There (is|are) (\d*) interface(s)? on the system" {
$numberOfInterfaces = ($Line[0] | Select-String -Pattern "^There (?:is|are) (\d*) interface(?:s)? on the system*").Matches.Groups[1].Value
}
"^Name" {
$name = $Line[1]
}
"^Description" {
$description = $Line[1]
}
"^GUID" {
$guid = $Line[1]
}
"^Physical Address" {
$physicalAddress = ($Line[1].ToUpper()).Replace(":", "-")
}
"^Additional PDP Context" {
$additionalPdpContext = $Line[1]
}
"^Parent Interface Guid" {
$parentInterfaceGuid = $Line[1]
}
"^State" {
$state = $Line[1]
}
"^Device type" {
$deviceType = $Line[1]
}
"^Cellular class" {
$cellularClass = $Line[1]
}
"^Device Id" {
$deviceId = $Line[1]
}
"^Manufacturer" {
$manufacturer = $Line[1]
}
"^Model" {
$model = $Line[1]
}
"^Firmware Version" {
$firmwareVersion = $Line[1]
}
"^Provider Name" {
$providerName = $Line[1]
}
"^Roaming" {
$roaming = $Line[1]
}
"^Signal" {
$signal = [single]$Line[1].Replace("%", "") / 100
}
"^RSSI / RSCP" {
$rssiRscp = $Line[1]
}
}
}
}
$CellularInterface = [psobject] @{
Name = $name
Description = $description
Guid = $guid
PhysicalAddress = $physicalAddress
AdditionalPdpContext = $additionalPdpContext
ParentInterfaceGuid = $parentInterfaceGuid
State = $state
DeviceType = $deviceType
CellularClass = $cellularClass
DeviceId = $deviceId
Manufacturer = $manufacturer
Model = $model
FirmwareVersion = $firmwareVersion
ProviderName = $providerName
Roaming = $roaming
Signal = $signal
RssiRscp = $rssiRscp
}
$readyInformationOutput = netsh mbn show readyinfo interface=`"$($CellularInterface.Name)`"
[String[]] $telephoneNumbers = @()
ForEach ($Line In $readyInformationOutput) {
$Line
If (-not ([String]::IsNullOrEmpty($Line))) {
$Line = ($Line -split ":", 2).Trim()
Switch -Regex ($Line) {
"^State" {
$readyInformation_State = $Line[1]
}
"^Emergency mode" {
$readyInformation_EmergencyMode = $Line[1]
}
"^Subscriber Id" {
$readyInformation_SubscriberId = $Line[1]
}
"^SIM ICC Id" {
$readyInformation_SimIccId = $Line[1]
}
"^Telephone #(\d*)" {
$telephoneNumbers += $Line[1]
}
}
}
}
$ReadyInformation = [psobject] @{
State = $readyInformation_State
EmergencyMode = $readyInformation_EmergencyMode
SubscriberId = $readyInformation_SubscriberId
SimIccId = $readyInformation_SimIccId
TelephoneNumbers = $telephoneNumbers
}
$CellularInterface | Add-Member -MemberType NoteProperty -Name "ReadyInformation" -Value $ReadyInformation -Force
Remove-WmiObject "WWAN" -ErrorAction SilentlyContinue
$wwanClass = New-Object System.Management.ManagementClass("root\cimv2", [String]::Empty, $null)
$wwanClass["__CLASS"] = "WWAN"
$wwanClass.Qualifiers.Add("Static", $true)
$wwanClass.Properties.Add("Name", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Description", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Guid", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("PhysicalAddress", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("AdditionalPdpContext", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("ParentInterfaceGuid", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("State", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("DeviceType", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("CellularClass", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("DeviceId", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Manufacturer", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Model", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("FirmwareVersion", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("ProviderName", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Roaming", [System.Management.CimType]::String, $false)
$wwanClass.Properties.Add("Signal", [System.Management.CimType]::Real32, $false)
$wwanClass.Properties.Add("RssiRscp", [System.Management.CimType]::String, $false)
$wwanClass.Properties["DeviceId"].Qualifiers.Add("Key", $true)
$wwanClass.Put() | Out-Null
Remove-WmiObject "WWAN_SIM" -ErrorAction SilentlyContinue
$wwanSimClass = New-Object System.Management.ManagementClass ("root\cimv2", [String]::Empty, $null)
$wwanSimClass["__CLASS"] = "WWAN_SIM"
$wwanSimClass.Qualifiers.Add("Static", $true)
$wwanSimClass.Properties.Add("AdapterGuid", [System.Management.CimType]::String, $false)
$wwanSimClass.Properties.Add("State", [System.Management.CimType]::String, $false)
$wwanSimClass.Properties.Add("EmergencyMode", [System.Management.CimType]::String, $false)
$wwanSimClass.Properties.Add("SubscriberId", [System.Management.CimType]::String, $false)
$wwanSimClass.Properties.Add("SimIccId", [System.Management.CimType]::String, $false)
$wwanSimClass.Properties.Add("TelephoneNumbers", [System.Management.CimType]::String, $true)
$wwanSimClass.Properties["SimIccId"].Qualifiers.Add("Key", $true)
$wwanSimClass.Put() | Out-Null
Set-WmiInstance -Path \\.\root\cimv2:WWAN -Arguments @{
Name = $CellularInterface.Name;
Description = $CellularInterface.Description;
Guid = $CellularInterface.Guid;
PhysicalAddress = $CellularInterface.PhysicalAddress;
AdditionalPdpContext = $CellularInterface.AdditionalPdpContext;
ParentInterfaceGuid = $CellularInterface.ParentInterfaceGuid;
State = $CellularInterface.State;
DeviceType = $CellularInterface.DeviceType;
CellularClass = $CellularInterface.CellularClass;
DeviceId = $CellularInterface.DeviceId;
Manufacturer = $CellularInterface.Manufacturer;
Model = $CellularInterface.Model;
FirmwareVersion = $CellularInterface.FirmwareVersion;
ProviderName = $CellularInterface.ProviderName;
Roaming = $CellularInterface.Roaming;
Signal = $CellularInterface.Signal;
RssiRscp = $CellularInterface.RssiRscp;
} | Out-Null
Set-WmiInstance -Path \\.\root\cimv2:WWAN_SIM -Arguments @{
AdapterGuid = $CellularInterface.Guid;
State = $CellularInterface.ReadyInformation.State;
EmergencyMode = $CellularInterface.ReadyInformation.EmergencyMode;
SubscriberId = $CellularInterface.ReadyInformation.SubscriberId;
SimIccId = $CellularInterface.ReadyInformation.SimIccId;
TelephoneNumbers = $CellularInterface.ReadyInformation.TelephoneNumbers;
} | Out-Null
}