Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Monday, May 23, 2016

Powershell Script to set DNS Servers

Your DNS servers have changed.  Your servers have statically set IP addresses and you need to update the DNS entries.  You have a bunch of servers and don't want to do this manually.  This script will run through a text file that you created with all your servers in it.

Assumptions:  You have a file called servers.txt that contains a list of your servers (one on each line).

Copy the text below and paste into a text editor.
Change the line $DNSServers and put in the addresses you want.
Save the file as:  SetDNS.ps1
Open up a powershell window and run.
Check your servers DNS settings to confirm.

Tuesday, October 2, 2012

Managing Self Signed Certs and When They Expire

Have you ever walked in to work one morning to have people jump on you stating nothing is working?  You never got any pages from your monitoring system.  Everything appears to still be up.  Come to find out one of your self sign SSL certificates expired and needs updating.  Well, it has happened to some of the Windows Admins I have worked with.  It is difficult to track and manage self signed certificates.  Even if you have a good handle on it, and have automated reminders about certificates that will expire, it can slip by.  I came across a utility (script) called "ssl-cert-check.bash" found here:  http://prefetch.net/articles/checkcertificate.html  And, this does almost exactly what I want.  This will show you and even e-mail you if you have any servers with expired certificates.  I wanted to take it one simple step further...  I want a report e-mailed to my department regarding the status of all certificated whether they expired or not.  So here is what I did.  On a linux server I put the "ssl_cert-check.bash" file in my utility user's home "bin" directory.  I then created a file called ssldomains.txt (following the format described in the link above) containing the list of servers that have ssl certificates.  I then created a file called "cert_report.bash" in the same bin directory.  It's contents looks like this:
-----------------------------------------
#!/bin/bash
#
# SCRIPT: cert_report.bash
# AUTHOR: Bob
# DATE: Sep 24, 2012
# REV: 1.1.P (Valid are A, B, D, T, Q, and P)
# (For Alpha, Beta, Dev, Test, QA, and Production)
#
# PLATFORM: Not platform dependent
#
# PURPOSE: This script will call another script to report SSL Cert
# expiration days, save to a text file, and e-mail that text
# file.
#
# set -n # Uncomment to check script syntax, without execution.
# # NOTE: Do not forget to put the # comment back in or
# # the shell script will never execute!
# set -x # Uncomment to debug this shell script
#
##########################################################
# DEFINE FILES AND VARIABLES HERE
##########################################################
THIS_SCRIPT=$(basename )

##########################################################
# DEFINE FUNCTIONS HERE
##########################################################
 

##########################################################
# BEGINNING OF MAIN
##########################################################
~/bin/ssl_cert_check.bash -f ~/bin/ssldomains.txt > /tmp/SSL_Cert_Report.txt

echo "Attached is the bi-monthly SSL Certificate Expiration Report." | mutt -s "SSL Cert Check Report" -a /tmp/SSL_Cert_Report.txt mydepartment@mydomain.com

# End of script
----------------------------------------------

I then added an entry in cron for this to run twice a month.
0 8 1,15 * * ~/bin/cert_report.bash

This delivers a nicely formatted report of my servers and their certificate status.  Here is an example of the e-mailed report.

Host                                                    Status        Expires        Days
-------------------------------------------  ------------ ------------      ----
appsrv.mydomain.com:443                Valid       Jul 7 2014      643
lync1001.mydomain.com:443            Valid       Feb 13 2013   134
monitor01.mydomain.com:443          Valid       Feb 13 2013   134
idm.mydomain.com:443                     Valid       Oct 14 2021   3299
mail.mydomain.com:443                    Valid       Jul 10 2014   646
ntsrv1.mydomain.net:3471                 Valid       Aug 30 2013 332
ops1003.mydomain.net:3471              Valid       Feb 13 2013 134
web1003.mydomain.net:4443             Valid       Oct 14 2021 3299
web1004.mydomain.net:4443             Valid       Oct 14 2021 3299
report.mydomain.com:443                  Valid       Jul 7 2014    643
reportdev.mydomain.com:443            Valid       Jul 7 2014    643
srvavautil.mydomain.net:443              Valid      Mar 15 2019 2355
srvmail1002.mydomain.net:443          Valid      Jul 10 2014   646
srvmom01.mydomain.net:443             Valid      Mar 3 2028   5631
srvmoss001.mydomain.net:443           Valid      Aug 1 2013   303
srvocs2001.mydomain.net:443            Valid     Dec 29 2012   88
srvrecord2001.mydomain.net:443       Valid      Feb 13 2013   134
srvslshd1001.mydomain.net:443          Valid      Dec 14 2014   803
srvunibackup1001.mydomain.net:443  Valid      Sep 6 2014    704
srvvault2001.mydomain.net:443          Valid       Sep 6 2014   704
srvwas2001.mydomain.net:443            Valid       Jan 5 2020   2651
srvwcs2001.mydomain.net:443            Expired   Dec 16 2011 -291
app.mydomain.com:443                       Valid       Jul 9 2014     645
sftp.mydomain.com:443                       Valid       Feb 10 2015  861
solarwinds.mydomain.com:443            Valid       Feb 13 2013  134
support.mydomain.com:443                 Valid       Jul 9 2014     645
vcenter01.mydomain.com:443             Valid       Sep 27 2021   3282

