Search code examples
windowspowershelldriveripfw

Automate installation of DummyNET Driver using PowerShell


tl;dr trying to automate a driver / adapter binding / adapter service using PowerShell / (Set|Get)-NetAdapterBinding / PnPUtil / nvspbind

I've been exploring automating the installation of the dummynet driver on a network adapter on Windows Server 2012 and 2012 R2.

I need to automate these steps:

Pull up the properties for the Network Adapter that is used to access the Internet
Click "Install"
Select "Service" and click "Add"
Click "Have Disk" and navigate to webpagetest\dummynet
Select the ipfw+dummynet service (and click through any warnings about the driver being unsigned)

I believe I can add the driver's INF files to the Driver Store using the PnPUtil utility.

I've explored the (Set|Get)-NetAdapterBinding powershell modules, and I can't seem to get the driver to register properly.

Here is the result of a Get-NetAdapterBinding after I installed it via the manual method:

PS C:\Users\Administrator> Get-NetAdapterBinding public0 -DisplayName ipfw+dummynet | format-list

Caption              : MSFT_NetAdapterBindingSettingData 'Citrix PV Network Adapter #0'
Description          : ipfw+dummynet
ElementName          : unipi_ipfw
InstanceID           : {906E5591-5C6C-4D07-BB8D-BA387BA4B646}::unipi_ipfw
InterfaceDescription : Citrix PV Network Adapter #0
Name                 : public0
Source               : 1
SystemName           : ComputerName
BindName             : Ipfw
Characteristics      : 17424
ComponentClassGuid   : {4D36E974-E325-11CE-BFC1-08002BE10318}
ComponentClassName   : Filter
ComponentID          : unipi_ipfw
DisplayName          : ipfw+dummynet
Enabled              : True
PSComputerName       :
ifAlias              : public0
InterfaceAlias       : public0
ifDesc               : Citrix PV Network Adapter #0

Get-NetAdapterBinding -Name public -DisplayName ipfw+dummynet | GM    

TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/StandardCimv2
/MSFT_NetAdapterBindingSettingData

Name                      MemberType    Definition                             
----                      ----------    ----------                             
ifAlias                   AliasProperty ifAlias = Name                         
ifDesc                    AliasProperty ifDesc = InterfaceDescription          
InterfaceAlias            AliasProperty InterfaceAlias = Name                  
Clone                     Method        System.Object ICloneable.Clone()       
Dispose                   Method        void Dispose(), void IDisposable.Dis...
Equals                    Method        bool Equals(System.Object obj)         
GetCimSessionComputerName Method        string GetCimSessionComputerName()     
GetCimSessionInstanceId   Method        guid GetCimSessionInstanceId()         
GetHashCode               Method        int GetHashCode()                      
GetObjectData             Method        void GetObjectData(System.Runtime.Se...
GetType                   Method        type GetType()                         
ToString                  Method        string ToString()                      
BindName                  Property      string BindName {get;}                 
Caption                   Property      string Caption {get;set;}              
Characteristics           Property      uint32 Characteristics {get;}          
ComponentClassGuid        Property      string ComponentClassGuid {get;}       
ComponentClassName        Property      string ComponentClassName {get;}       
ComponentID               Property      string ComponentID {get;}              
Description               Property      string Description {get;set;}          
DisplayName               Property      string DisplayName {get;}              
ElementName               Property      string ElementName {get;set;}          
Enabled                   Property      bool Enabled {get;set;}                
InstanceID                Property      string InstanceID {get;set;}           
InterfaceDescription      Property      string InterfaceDescription {get;}     
Name                      Property      string Name {get;}                     
PSComputerName            Property      string PSComputerName {get;}           
Source                    Property      uint32 Source {get;}                   
SystemName                Property      string SystemName {get;}

Here is my attempt to Set-NetAdapterBinding with the arguments documented for that module:

Set-NetAdapterBinding -Name public0 -Component unipi_ipfw -Enabled $True

Set-NetAdapterBinding : No matching MSFT_NetAdapterBindingSettingData objects
found by CIM query for instances of the
ROOT/StandardCimv2/MSFT_NetAdapterBindingSettingData class on the  CIM server:
SELECT * FROM MSFT_NetAdapterBindingSettingData  WHERE ((Name LIKE 'public0'))
AND ((ComponentID LIKE 'unipi[_]ipfw')). Verify query parameters and retry.
At line:1 char:1
+ Set-NetAdapterBinding -Name public0 -Component unipi_ipfw -Enabled $True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_NetAdapterBindingSettingDa
   ta:String) [Set-NetAdapterBinding], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Set-NetAdapterBindin
   g

In trying to figure out the best way to do this, I also came across the nvspbind utility, and attempted to use this tool to add the driver. Unfortunately, I can't seem to get that to bind to the adapter either. The utility just keeps spitting out it's usage information.

What's the best way to approach this issue using PowerShell?


Solution

  • I worked with a co-worker and we found a solution:

    bcdedit /set TESTSIGNING ON    
    Import-Certificate -FilePath C:\webpagetest\WPOFoundation.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
    cd C:\webpagetest
    .\mindinst.exe c:\webpagetest\agent\dummynet\64bit\netipfw.inf -i -s
    Enable-NetAdapterBinding -Name private0 -DisplayName ipfw+dummynet
    
    1. Use bcdedit to set TESTSIGNING ON
    2. Then, you have to import the Certificate provided by the driver into the Certificate Store so it is a trusted driver.
    3. Then, using the mindinst.exe utility, you can install the driver as a Network Service Binding.
    4. Then, the standard Enable-NetAdapterBinding module will work to enable the service.