[VB Script] Automate the copy of folders across the network to a local removable drive in Windows.

So you need a quick method to grabing folders from a UNC path and place a copy of them on a removable drive.  I had a customer who wanted to do the old USB drive swap for off site backup storage. I tried to explain that now with the advent of the cloud we could move the files off site without any user intervention but they really wanted to do it manually.

So here is a Automated script to help with a manual process.

Download Script Here

Here is the basic beak down of the script.

In the first part of the script we set the email server to relay mail to, our domain name and the email addresses we want to send reports to.

‘ Company Internet Domain Name
ODomain = “mydoamin.com”
‘ Set the SMTP server IP
oMyIP = “192.168.1.5”
‘ Where do you want the message to be delivered
oTo = “myemail@mydomain.com;another@email.com

This next part sets up the local directory we will be copying to, The script during execution will delete all things off the drive and then rebuilds the directory structure you want so we have to tell it the directory we want added back after the delete.

‘### Check folders exist and prep for copy

Dim oName, ODomain, oMyIP, oTo, newfolder, newfolderpath
Set FSO =CreateObject(“scripting.FileSystemObject”)

‘###Change my folder path  ######################
If FSO.FolderExists(“F:\Backup\”) Then 
   FSO.DeleteFolder “F:\Backup”
   wscript.sleep 90000
End If

‘##### Change My folder path#########
newfolderpath = “F:\Backup”
If Not FSO.FolderExists(newfolderpath) Then
   Set newfolder = FSO.CreateFolder(newfolderpath)
   wscript.sleep 5000
End If

 

Now we need to start the actual copy and get some files on our removable disk. You will need to edit the “newfolderpath” so it reflects where you want the files copied to. You will need to edit the FSO.CopyFilder so that it resembles your UNC path. You can copy the em=ntire code block and repeat over and over again for multiple UNC paths or folders.

‘###Grab files and place them in new folder (We must create that new folder now)

‘###  Change my new folder path ###################
newfolderpath = “F:\Backup\MyNewfOLDER”

If Not FSO.FolderExists(newfolderpath) Then
   Set newfolder = FSO.CreateFolder(newfolderpath)
End If

FSO.CopyFolder “\\MyIP Address\MyShare\MyFolder”, “F:\Backup\mYNewFolder” ,True
wscript.sleep 5000

‘### You can copy the top several lines starting with the new folder creation and repeat as many times as needed. This will allow for mulitple locations and folder

Next we write an event log in windows reporting that we completed the copies.

Set WshShell = WScript.CreateObject(“WScript.Shell”)
strCommand = “eventcreate /T Warning /ID 99999 /L SYSTEM /D ” & _
    Chr(34) & “The Script has completed the scheduled backup copy to the offsite drive (F:)” & Chr(34)
WshShell.Run strcommand

Then we send off a email to the users we set in the above script area.

‘ Get the computer name
Set WshNetwork = CreateObject(“WScript.Network”)
oName = WshNetwork.ComputerName
‘ Set the visual basic constants as they do not exist within VBScript.
‘ Do not set your smtp server information here.
Const cdoSendUsingMethod = “http://schemas.microsoft.com/cdo/configuration/sendusing“, _
cdoSendUsingPort = 2, _
cdoSMTPServer = “http://schemas.microsoft.com/cdo/configuration/smtpserver

‘ Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject(“CDO.Message”)
Set iConf = CreateObject(“CDO.Configuration”)
Set Flds = iConf.Fields

‘ SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

‘ Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With

‘ Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oName & “@” & oDomain
.Subject = “Backup Copy to Offsite Drive Started”
.TextBody = “The NTVI Server Backup copying is now taking place. The drive should be ready to remove offsite.”
End With

‘ An attachment can be included.
‘iMsg.AddAttachment Attachment

‘Send the message.
iMsg.Send

Thats it, You can download a zipped copy of the entire script using the above link.

I hope this helps you, Enjoy..

Cubert

Kaseya Agent Procedure -> Alert if Privileged Account are changed in Active Directory

Out of the skunkworks here at Squidworks comes a new Kaseya Agent Procedure. This procedure (Script) pulls all members of privileged accounts groups like Domain Admins, Enterprise Admins and Schema Admins and stores it to the GETFILE location on your K-Server. Also viewable using LiveConnect -> Agent Data -> GetFile Tab.  You can add and remove groups from the VBScript to match your needs. The nice thing about this script is it finds out what your Forest is and queries the domains inside. You do not need to edit script for every domain in your customer base. This 1 script will query any domain it is pointed at, with out knowing what the domain name is! (Sweet) This makes it a great tool to deploy across all customers as it requires no edits to run on any domain.