Friday, April 6, 2012

Easy way to clean up old (unneeded) files and directories on Windows

As a System Administrator, Care and Feeding of your servers is a crucial task.  Imagine you have a directory containing daily transaction (substitute log, backup, or just about anything else) files.  You need to keep these files for a period of time for auditing purposes, but space is limited and you don't want or need to keep them indefinitely.  What is an Admin to do?  Set a quarterly task to do general clean up?  Yuck.

In Linux it is pretty easy to accomplish this task with the "find" command and its various switches.  How do you do it on a Windows server?  What I am about to show you works on Windows 2008 Servers.  It may not work on Windows 2003 as I believe the syntax for our magic command "forfiles" was a little different.

Below is are the commands you need in a batch file to delete files and/or folders older than "x" days.
Open up notepad or your favorite Windows plain text editor (I like Notepad++ btw).
Enter the following text between the "-----" but not including the "-----"

--------------------------------------------------------
@echo off
rem - The following line is a cya testing line.  It will display the files or
rem - folder that are older than "x" days but does not delete them.
rem - Where you see /d -x
rem - replace x with your criteria.  I will use 30 do anything older than 30 days.
rem - also change your path.  In this example, I want to clean up files in the
rem - E:\SharePointBackup directory older than 30 days.
rem - Uncomment the following "forfiles" line for testing,
rem - but make sure all other lines are commented out.
rem FORFILES /p "E:\SharePointBackup" /s /m *.* /d -30 /c "CMD /C ECHO @FILE"

rem - The following line will delete files older than "30" in given directory
rem - This will just delete files and not remove directories or anything else.
rem - Uncomment the following "forfiles" line to delete files older than 30 days, but make sure
rem - all other lines are commented out.
rem FORFILES /p "E:\SharePointBackup" /s /m *.* /d -30 /c "CMD /C del /Q @FILE"

rem - This will look for directories in a given path older than 30 days
rem - and delete it and all of its contents.  All files and subdirectories in directories
rem - that are older than 30 days.
rem - Uncomment the following "forfiles" line to delete directories older than 30 days, but make sure
rem - all other lines are commented out.
rem FORFILES /p "E:\SharePointBackup" /d -30 /c "CMD /C if @isdir==TRUE RMDIR /S /Q @path"
----------------------------------------------------------------

Save this file on your server as whatever you want with a ".bat" extension.  Example:  delete_older_than_30.bat

Make sure you "test" this on data you wouldn't mind losing before putting it in production.  Once you have tested and have verified it will do what you want it to do, you can schedule a daily (or whatever you'd like) task using the scheduler calling this batch file.

I hope this helps some of you out there.

Wednesday, April 6, 2011

Thermaltake - Dual Bay Docking Station for SATA drives

I bought one of these little gems at Best Buy recently.  I love it.
I use it on my Linux and Windows Servers/PCs to copy, image, and access SATA drives.  It works with 3.5 inch and 2.5 inch SATA drives.  I bought mine on-sale for $59.00.  It can access two drives at a time and can be connected to your computer with the supplied USB or eSATA cable.  This comes in very useful in my line of work.  It sure beats an external inclosure.
You can read more about it here:  http://www.thermaltakeusa.com/Product.aspx?C=1346&ID=1895

Tuesday, April 5, 2011

Backing Up your Laptop or PC - Easy!

I was using a program called G4L to image my laptop or pc but I have found a much easier way.  It works with Linux or Windows, no installation is needed, allows you to resize partitions, backup systems, access files, and recover lost data.  It is a live CD called "Redo".  Check it out here http://redobackup.org/.  It rocks!

Taken from the site:

Redo Backup and Recovery is so simple that anyone can use it. It is the easiest, most complete disaster recovery solution available. It allows bare-metal restore. Bare metal restore means that even if your hard drive melts or gets completely erased by a virus, you can have a completely-functional system back up and running in as little as 10 minutes.


All your documents and settings will be restored to the exact same state they were in when the last snapshot was taken. Redo Backup and Recovery is a live CD, so it does not matter if you use Windows or Linux. You can use the same tool to backup and restore every machine. And because it is open source released under the GPL, it is completely free for personal and commercial use.

Friday, October 30, 2009

Converting a Physical Server (or Virtual Server) to Oracle VM (or Xen)

I needed to move some physical Windows 2003 servers.  The site I wanted to move these servers to already had a substantial Oracle VM Server environment that I had built up.  Oracle VM is based off of Xen.  Using Oracle's P2V whitepaper led me to a converted virtual machine that would not boot.  After much searching I found a process that worked for me.  Pulling from different areas on the web the process I came up with is this.

