Solved

how to run vb script in powershell

Posted on 2016-11-28
2
17 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

10 Experts available now in Live!

Get 1:1 Help Now