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.