使用 Powershell 的 Netscaler 自动化
Netscaler automation with Powershell
我想使用 Powershell 为 NetScaler 配置制作交互式脚本。我可以使用 PSH ISE 成功登录并将服务器添加到 netscaler。但是,我在添加多台服务器时遇到问题。我不太确定该怎么做。
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`
添加服务器
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"
从用户那里获取服务器数量
$Responses = Read-Host -Prompt 'How many servers do you want to add'`
do
{
使用用户的响应添加服务器
$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)`
}
}}
}
您可以使用它从用户那里获取服务器的随机数:
$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
我想使用 Powershell 为 NetScaler 配置制作交互式脚本。我可以使用 PSH ISE 成功登录并将服务器添加到 netscaler。但是,我在添加多台服务器时遇到问题。我不太确定该怎么做。
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`
添加服务器
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"
从用户那里获取服务器数量
$Responses = Read-Host -Prompt 'How many servers do you want to add'`
do
{
使用用户的响应添加服务器
$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)`
}
}}
}
您可以使用它从用户那里获取服务器的随机数:
$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