Note:  This process works for Physical servers or Virtual servers (Example:  VMWare).

   1. On the server you wish to convert you need to do some prep work.  You'll need to make sure the server has ide device drivers available and the registry needs to be made aware.  Believe it or not Microsoft has a KB article that details what we need to do.  The section of this KB article we need is under the heading "More Information".  The article can be found here - http://support.microsoft.com/kb/314082
   2. In summary you need to extract the Atapi.sys, Intelide.sys, Pciide.sys, and Pciidex.sys files from the %SystemRoot%\Driver Cache\I386\Driver.cab file and copy the files to the %SystemRoot%\System32\Drivers folder and then copy the registry section to a file (Example: mergeide.reg) and merge the file in to the registry.
   3. Use the free VMWare converter tool to convert the Physical machine to a vmdk file.  If you are doing this on a server (HP or Dell for example) make sure you unselect any management partitions.
   4. Copy this vmdk file to your Oracle VM (or Xen) Server and run the following command:  # qemu-img convert (filename).vmdk (filename).img
   5. Then create a Windows 2003 guest VM (or which ever the OS is of the box you are converting) and make sure it is shutdown.
   6. Remove the img file for the guest you just created and replace it with the one you created in step 4.  Make sure you rename your new image file to the same name as the one you removed in the beginning of step 6.
   7. The guest VM should boot up.  Once your image is up, remove any VMWare tools or conversion programs and remove any Vendor specific management programs (example HP or Dell utilities).


Done.  This process worked for me.  Hope it will help you too.

Wednesday, September 23, 2009

Imaging Your PC or Server

I have been using an open source tool called G4L for a while to create images of my PCs and Servers.  I figured I would share my process to help others looking to get images of their Windows or Linux Servers or PCs.  Hope this helps some of you out there. Of course, do this at your own risk. If you are not careful you can really mess things up.

Creating a server Image:

Prerequisites:
1. Laptop on the same network as the device to be imaged
2. FTP server on the Laptop capable of supporting files over 4GB.
FileZilla recommended.
http://filezilla-project.org/download.php?type=server
3. USB Harddrive connected to the laptop with two directories: img and g4l (by default g4l will look for and create images in the /img directory)
4. Get the g4l scripts (files3.tar.gz). File can be obtained at: http://sourceforge.net/projects/g4l/files/
5. Unzip the zip file to the g4l directory on the USB drive.

Assumptions:
1. You are using a CDROM ISO that is appropriate for your hardware platform architecture.

Windows or Linux - Use the G4L ISO. If you run in to issues regarding drivers, etc use Knoppix or System Rescue ISO.
     http://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/1.3.0/
     http://sourceforge.net/projects/g4l/files/g4l%20ISO%20images/g4l-v0.30.iso/g4l-v0.30.iso/download
     http://knopper.net/knoppix-mirrors/index-en.html
2. Server can be booted from CDROM Drive
3. Server can see the network after being booted from CDROM
4. FTP Server is started on the laptop, anonymous access granted, read/write/delete access granted, and the laptop is connected to the network.
5. Root directory of your FTP Server is your external USB hard drive attached to the laptop.

Instructions:

1. Boot Server from CDROM. G4L-ISO, Knoppix or System Rescue CD
1a.  If you are using the G4L-ISO you can skip down to step 17 assuming you have a DHCP server handing out an IP address.
2. Set IP Address if one was not assigned via DHCP (ifconfig eth0 10.10.10.75 netmask 255.255.255.0) - use your own IP and netmask here.
3. Test network connectivity by pinging the FTP server
4. Create directory /tmp/g4l (mkdir -p /tmp/g4l)
5. Change directories to /tmp/g4l (cd /tmp/g4l)
6. FTP to the FTP Server (ftp 10.10.10.17) - Use the IP of your FTP server.
7. Log in (anonymous)
8. Change to the g4l directory (cd g4l)
9. Turn on binary mode (bin)
10. Turn on hash mode (hash)
11. Turn off prompt (prompt)
12. Get the g4l scripts (mget *)
13. quit
14. Change directories to / (cd /)
15. export PATH=$PATH:/tmp/g4l/
16. chmod 777 /tmp/g4l/*
17. Run G4L (/g4l)
18. Answer the following prompts: Yes, OK, OK
19. Config option D with the appropriate IP Address of the FTP Server
20. Config option E - Set the username and password (anonymous:foo)
21. Config option F - Set the name of the file you will be creating
22. Select Option H
23. Select the partition/drive you want to image
24. Confirm image process is under way
25. Wait.
26. When complete, you can exit the g4l utility and halt the system.

Restoring a Server Image:

Prerequisites:
Same as above

Assumptions:
Same as above AND
1. The drive you will restore the image to is the same size or larger than the size of the drive you took the image from.
2. You know that by restoring your image to a drive of larger size will not automagically make your partition larger. If you restore to a larger drive you will need to use another tool (like gparted live) to change the size of your partitions.
3. You are fully aware that any data that existed on the drives prior to doing the restore will be wiped out. Make sure you restore an image to new drives, drives that contain no data, or drives you don't mind being wiped out.

Instructions:
Follow the same steps above until you get to #21
1. Here for option F, instead of putting in a name of an image to create, you will select the name of the image already created.
2. Instead of selecting option H to do a backup, select option I to restore.