使用 Plink 更改多台思科交换机的配置

Using Plink to change configs on multiple cisco switches

我现在有一个 PS 脚本,可以让我一个接一个地登录一系列交换机。

70..80 | % { plink "172.16.15.$_" -l enterusername -pw enterpassword}

这允许我从以 .70 结尾的开关开始,完成后键入 exit,它会自动按顺序登录到下一个。

我想创建一个文本文件,其中包含我想对交换机上的 运行-config 进行的更改,例如可能将用户添加到 100 台左右的交换机。我如何添加到 PS 脚本以使其将更改应用到创建的文本文件中包含的配置?我正在尝试自动更改 100 个边缘交换机,而不是必须在每个交换机中键入配置。

或者不指向文本文件,我能否以某种方式将开关配置的更改直接添加到 PS 脚本中?

如有疑问,请阅读 documentation(强调我的):

7.2 Using Plink

This section describes the basics of how to use Plink for interactive logins and for automated processes.

Once you've got a console window to type into, you can just type plink on its own to bring up a usage message. This tells you the version of Plink you're using, and gives you a brief summary of how to use Plink:

Z:\sysosd>plink
PuTTY Link: command-line connection utility
Release 0.53
Usage: plink [options] [user@]host [command]
       ("host" can also be a PuTTY saved session name)
Options:
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -ssh -telnet -rlogin -raw
            force use of a particular protocol (default SSH)
  -P port   connect to specified port
  -l user   connect with specified username
  -m file   read remote command(s) from file
  -batch    disable all interactive prompts

所以您需要做的就是创建命令文件,并将其添加到命令行:

70..80 | ForEach-Object {
    plink "172.16.15.$_" -l enterusername -pw enterpassword -m 'C:\commands.txt'
}