I want to invoke telnet.vbs
within my PowerShell script.
That script should restart the host $line
in every iteration of foreach loop.
telnet.vbs
script:
Option explicit
Dim oShell
set oShell= Wscript.CreateObject("WScript.Shell")"
oShell.Run "telnet"
WScript.Sleep 3000
oShell.Sendkeys "open $line~"
WScript.Sleep 5000
oShell.Sendkeys "y~"
WScript.Sleep 5000
oShell.Sendkeys "fusion~"
WScript.Sleep 4000
oShell.Sendkeys "tnniw~"
WScript.Sleep 4000
oShell.Sendkeys "shutdown -r -t 0~"
Wscript.Quit}
I want to run this script in loop and inside telnet.vbs
, $line
should be replaced in every iteration:
foreach($line in $servers)
{
& .\telnet.vbs
}
I tried this:
(Get-Content .\telnet.vbs).Replace("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))","$line") | Set-Content .\telnet.vbs
But it do nothing. Certainly the syntax is wrong.