1

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)`

}
}}
}
current_me
  • 35
  • 1
  • 4
  • There is a useful PowerShell module on [GitHub](https://github.com/devblackops/NetScaler) for interacting with Citrix NetScaler via the Nitro API, will be worth looking at it. – Kate Orlova Jun 17 '19 at 21:29

1 Answers1

0

you can use this to get random number of server from user :

$ServerList = New-Object System.Collections.ArrayList # SERVERNAME ARRAY

try 
{
    [int]$ServerCount = Read-Host  "Enter the total number of server : " # READING TOTAL NUMBER OF SERVERS

     for ( $i = 0 ; $i -lt $ServerCount ; $i++) # FOR LOOP
     {
          [String]$servername = Read-Host "Enter the server name : " # READING SERVER NAME FROM USER
          $ServerList.Add($servername) | Out-Null # ADDING THE SERVER NAME TO THE LIST
     } 
} 
catch
{
        Write-Error $_ # DISPLAY ERROR  
}

$ServerList # PRINT THE SERVER LIST
Nirav Mistry
  • 949
  • 5
  • 15