Configuration Item not returing data for NETSH command

MikeB 101 Reputation points
2021-09-10T16:06:02.223+00:00

I am attempting to gather SIM card details from our LTE-enabled laptops by running the NETSH command to gather the SIM card details and then write the data to WMI. The script I am using works perfectly when I run it manually on the system as Administrator or with a local admin account, however, when I run the script as a CI, some of the values are blank. I am able to replicate this issue when I run the script manually from a command prompt running as System.

The script is set to run these commands to gather the SIM card information:

netsh mbn show readyinfo * | findstr "SIM ICC ID"
netsh mbn show readyinfo * | findstr "Telephone #"
netsh mbn show interfaces | find "Device Id"
netsh mbn show interfaces | find "Physical Address"
netsh mbn show interfaces | findstr "Manufacturer"
netsh mbn show interfaces | findstr "Model"

Running from a command prompt as Administrator, I see values returned from each command and life is good:

C:\WINDOWS\system32>netsh mbn show readyinfo * | findstr "SIM ICC ID"
SIM ICC Id : 89XXXXXXXXXXXX49045

C:\WINDOWS\system32>netsh mbn show readyinfo * | findstr "Telephone #"
Telephone #1 : 07XXXXXXX09

C:\WINDOWS\system32>netsh mbn show interfaces | find "Device Id"
Device Id : 35XXXXXXXXXXX95

C:\WINDOWS\system32>netsh mbn show interfaces | find "Physical Address"
Physical Address : 84:XX:XX:XX:XX:43

C:\WINDOWS\system32>netsh mbn show interfaces | findstr "Manufacturer"
Manufacturer : Sierra Wireless, Incorporated

C:\WINDOWS\system32>netsh mbn show interfaces | findstr "Model"
Model : DW5816e Snapdragon? X7 LTE

Running from a command prompt as System (and thus I get the same results when it runs as a CI), values are only returned for the command where “netsh mbn show readyinfo *” is used and the lines where the command “netsh mbn show interfaces” is used returns nothing:

C:\WINDOWS\system32>whoami
nt authority\system

C:\WINDOWS\system32>netsh mbn show readyinfo * | findstr "SIM ICC ID"
SIM ICC Id : 89XXXXXXXXXXXX49045

C:\WINDOWS\system32>netsh mbn show readyinfo * | findstr "Telephone #"
Telephone #1 : 07XXXXXXX09

C:\WINDOWS\system32>netsh mbn show interfaces | find "Device Id"

C:\WINDOWS\system32>netsh mbn show interfaces | find "Physical Address"

C:\WINDOWS\system32>netsh mbn show interfaces | findstr "Manufacturer"

C:\WINDOWS\system32>netsh mbn show interfaces | findstr "Model"

So, it looks like the System profile either does not have access to this data or it just doesn’t apply to that profile, so I need to be able to somehow get the CI to gather information when the command “netsh mbn show interfaces” Is used. Note that running this under the user context will not work, as this is writing to WMI and these users do not have admin rights.

Any ideas on how to make this work as a CI or if there is a different way to gather the SIM card information?

Microsoft Security | Intune | Configuration Manager | Other
0 comments No comments
{count} votes

Accepted answer
  1. MikeB 101 Reputation points
    2021-09-15T19:16:32.857+00:00

    Thank you Sherry. As it turns out, all of the problem systems were running the Japanese language pack and the output was not recognized as valid output by Netsh. To work around this issue, I forced the language to English for the duration of the Powershell session by adding 'chcp 437' to the beginning of the script.

    Updated final script:

    If anyone is interested, here is the final PS script.

    chcp 437
    
    $CurrentEA = $ErrorActionPreference
    $ErrorActionPreference = 'SilentlyContinue'
    (Get-WmiObject -Namespace root\cimv2 -class CM_SIMCard).Delete()
    $ErrorActionPreference = $CurrentEA
    
    
    # Use Netsh to get the values of the SIM card
    $DeviceID = ((netsh mbn show interfaces | find "Device Id") -split ': ')[1]
    $SIMICCID = ((netsh mbn show readyinfo * | findstr "SIM ICC ID") -split ': ')[1]
    $PhysicalAddress = ((netsh mbn show interfaces | find "Physical Address") -split ': ')[1]
    $Manufacturer = ((netsh mbn show interfaces | findstr "Manufacturer") -split ': ')[1]
    $Model = ((netsh mbn show interfaces | findstr "Model") -split ': ')[1]
    $TelephoneNumber = ((netsh mbn show readyinfo * | findstr "Telephone #") -split ': ')[1]
    
    
    $newClass = New-Object System.Management.ManagementClass("root\cimv2", [String]::Empty, $null);
    
        $newClass["__CLASS"] = "CM_SIMCard";
    
        $newClass.Qualifiers.Add("Static", $true)
        $newClass.Properties.Add("DeviceID", [System.Management.CimType]::String, $false)
        $newClass.Properties["DeviceID"].Qualifiers.Add("key", $true)
        $newClass.Properties["DeviceID"].Qualifiers.Add("read", $true)
        $newClass.Properties.Add("SIMICCID", [System.Management.CimType]::String, $false)
        $newClass.Properties["SIMICCID"].Qualifiers.Add("read", $true)
        $newClass.Properties.Add("PhysicalAddress", [System.Management.CimType]::String, $false)
        $newClass.Properties["PhysicalAddress"].Qualifiers.Add("read", $true)
        $newClass.Properties.Add("Manufacturer", [System.Management.CimType]::String, $false)
        $newClass.Properties["Manufacturer"].Qualifiers.Add("read", $true)
        $newClass.Properties.Add("Model", [System.Management.CimType]::String, $false)
        $newClass.Properties["Model"].Qualifiers.Add("read", $true)
        $newClass.Properties.Add("TelephoneNumber", [System.Management.CimType]::String, $false)
        $newClass.Properties["TelephoneNumber"].Qualifiers.Add("read", $true)
        $newClass.Put()
    
    
    
    # Set the instance
    Set-WmiInstance -Class CM_SIMCard -Argument @{DeviceID=$DeviceID;SIMICCID=$SIMICCID;PhysicalAddress=$PhysicalAddress;Manufacturer=$Manufacturer;Model=$Model;TelephoneNumber=$TelephoneNumber}|Out-Null
    
    
    # Set the return code
    if (Get-WmiObject -Class CM_SIMCard)
    {
        $Compliance = 'True'
    }
    Else
    {
        $Compliance = 'False'
    }
    
    $Compliance
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sherry Kissinger 5,526 Reputation points
    2021-09-10T20:32:58.467+00:00

    I don't have any test devices with LTE to play with; but I noticed this similar query; and the person at the end said "this is working perfectly"... whether or not it'll work for your situation, I don't know: https://social.technet.microsoft.com/Forums/en-US/96b5f3ff-4a4e-4448-819c-0432a5e0562f/netsh-command-without-run-as-administrator

    Worth testing anyway; unsure if you'll have to imbed some kind of username and password in the script, just to do this--it doesn't say if there are prompts involved or not.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.