I want to use Powershell to make an interactive script for NetScaler configuration. I can successfully log in and add a server to netscaler using PSH ISE. However, I am having a problem adding multiple servers. I am not so sure how to go about this.
Import-Module C:\netscaler-configuration-master\netscaler-configuration-
master\Modules\NetScalerConfiguration
function Configure-Netscaler{
$NSAddress = Read-Host -Prompt 'Enter $NSAddress' `
$NSUsername = Read-Host -Prompt 'Enter $NSUsername'`
$NSPassword = Read-Host -Prompt 'Enter $NSPassword'`
$myNSSession = Connect-NSAppliance -NSAddress $NSAddress -NSUserName
$NSUsername -NSPassword $NSPassword`
Adding Servers
Write-host 'Adding Servers'
$Readhost = Read-Host 'Do you want to add more than one server?[y/n]'`
Switch ($Readhost)`
{
N{ Write-Host "Begin Entering Server Name and Add IP Address"
$NSSession = $myNSSession`
$Server_Name = Read-Host -Prompt 'Enter $Name'`
$IPAddress = Read-Host -Prompt 'Enter $IPAddress'`
Add-NSServer -NSSession $myNSSession -Name $Name -IPAddress $IPAddress}`
Y { Write-Host "Begin Entering Multiple Server Names and Add IPAddress"
Taking Number of Servers from User
$Responses = Read-Host -Prompt 'How many servers do you want to add'`
do
{
Using the User's Response to add servers
$NSSession = $myNSSession`
$Server_Name = Read-Host -Prompt 'Enter $Name'`
$IPAddress = Read-Host -Prompt 'Enter $IPAddress'`
$multiple_servers = Add-NSServer -NSSession $myNSSession -Name $Name -
IPAddress $IPAddress,`
$multiple_servers++}`
until($Responses -lt $multiple_servers.count)`
}
}}
}