Solved

how to run vb script in powershell

Posted on 2016-11-28
2
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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