The script should be scheduled to run every day, each time it is run it copies a new file up to the GETFILE area and does a compare of the 2 files. If they are not exactly the same it will send an alert that a change has happened.

You then need to watch for this alert to happen and alarm on it. To do this you will goto your Monitor tab in Kaseya. In the main menu under Agent Monitoring select Alerts. In the main window under alerts you will find a drop down selection box called “Select Alert Function“. In this drop down list locate and select “Get Files” then select the AD server you are running the script on and set it to Alarm and email you upon change.

That’s It. It will check your accounts and if a change takes place it then alerts you that a change has happened to which you can investigate. This works great if you need to keep people out of these privileged accounts groups. 

AD Admin Audit Kaseya Script Zip

Enjoy

Cubert

VBScript code: View CPU usage for a process name

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU usage for each process it finds that matches the Process Name provided.

Then I would copy the code below to a .vbs file and run it in a the CLI.


DIM MyPID(20), objProcess, objItems, objitem
DIM XX, I
XX = -1
set objService = getobject("winmgmts:")
for each Process in objService.InstancesOf("Win32_process")
if Process.Name = "svchost.exe" Then XX = XX + 1
if Process.Name = "svchost.exe" Then MyPID(XX) = Process.processid
Next
For I = 0 To 20
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &MyPID(I)& "")
for each objItem in objItems
Wscript.Echo MyPID(I) & " = " & objItem.PercentProcessorTime

Next
Next

More VBScript created for BBWin External testing for www.AlertOnFailure.com

AOF adds VBScript created for BBWin External testing to it’s library

[ipconfig]

Microsoft Networking Information Overload
What a name! The MOAB of network information this jewel of a script dumps out all sorts of good information to have at your finger tips.

In this version there is only one status of green so you

AOF adds VBScript created for BBWin External testing to it’s library

[ipconfig]

Microsoft Networking Information Overload
What a name! The MOAB of network information this jewel of a script dumps out all sorts of good information to have at your finger tips.

In this version there is only one status of green so you can’t place a notification on this test but it does provide some really good data to have at your finger tips.

It provides:

All IP, Wins and DNS information
The System name, domain name and current logged in user
All Network Login Profiles
Dump of your routing table
All Network Clients Installed
Host Proxy Server Information
All Network Adapter Configuration Properties

[defrag]

defrag checks each fixed drive on the host and reports back a status of yellow if any drive needs defraging.

Else if all drives report no defrag needed the status is green.

The report shows up as a “System Dot” called “defrag” and you can assign alert notifications to this test. Currently the test only reports a status of yellow or green. there is no red status in this test.

[PWRmgt]

PWRmgt confirms the current power management setting and any power supply alarms and reports the information back to the AOF server.

This does include status changes, Green, Yellow and Red based on the nature of the issues.

This test creates a “System DOT” called “PWRmgt” on the AOF display and can be used to set alert notifications to.

Get Scripts Here

New VBScript created for BBWin External testing for www.AlertOnFailure.com

I’ve created 2 new VB scripts to use with AOF and BBWin’s External test functions. These scripts were tested on BBwin 0.12 and AOF Beta and work great!

[RePing] Ping multiple internal host addresses

Provides the ability to ping multiple host behind a firewall or other device, Great is you need to test to see if a Wireless AP is up or if a network printer is

I’ve created 2 new VB scripts to use with AOF and BBWin’s External test functions. These scripts were tested on BBwin 0.12 and AOF Beta and work great!

[RePing] Ping multiple internal host addresses

Provides the ability to ping multiple host behind a firewall or other device, Great is you need to test to see if a Wireless AP is up or if a network printer is available. There are many systems that do not run a agent that you can ping to see if they are up and running. This all gets reported back to the AOF servers and placed as a “System Dot” called “RePing”. If a host fails to will change status. You can use this to get remote notifications of failures by placing a alert notification rule to the test.

See Script file

[Wares] List All Installed Software on AOF server (BBDisplay)

Wares.vbs is a visual basics script used to upload a list of installed software on a windows host.  In version one we are sending just the data, no status changes are happening. Version 2 will have the ability to alert if apps are added or removed.

See VB Script

These were developed to be used with www.alertonfailures.com  free system monitoring and management services but the scripts will work just fine with any XYmon server or BBDisplay server.