Solved

how to run vb script in powershell

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Temporary Write Permission for a Drive 15 53
Merge column output 6 34
How to export members from Domain Local Security group ? 10 43
Start-Process Output 3 22
Utilizing an array to gracefully append to a list of EmailAddresses
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

734 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