This PowerShell script is used to add RADIUS clients to multiple
RADIUS servers. Below is a breakdown of the script's components:
- Synopsis: A brief
description of the script's purpose.
- Description: An
explanation of what the script does, including that it reads RADIUS client
information from a CSV file and adds them to multiple RADIUS servers while
logging the results.
- Notes: Includes
metadata about the script, such as the file name, prerequisites, author,
and date.
- Example: Shows how
to use the script with example parameters.
The script defines a function called Add-RADIUSClients
with three parameters:
- $CsvPath: The path
to the CSV file containing RADIUS client information.
- $ServerListPath: The path to a text file containing a list of RADIUS server names.
- $LogFilePath: The path
to the log file where the script will log the results.
Within the function, it performs the
following steps:
- Imports the RADIUS client information from the CSV
file.
- Reads the list of RADIUS server names from the text
file.
- Iterates through each server and each client to add
RADIUS clients to the servers.
- Uses Invoke-Command to remotely execute the New-NpsRadiusClient
cmdlet on each server, adding the RADIUS client.
- Logs the results to the specified log file,
indicating success or any errors encountered.
The Try and Catch blocks are
used to handle any errors that may occur during the process, logging the error
messages to the log file.
The script concludes with an example usage
section, where you can specify the paths to your CSV file, server list, and log
file, and then call the Add-RADIUSClients function with these
parameters.
Make sure to have PowerShell Remoting
enabled on the target servers and the required modules imported for the script
to work as expected.
<#
.SYNOPSIS
Add-RADIUSClients - Add RADIUS clients to multiple servers.
.DESCRIPTION
This script
reads RADIUS client information from a CSV file and adds those clients
to multiple
RADIUS servers specified in a text file. It logs the results to a log file.
Author: Navinya
Ambre
Date:
10/10/2023
.NOTES
File Name : Add-RADIUSClients.ps1
Prerequisite : PowerShell
Remoting enabled on target servers, required modules imported.
.EXAMPLE
.\Add-RADIUSClients.ps1 -CsvPath "C:\Path\To\radiusclient.csv"
`
-ServerListPath
"C:\Path\To\servers.txt" `
-LogFilePath
"C:\Path\To\radiusclient.log"
#>
function Add-RADIUSClients {
param (
[string]$CsvPath,
[string]$ServerListPath,
[string]$LogFilePath
)
$ClientInfo = Import-Csv -Path $CsvPath
$ServerNames = Get-Content -Path $ServerListPath
foreach ($ServerName in $ServerNames) {
ForEach ($Client in $ClientInfo) {
Try {
Invoke-Command -ComputerName $ServerName -ScriptBlock {
param ($Client)
New-NpsRadiusClient $Client.ClientName -Address $Client.Address -VendorName $Client.VendorName -AuthAttributeRequired $False -SharedSecret $Client.SharedSecret
} -ArgumentList $Client -ErrorAction Stop
Add-Content -Path $LogFilePath -Value "Added RADIUS client $($Client.ClientName) on $ServerName"
} Catch {
Add-Content -Path $LogFilePath -Value "Error adding RADIUS client $($Client.ClientName) on $ServerName : $_"
}
}
}
}
# Example usage:
$CsvPath = "C:\Path\To\radiusclient.csv"
$ServerListPath = "C:\Path\To\servers.txt"
$LogFilePath = "C:\Path\To\radiusclient.log"
Add-RADIUSClients -CsvPath $CsvPath -ServerListPath $ServerListPath -LogFilePath $LogFilePath
Please consider this an open forum for sharing your thoughts, modifications, and suggestions regarding the script. Your input and feedback are highly encouraged and valued.