I’ve been able to SSH into my TPLink Router (ER605) and create a VLAN successfully.
But when I try to send the same commands through a script, it doesn’t work. So far, I’ve tried netmiko/paramiko (python), bat files, and ps1 files.
Here’s the contents of the commands.txt file:
enable
configure
vlan 11
name created_using_automated_SSH
exit
exit
And here is the script:
# Variables
$router_ip = "192.168.0.1"
$username = "admin"
$password = "password_goes_here"
$plink_path = "C:Program FilesPuTTYplink.exe" # Adjust this path as needed
# Read commands from the file
$commands = Get-Content -Path "commands.txt" -Raw
# Construct the plink command
$plink_command = "&'$plink_path' -ssh $username@$router_ip -pw $password -batch -m commands.txt"
# Execute the plink command and capture output and error
Write-Output "Executing plink command..."
$output = Invoke-Expression $plink_command 2>&1 | Out-String
# Display the output
Write-Output "Output:"
Write-Output $output
# Check if the VLAN creation was successful
if ($output -like "*VLAN creation and configuration completed*") {
Write-Output "VLAN created successfully"
} else {
Write-Output "VLAN creation failed. Please check the router configuration."
}
The script always fails.
Any help on how to go about it, would be really appreciated!
Many thanks!
1