How to add bulk RADIUS client in NPS using powershell

asked 2021-04-15T11:04:04.053+00:00
Mohd Arif 871 Reputation points

I have to add more than 50 RADIUS client in NPS. I think using power shell will make it easy. I created below script BUT after running this script, I get something like, I do not know what to enter here. can some one help me pls.

Supply values for the following parameters:
Process[0]:

**Script*
Import-Csv D:\ND.csv

Foreach-Object
{

$DeviceName = $."Name"
$IPAddress = $
."IP"
$SecretePass = $_."SecreteKey"

New-NpsRadiusClient -Address $IPAddress -Name $DeviceName -SharedSecret $SecretePass -VendorName Cisco -AuthAttributeRequired $True

}

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
8,143 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,613 questions
No comments
{count} votes

Accepted answer
  1. answered 2021-04-15T11:25:48.807+00:00
    Ian Xue (Shanghai Wicresoft Co., Ltd.) 18,351 Reputation points Microsoft Employee

    Hi,

    The pipeline operator "|" is missing.

    Import-Csv D:\ND.csv | Foreach-Object  
    {  
        $DeviceName = $_."Name"  
        $IPAddress = $_."IP"  
        $SecretePass = $_."SecreteKey"  
        New-NpsRadiusClient -Address $IPAddress -Name $DeviceName -SharedSecret $SecretePass -VendorName Cisco -AuthAttributeRequired $True  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments

3 additional answers

Sort by: Most helpful
  1. answered 2021-04-15T12:34:14.143+00:00
    Mohd Arif 871 Reputation points

    Still same problem

    88270-npserror.jpg

    No comments

  2. answered 2021-04-15T13:14:33.4+00:00
    Mohd Arif 871 Reputation points

    This was bullshit :). I did not place inverted comma (") at D:\ND.CSV so I was getting this error. Now place command and command is like as below. It works good now.

    Import-Csv "D:\ND.csv" | Foreach-Object
    {
    $DeviceName = $."Name"
    $IPAddress = $
    ."IP"
    $SecretePass = $_."SecreteKey"
    New-NpsRadiusClient -Address $IPAddress -Name $DeviceName -SharedSecret $SecretePass -VendorName Cisco -AuthAttributeRequired $True
    }


  3. answered 2021-12-06T13:13:36.533+00:00
    Matthew Thomas 1 Reputation point

    I have been trying to perform bulk imports of Radius clients to NPS with the above and many other code samples to not avail. As this post comes up a lot when I search about this topic, I'm going to post here what I've found and what I realized. To be clear I'm in no means a powershell enthusiast so the below could be the completly wrong answer but it worked for me.

    What I've realised is that all the examples I've seen so far regarding this are trying over engineer the solution with hands tied behind their backs.

    Import-CSV will actually already to the hard work for you, you don't need to do anything fancy.. Especially if a lone network engineer just wants to bulk import some things, you've done the hard data entry work regarding your CSV, you've created each column name, something simple like ipaddr, hostname, vendor and then underneath that you've done the tedious data entry etc.

    If you simple run import-csv "[path to your CSV]\mybigfatcsv.csv, you'll see it'll spits out an array:

    PS C:\Windows\system32> Import-csv "C:\REDACTED\mybigfatcsv.csv" 
    
    ipaddr  hostname vendor         
    ------  -------- ------         
    1.2.3.4 faker    Cisco          
    4.3.2.1 rekaf    RADIUS Standard
    

    PLEASE, remember that with $_. you're declaring a variable so you'll need to use the column name in your CSV as I have ipaddr, hostname, vendor afterwards
    If you want to check that your CSV works in a cmdlet you can then pipe this to a foreach-object then to write-host to output the values.

    PS C:\Windows\system32> Import-csv "C:\Users\REDACTED\Desktop\mybigfatcsv.csv" | ForEach-Object {
    write-host $_.ipaddr $_.hostname $_.vendor
    }
    1.2.3.4 faker Cisco
    4.3.2.1 rekaf RADIUS Standard
    
    PS C:\Windows\system32> 
    

    Now that we can see the the variables can be brought correctly into a cmdlet without actual doing anything let's try the New-NpsRadiusClient cmdlet:

    PS C:\Windows\system32> Import-csv "C:\Users\REDACTED\Desktop\mybigfatcsv.csv" | ForEach-Object {
    New-NpsRadiusClient -Address $_.ipaddr -Name $_.hostname -VendorName $_.vendor -SharedSecret "placeholder" -AuthAttributeRequired $true 
    }
    
    
    Name                  : faker
    Address               : 1.2.3.4
    AuthAttributeRequired : True
    SharedSecret          : placeholder
    VendorName            : Cisco
    Enabled               : True
    
    Name                  : rekaf
    Address               : 4.3.2.1
    AuthAttributeRequired : True
    SharedSecret          : placeholder
    VendorName            : RADIUS Standard
    Enabled               : True
    
    
    
    
    PS C:\Windows\system32> Import-csv "C:\Users\REDACTED\Desktop\mybigfatcsv.csv" | ForEach-Object {
    New-NpsRadiusClient -Address $_.ipaddr -Name $_.hostname -VendorName $_.vendor -SharedSecret "placeholder" -AuthAttributeRequired $true 
    }
    New-NpsRadiusClient : The Radius client faker already exists.
    At line:2 char:1
    + New-NpsRadiusClient -Address $_.ipaddr -Name $_.hostname -VendorName  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (Microsoft.Nps.C...usClientCommand:NewNpsRadiusClientCommand) [New-NpsRadiusClient], ArgumentException
        + FullyQualifiedErrorId : New-NpsRadiusClient.ArgumentException,Microsoft.Nps.Commands.NewNpsRadiusClientCommand
    
    New-NpsRadiusClient : The Radius client rekaf already exists.
    At line:2 char:1
    + New-NpsRadiusClient -Address $_.ipaddr -Name $_.hostname -VendorName  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (Microsoft.Nps.C...usClientCommand:NewNpsRadiusClientCommand) [New-NpsRadiusClient], ArgumentException
        + FullyQualifiedErrorId : New-NpsRadiusClient.ArgumentException,Microsoft.Nps.Commands.NewNpsRadiusClientCommand
    
    
    PS C:\Windows\system32> 
    

    As you can see from the above it's successfully created Radius clients and if you execute it again it won't overwrite them as the objects already exist.
    Unfortunately it doesn't appear at the time of this post that you can utilise a SharedSecret template so I've used a simple password that will be changed but at least 99% of my work is done for me.

    I hope this helps out other people who've spent time on this, but mostly for myself who will most likely need to do this again and will probably stumble on this post in the future as I have in the past.

    No comments