[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] – Run CHKDSK And Repair If Needed.

Free Kaseya Script – Run CHKDSK And Repair

Here is another free script from Cubert’s Dwelling, An Agent procedure that will run a CHKDSK in read only mode. Parse the output and run a chkdsk /F if it meets the criteria set forth in the script. It then emails an alert with the scan results to a email address provided before it uploads a copy of the scan to the get file for storage and review. Finally it updates 2 custom fields in the system info table with a brief result and the last run time. If it finds the disk healthy it will report as such if not it will report one of several error types.

Download Script Here

You will need to unzip the script and import it into Kaseya. Once imported edit the script and find the 2 places it email out and update the email address(es), Then you will need to add the 2 custom fields into your System-info table.

To add the custom fields:
1#  Open Kaseya and go to [Audit] – [View Individual Data] – [System Information] and select the button marked [New Custom Field]

2# The next box that pops up will create a new field, We will need to add 2 fields the first is CheckDisk Status and it will be a type String and Check Disk Updated with a type String.

Now run your disk check and see what it shows. If it meets with the right disk errors, a  repair is sent to the system and a email to you to reboot system when you can so the repair can complete. You can add another execute command under where we call the chkdsk /F with a shutdown -r -t 3 and that will cause the system to reboot its self after issuing the fix cmd. This is great for servers where your scheduling the disk scans during maintenance cycles but not so good with workstations where user gets booted up then a scan runs that then reboots the system will only inflame your users. So be mindful of how you use a shutdown cmd.

Enjoy

Cubert 🙂

XYMON -> New BBWin Client GUI 1.1 Released.

Are you looking for a BBWin Client GUI to configure BBWin.cfg?

Can I see by raise of hand how many of you out there wishes for a good BBWin GUI so you don’t have to edit a that bloody XML file. I am having to flip between Wordpad, Task Manager and the Services console to place in the services and processes I want to monitor on my Windows hosts and that was such a pain.

So out comes BBWin-GUI!

Download file –> BBWin-GUI-1.1

 

BBWin is an open source client for Windows working with BigBrother or Xymon(Hobbit) monitoring software. We also have a custom VM appliance with XYmon and Cacti pre installed and ready to go. See MAG Server here on Squidworks for more information.

Our new BBWin GUI will read in your current BBWin.cfg file and then allow you to edit it. It provides all the services and processes running on your system and pulls all the unique event logs so  you may choose what to accept and what to ignore. Inside the new BBWin-GUI you will find your local disks and the ability to exclude disks as well as set the thresholds for warnings and panics.  Checkout some of the screen shots below.  Download and try BBWin GUI.

 

 

 

 

 


 

 

 

 


 

 

 

 


 

As always I hope this little app helps someone out there.

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

Recursive Access Control Lists with Max Depth

Here is a Visual Basics script I put together which will list all of the Access Control Lists (ACL’s) for all folders in a particular directory.

It allows you to specify a start point and a max depth to recurse.

I needed this so that I could generate a report listing the ACLS’s for various shares. It uses the CACLS executable and as long as you have access to the shares it should run without issue. (However, as with anything Microsoft, I make no guarantees that it will function properly on your system). I tried to account for various idiosyncrasies’ in the way windows operates but if you find a bug, let us know and we will try to correct it.

Download -> ACL List script

How to close cmd or command window after executing a program

Get the CMD.exe Window to close

Do you ever have a bat or cmd file that you have written to do something like update a config file then launch a application or process, and have it fail to close the cmd window after it completes even with the “EXIT” command placed at the end of script?

Yes? Funny…  me too.

Here is what I found fixes the issue.

I have a script that updates the desktop gadgets your profile should launch upon login.  Pretty simple script, it copies the settings.ini file from a network share and places it in your profile directory under “sidebar” and then launches sidebar.exe with a switch. This is a great script for controlling the gadgets seen on a users desktop. (Script example below if you want it)

The problem I was having with this script was I was trying to launch the sidebar application after the update and that was causing the cmd window not to close after it launched the application.

C:\Program Files\Windows Sidebar\sidebar.exe” /autostart

Here is the trick to get a cmd that fails to release after launch in a batch file to actually release.

start “” “C:\Program Files\Windows Sidebar\sidebar.exe” /autostart

If you look at the command, I use the “start” cmd and then supply (“”) a literal nothing as a switch to the “start” cmd. Then in quotes (if spaces exist) the command to run.

Wow, the window now closes after it launches the sidebar application.

I hope this helps some scripter out there with login scripts they are writing. Below you will find a copy of my login script to set gadgets up on Desktop when a user logs in.

 

Here is a little more about the “load default gadgets at login” script.

[Force default gadgets to load on the desktop when a user logs in]

How to force default gadgets on a users desktop, First off to get started you need to setup a profile and launch the gadgets you want on the desktop. Move them where you want them to be on the desktop so that they are placed in the areas you want them. We have dual monitors across our tech team so we placed all gadgets on second monitor.

Now go grab the config file you just created by moving and launching the gadgets you wanted. The default location for the gadget config file in a users profile is:

%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Settings.ini

Lastly we create a batch file to recopy this file each time a user logs in and then launches the sidebar application.

 

Create a new batch file called gadgets.bat then place the following in the file.

REM @echo off
taskkill /IM sidebar.exe /f
copy /Z /Y \\myserver\myshare\Settings.ini  “%userprofile%\AppData\Local\Microsoft\Windows Sidebar\”
start “” “C:\Program Files\Windows Sidebar\sidebar.exe” /autostart

