0

Hello Stack community I have been trying to search this for a while now but can't seem to find anything. All I want to do is launch a webpage using iexplorer.exe "www.myserverIP.com\dev\emailme.php" It is suppose to be an air gap kind of server that turns on its connection takes a backup of multiple other servers then shuts off its connection. In between turning it on and off I want it to visit my wamp server to run a php script to send me an email of when this happens :D I already made the PHP script. Any other ideas are completely welcome as well I always love trying something new!

Code is provided below:

    # Monday Backup Script

#7zip path:
$path = "C:\Program Files\7-Zip\7z"
$date=get-date -format "%M.%d.yy"

#:: /COPYALL :: COPY ALL file info
#:: /B :: copy files in Backup mode. 
#:: /SEC :: copy files with SECurity
#:: /MIR :: MIRror a directory tree 

#:: /R:n :: number of Retries
#:: /W:n :: Wait time between retries
#:: /LOG :: Output log file
#:: /NFL :: No file logging
#:: /NDL :: No dir logging

# Open Network
netsh interface set interface ethernet enabled

# Alert for Backup

iexplore.exe "http://172.20.255.3/NeikoDev/Backup%20emails/Backup%20Emails.php"
taskkill /IM iexplore.exe /F
# ^^^ THIS IS THE CODE THAT DOESNT WORK FOR THIS ^^^^**



# Wait for network to come online
sleep 120

# Backup NAS to local
ROBOCOPY "\\10.0.5.100\PrivateData\." "D:\PrivateData\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\Monday.txt
ROBOCOPY "\\10.0.5.100\PrivateData1\." "D:\PrivateData1\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate1.txt
ROBOCOPY "\\10.0.5.100\PrivateData2\." "D:\PrivateData2\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate2.txt
ROBOCOPY "\\10.0.5.100\PrivateData3\." "D:\PrivateData3\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPrivate3.txt
ROBOCOPY "\\10.0.5.100\HomeworkArchive\." "D:\HomeworkArchive\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayHomeworkArchive.txt
ROBOCOPY "\\172.20.255.125\PortableDeviceFilesArchive\." "D:\PortableDeviceFilesArchive\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayPorDevArch.txt
ROBOCOPY "\\172.20.255.3\wamp\." "D:\3wampBackups\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayWAMPSERVER.txt
ROBOCOPY "\\172.20.255.123\wamp\." "D:\123wampBackups\." /COPYALL /B /SEC /MIR /R:0 /W:0 /LOG:C:\backups\LOGS\Monday\MondayWAMPSERVER123.txt

# Wait for files to finish
sleep 60

# Zip logs
& $path a Monday.zip Monday*.txt

# Copy to network
cp Monday.zip  "$date.zip"
cp "$date.zip" "\\10.0.5.100\PrivateData\Resource\Network\backuplogs\Monday\$date.zip"

# Wait for network traffic to stop
sleep 120

# Close network
netsh interface set interface ethernet disabled
KenS
  • 30,202
  • 3
  • 34
  • 51
Specters
  • 3
  • 5

2 Answers2

0

As you mentioned in your own comment (by the way, please edit your question instead of commenting on it in the future), this can be done by using an Internet Explorer ComObject:

$IE=new-object -com internetexplorer.application 
$IE.navigate2("www.microsoft.com") 
$IE.visible=$true

# do more stuff until done with IE

$IE.Close()

This way you have better control over IE, and can do things like check if a page is still loading, which I imagine yours would be while running scripts, or if not perhaps your script can forward to a new page when completed, or make some change that your comobject can detect, so you know when to move on or close the site.

Community
  • 1
  • 1
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
  • Awesome yeah sorry It wouldn't let me edit for 5 minutes Ill be sure to wait next time instead of rushing :D – Specters Apr 28 '17 at 17:05
0

You haven't described what the problem is when the script hits line 21. I'm going to assume, without running your script, that the previous line is successfully retrieving the web page within IE but the desired effect is that this window is immediately closed, whereas the taskkill command is failing to shut IE.

If what you want is for the web address to be hit without leaving an open browser window, I would suggest a simpler way to go about this is to request the web address directly from PowerShell and skip the browser altogether.

One way to achieve this in PowerShell v3 is to use Invoke-WebRequest like so:

Invoke-WebRequest -Uri "http://172.20.255.3/NeikoDev/Backup%20emails/Backup%20Emails.php"

But there are similar alternatives outlined here: http requests with powershell

Community
  • 1
  • 1
Daniel Hume
  • 437
  • 4
  • 9