Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to run vb script in powershell

Posted on 2016-11-28
2
Medium Priority
?
111 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 2000 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

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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