Powershell / Cisco IOS – Generate a list of commands from a csv list of devices

Generates a .doc of commands to paste into devices.  pulls IP and hostname from csv and structures the commands in a way you can copy/pasta.

CSV should look like this:,switch1,switch2,switch3

$pshost = get-host
$pswindow = $pshost.ui.rawui
$pswindow.WindowTitle = "Generate Commands"

New-Item "C:\CyberTransport\04-Scripts\Powershell-Generate-Command-Sheet-From-CSV\generated.doc" -Force -Type file

$excelFile = "C:\CyberTransport\04-Scripts\Powershell-Generate-Command-Sheet-From-CSV\nodes.csv"
$generatedFile = "C:\CyberTransport\04-Scripts\Powershell-Generate-Command-Sheet-From-CSV\generated.doc"

get-content $excelFile | Where {-not ($_.StartsWith('#'))} | foreach { 

$ipAddress = $_.split("{,}")[0]
$hostname = $_.split("{,}")[1]

$commands = @"
!--- SSH into $ipAddress`r`n
conf t`r`n
hostname $hostname`r`n


$commands | Out-File $generatedFile -Append -Encoding ascii

ii $generatedFile


Leave a Reply

Your email address will not be published. Required fields are marked *