Solved

how to run vb script in powershell

Posted on 2016-11-28
2
32 Views
Last Modified: 2016-11-29
I have a vb script that will start a command prompt, connect to a switch then save the switch configuration to a tftp server.  Is there a way to either rewrite this in powershell or run this vb script from powershell?  I am looking to run this for multiple switches so I would assume I would be using a for each on an array of IP address for the switch.  

<job>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet 172.24.209.254 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("^Y")
WScript.Sleep 1000
WshShell.SendKeys ("EN")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys ("copy running-config tftp address 172.24.109.124 filename Backup2.txt")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("logout")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Quit 
</script>
</job>

Open in new window

0
Comment
Question by:Roccat
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41904685
You can use SendKeys with Powershell as well:
$TargetList = @(
	'172.24.209.254'
	'172.24.209.1'
)

Write-Warning "DO NOT CLICK ANYWHERE WHILE THIS SCRIPT IS RUNNING!"

$WshShell = New-Object -ComObject 'WScript.Shell'
Start-Process -FilePath 'cmd.exe'
Start-Sleep -Seconds 1
$TargetList | ForEach-Object {
	$WshShell.SendKeys("telnet.exe $($_) 23")
	$WshShell.SendKeys('{Enter}')
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('^Y')
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('EN')
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('{Enter}')
	Start-Sleep -Seconds 3
	$WshShell.SendKeys("copy running-config tftp address 172.24.109.124 filename Backup_$($_).txt")
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('{Enter}')
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('logout')
	Start-Sleep -Seconds 1
	$WshShell.SendKeys('{Enter}')
}

Open in new window

1
 

Author Closing Comment

by:Roccat
ID: 41905629
Thank you!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select tabs in Word with Powershell 8 43
Powershell script 13 60
need a script to alert when there are delta vmdk's building on the VM's 3 29
exchange, outlook 2 27
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
A brief introduction to what I consider to be the best editor for PowerShell.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now