Copy the Settings.ini file to a network share. Edit the “myserver” and the “myshare” to represent your network share that holds the “Settings.ini” file.

Then add it to your users login script active directory properties.  You can also just copy and paste the lines in to an existing login script if your using them to do other things like mapping drives or printers and such.

Download script -> Launch Default Gadgets batch file

 

Kaseya Agent Procedure – FTP Remote Client Backup Script

Backup Windows Systems to a FTP Server

Download: -> Kaseya FTP Backups

So you have Kaseya clients out on the wire that need some level of backup but are not near a NAS or USB Drive. Have thoes clients backup to a FTP server by using WinSCP and a Kaseya Script to do the job for you.

This script has several peices and can be customized for what ever need you have. I currently have the script setup in 3 files.

File #1 (WinSCP_Backup.bat) This is executed by the Kaseya script and passed 2 variables. The variables are the name of the local folder and the name of the remote folder you want to sync.

Example:

c\temp\WinSCP_backup.bat userA FTPdirA >> c\temp\backup.log

We call the BAT file passing “userA” and “FTPDira” this could be the users name for their home directory and the remote directory which could be any folder on your ftp minus the first “/”

File #2 (WinSCP_backup.txt) This file tells WinSCP how to connect to your FTP server and what root directories to start looking in for the folder names provided above. You need to edit this file adding your FTP server information, username and password for FTP if needed.

File #3 is WinSCP.exe, This is a freely available FTP and SCP client for windows that is very configurable and has CLI functions.

This set of scripts in it’s current form will allow you to sync the local systems users home directories to a remote FTP server.

Sync is currently one direction as shown below. But you can sync any way you want.
c:\Documents and Settings\username  -> ftp://ftp.domainname.com/foldername

 Enjoy

Cubert  😎

Scripts to be used at your own descression, no warranty is implied.

How-to Emulate the TOP command in Windows

Top is a Linux process that shows a list of processes running on the system and what levels of resources are being used. This application provides all processes running, the CPU and Memory consumed and with several switches available you can see things like the location of the executable that is running.

Unfortunately, they don’t make a TOP executable ported for Microsoft Windows but don’t despair.   You can

Top is a Linux process that shows a list of processes running on the system and what levels of resources are being used. This application provides all processes running, the CPU and Memory consumed and with several switches available you can see things like the location of the executable that is running.

Unfortunately, they don’t make a TOP executable ported for Microsoft Windows but don’t despair.   You can use Power Shell to script a simple TOP style display that operates just like TOP on a Linux system.

 

Here is the one liner you need to get a top style process viewer running on windows.

while (1) { ps | sort -desc cpu | select -first 30; sleep -seconds 2; cls }

 

Copy the above line and paste it in to your Power Shell console. You should see something similar to the following image.

Kaseya 2 Agent procedures and free scripts

 

www.kaseya.com

 

Do you run Kaseya RMM and need some free scripts?

Here is a compilation of scripts I have created for Kaseya to do different tasks, feel free to use them but keep in mind there is no guarantee. Use at your own discretion!

# Blackberry Enterprise Server ( BES

 

www.kaseya.com


 

Do you run Kaseya RMM and need some free scripts?

Here is a compilation of scripts I have created for Kaseya to do different tasks, feel free to use them but keep in mind there is no guarantee. Use at your own discretion!

# Blackberry Enterprise Server ( BES ) server services restart script.

This script uploads a bat file “Blackberry_Restart.bat” that stops and restarts the Blackberry Enterprise server services in the correct order they need to be done. It the writes a event log entry to the local application event log on windows and then to the script log in Kaseya. Lastly it sends a email to help desk to let them know it ran. Download the zip file, unzip and import the XML file into Kaseya then upload the bat file to your public side Kaseya.

BlackberryES_Restart

# Retrieve IE History

Use this script to collect a logged in users IE history. When the boss wants to know what a users been surfing you can run this against the system and have it email all the links the user has gone to.

This script uploads and executes a VB scrpt (iehistory2.vbs) on the remote system that uses NirSoft’s IE History View utility (iehv.exe) to dump IE URL history addresses for all user profiles on the system into a text file (history.txt). The contents of the text file are then captured into a Kaseya variable and emailed to an address or addresses specified in STEP 7.  Download the zip file, unzip and import xml file in to scripts on Kaseay server then upload the vb script and iehv.exe to Kaseya public file store. Edit the Kaseya script at line item 7 and place in your email address.

IEHistory

# VMware VCenter Health Check

The script grabs the basic state of things on your VMware ESX VCenter VSphere server and posts an HTML file to the “get file” area in Kaseya KLC. It uses a PowerTools Shell to collect the data and create the file. Download the zip, unzip and import the XML file it scripts. Upload the ps1 file to Kaseya Public folder and then edit script and locate the file in script and save script. This will update the script with the location of where you saved the ps1 file.

VMWare VCenter Health Check

#Windows Systems CCleaner Script

This script is a great tool for cleaning of temp files and caches from a users profile on any Windows system. The script looks at the system and determines if it is 64 bit or 32 bit, then it downloads the correct ccleaner.exe file and runs it against the system. In auto mode this script does not clean the registry so it is safe to schedule and run on a regular bases. This works on all 32 and 64 it windows including Windows 2008 R2. A user must be logged in for script to run on users profile.

Kaseya-CCLeaner-Script

Look for more of my scripts here on Squidworks.net

Enjoy

Cubert