Followers

Simple Powershell Script to Send Email on Windows Server 2012

Sending an email from Server 2012 using Powershell is a VERY simple process.
Below is a very simple example of sending an email using a powershell script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
$message = @"                          
Hello,
I have bad news.  It's not tragic, but you will have to do a small amount of work.
You only have 10% of space left on your hard drive.
You need to do some disk cleanup!!
Thank you,
Your Faithful Web Serving Machine
"@      
$smtpserver="smtp-server-name"
$emailTo = "sample@example.com"
$emailFrom = "administrator@example.com"
$subject="WARNING | WWW | Low Disk Space"
$msg = new-object Net.Mail.MailMessage
$msg.To.Add($emailTo)
$msg.From = $emailFrom
$msg.Subject = $subject
$msg.Body = $message
$smtp=new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($msg)

Deploy Printers via Group Policy on Windows Server 2008 R2

Every office has printers, and they all need to be connected.  If you have an office with a Windows Server domain, you can easily connect your printers using Group Policy.   Your printers and print drivers for your various operating systems must be installed and shared on the server before you begin.
This example is shown using Windows Server 2008 R2. To deploy your printers using Group Policy, you first need to install the Print and Document Services Role.  Open Server Manager, right click Roles, and choose Add Roles.  Select the Print and Document Services role. When installing the role, you need only choose Print server.
Pic1
After you have installed the Role services, go back into Server Manager and browse to Roles\Print and Document Services\Print Management\Print Server\\Printers.  Right-click on the printer you want to deploy, and choose Deploy with Group Policy
Pic2
After you have chosen Deploy with Group Policy, Click Browse to select the Group Policy you want to use, then select it.  After choosing the policy, click the check boxes to assign the printer on a user or computer basis (either per user or per machine).  Then click Add
Pic3
After you click Add, you can see the Printer name, the GPO that you assigned it to, and the Connection Type (per user or per machine).  You can add the printer to as many policies as you want.
 Pic4
Your users should not be administrators of their machines, which means that when your printers attempt to install themselves, it won’t work.  There are some changes that need to be made to the GPO assigning the printers so that non-administrator users can install them.  Open the GPMC (Group Policy Management Console) in Administrative Tools and browse to:
Computer Configuration | Policies | Administrative Templates | Printers
Right-Click Point and Print Restrictions and choose Properties.  Click Enabled.  Clear the checkboxes (if checked) that say “Users can Only point and print to these servers” and “Users can only point and print to machines in their forest”.  In the “When installing drivers for a new connection” box, select “Do not show warning or elevation prompt”.  These settings only apply to Vista and later.  If you are running Windows XP, hang your head in shame, because it’s no longer supported.
Your printers will now be deployed, and installed, on your clients.
Happy printing.
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Administrator

Windows 2012 : Network Load Balancing (NLB) implementation (GUI)


In this post I will the steps for Network Load Balancing implementation.

- NLB is a technology for LBFA ( Load Balancing / Fail Over)  for IP stateless applications (web applications : HTTP , HTTPS, FTP , ...).
- NLB can detect server failure but not app failure.
- NLB can contain 2 to 32 nodes.

*******************************************************************************
I have 2 identical servers, both joined to Domain. Each server has 2 NICs :

NLBServerA  :
           NIC1 => Management Network , IP : 192.168.0.141
           NIC2 => NLB Cluster ,  IP : 192.168.0.142


NLBServerB  : NIC1 => Management Network , NIC2 => NLB Cluster
           NIC1 => Management Network , IP : 192.168.0.143
           NIC2 => NLB Cluster ,  IP : 192.168.0.144





Now I'm going to install IIS and Network Load Balancing Features on both servers (with default settings) :
Now we can open the "Network Load Balancing Manager" in 2 different ways :
1) In System Manager => Tools Menu => Network Load Balancing 
2) or you can open it by running "nlbmgr.msc" command :
The next step is create a New Cluster and add the Hosts to it : 
Type the Host name and click on Connect to see the list of Interfaces available for configuring a new cluster and select the one for clustering :
In the next Window accept the default settings and click on Next :
* Priority (Unique Host Identifier) : This parameter specifies a unique ID for each host. The host with the lowest numerical priority among the current members pf cluster handles all of the cluster's network traffic that is not covered by a port rule. You can override these priorities or provide load balancing for specific ranges of ports by specifying rules on the Port Rules tab of the Network Load Balancing Properties dialog box.
In the next window click on "Add" to enter the Cluster IP address : 
In "Cluster Parameters" window, accept the default settings and leave the Cluster Operation mode as "Unicast" :
* In Unicast mode , the MAC address of the cluster is assigned to the network adapter of the computer,and the built-in MAC address of the network adapter is not used.
** Microsoft recommends to accept the unicast default settings.
In the Port Rules window, you can accept the defaults or Remove the default one and create new Rules for Port 80 , Port 443 or any other port you need :
Click on Finish and after few seconds the first node in Cluster will be ready :
To add the second Host to Cluster, Right click on Cluster and select "Add Host To Cluster" :
Next steps will be exactly the same as before :
Now it's time to create a test page under a new site in IIS :
Create a new folder on C drive (New_Site) and a new text file with some text in it , save it and change the extension of file to "html" :
In IIS , Add a new Website :
Also you need to set the Default Document in IIS and point it to "TestPage.html"
And do the same thing on the second server and create the new site.
The next step is creating a "www" record in DNS and point it to cluster IP address (192.168.0.145 in this example) :
OK, everything is ready and in place now. Just need to do a quick test and show you how NLB Cluster works .
On another machine open the Browser and go to "http://www.NLBCluster.com" :
As you can see it will shot the page on NLBServerB . 
Let's Stop the "NLBServerB" Host  in Network Load Balancing Manager first :
If you refresh the page on the third machine :
It's pointing to the other server up & running in NLB Manager (NLBServerA) and it means NLB Cluster is working find and everything is done successfully :)
*********************************************************************************
To Configure NLB Manager Log Settings :
1) From the Option menu select "Log Settings"
2) check Enable Logging and specify a name and location for the log file :
*********************************************************************************
To Remove a Host from NLB Cluster :
1) Select the Host , right click and first select "Drainstop" , then "Stop"
2) Right click the host and select "Delete Host"

********************************************************************************
If you like to do all these steps with the PowerShell cmdlets, you can go to this link and see the full list of commands and examples :
Source:
http://technet.microsoft.com/en-us/library/ee817138.aspx

You can write a script to automate all these steps and use over and over in your environment if you need.
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Administrator

Introduction to Python Programming in Ubuntu Linux


Introduction to Python Programming in Ubuntu Linux
 
Python is one of a handful of modern programming languages gaining a lot of traction in the development community. It was created by Guido von Rossum in 1990, named after – you guessed it – the comedy, “Monty Python’s Flying Circus”. Like Java, once written, programs can be run on any operating system.
Python ProgrammingI began programming many years ago, and admittedly once I got into networking, turned away from my first love. But for those of you who would like to begin trying your hand at a new language, Python is excellent to start with. Supporters tout its low learning curve and elegant coding system.

Python Installation

Ubuntu makes starting easy, as it comes with a command line version pre-installed. In fact, the Ubuntu community develops many of its scripts and tools under Python. You can begin the process with either the command line version or the graphical Interactive Development Environment (IDLE).

Python Programming From the Command Line

Open a terminal window and type ‘python’ (without the quotes). This opens python in interactive mode.
Python Programming
While this mode is good for initial learning, you may prefer to use a text editor (like Gedit, Vim or Emacs) to write your code. As long as you save it with the .py extension, it can be executed in the terminal window.
Ready to write your first program? Many a road to programming excellence began with the old standby – the Hello World program. So that’s where we’ll begin.
At the prompt, type in print “Hello World!” (with the quotes) and hit enter. You’ll see the command printed on the next line.
Python Programming
To run a script from the command line, type: python my_script.py. To exit the command line, type exit() or hit ctrl+d

Python Programming with IDLE

Can’t imagine writing a long program from the command line? Me either. In that case, you can try IDLE. Open a terminal window and type: ‘idle’. (without the quotes). You’ll see the python graphical shell loaded.
Python Programming
To write a Python script, click on File > New Window. This will open a sort of Notepad type editor. Type in the following code:
#linuxversion.py
#Have user input version and print response
name = raw_input(“What Linux release do you use?”)
print “I also like”, name, ” – Linux rules!”
Couple things going on here. The first 2 lines, preceded by the # sign are just comments. One of my earliest programming lessons was to always comment your work, not only for your own sanity, but for those who may need to edit the code after you. The third statement uses the input gathered from the raw_input function and assigns it to a variable, name. Finally, the print statement will return the result.
Save the file, with a .py extension, then click on Run > Run Module from the menu to run the program.
Python Programming

A Word of Caution

Many programming languages typically ignore whitespace – that is the spacing in your code. But in Python, improper use of spacing can generate syntax errors. As an organization nut of sorts, I can appreciate the simplicity and readability of properly aligned code, but for some this takes a bit of getting used to.

Python Programming Resources

Now that you have Python up and running, you’ll undoubtedly want to move to on to a bit more complex programs. One of the best resources is the main Python website. Here are a few additional recommendations:

Conclusion

I hope you enjoyed this brief glimpse into Python. This is a language supported by a wide community and used by Google, NASA, Ubuntu and others. Give it a try for your next development project. Happy coding!
Ready to test your skills in Python? See how they stack up with this assessment from Smarterer, the newest addition to the Pluralsight family. Start this Python test now.
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Administrator
 

Linux File Permissions

linux-file-permissions_featured-image
What we’ll cover in this article is how to identify permissions for files & directories and how to change them, as well as changing ownerships, groups, etc. Depending on what you want to do, you’ll want to make sure you have the appropriate permissions (obviously), so let’s find out how to change them.
Let’s start by making a file we can use.
I issued the “touch” command to make a file creatively named testfile.
Touch will just create an empty file but has all the same attributes as an actual file. You can see this by using “ls –l.”
Commands:
touch test file
mkdir workfolder
Linux File Permissions 1
The permisions are broken into 4 sections.
Linux File Permissions 2

chmod – adds and removes permissions

If you wanted to add or remove permissions to the user, use the command “chmod” with a “+” or “–“, along with the r (read), w (write), x (execute) attribute followed by the name of the directory or file.
chmod +rwx “name of the file”
chmod –rwx “name of the directory”
Linux File Permissions 3
chmod +x testfile – this would allow me to execute
chmod –wx testfile – this would take out write and executable permissions
You’ll notice that this only changes the permissions for the owner of the file, in this case roman.

Changing Permissions for the Group Owners & Others

The command is similar to what we did before, but this time you add a “g” for group or “o” for users.
chmod g+w testfile
chmod g-wx testfile
Linux File Permissions 4
chmod o+w testfile
chmod o-rwx workfolder
Linux File Permissions 5
Lastly you can change it for everyone: “u” for users, “g” for group, & “o” for others; uog or a (for all).
chmod ugo+rwx workfolder – will give read, write, execute to everyone
chmod a=r workfolder – will give only read perission for everyone

chgrp – changing groups of files & directories

Another useful option is to change file permission to the group owning the file. Perhaps you create the files, but people on the db2 team can write/execute as well. We use chgrp for this purpose.
Linux File Permissions 6
You can see above that testfile and the work folder belong to the users group.
Linux File Permissions 7
By issuing the command – chgrp “name of the group” “name of the file” – you can change this.
chgrp sales testfile
chgrp sales workfolder
This give sales control of the file & then I can take away permissions for everyone else.
Note: The group must exit before you try to assign groups to files and directories.

chown – changing ownership

Another helpful command is changing ownerships of files and directories. The command is “chwon” along with “name of new owner” & “name of file.”
Linux File Permissions 8
The files belonged to roman. To give ownership to tom, issue the command:
chown tom testfile
chown tom workfolder
We can also combine the group and ownership command by:
Linux File Permissions 9
chown -R tom:sales /home/roman/tsfiles
The above command gives tom the ownership of the directory tsfiles, and all files and subfolders. The -R stands for recursive which is why all sub folders and files belong to tom as well.
As opposed to: chown tom workfolder
This command will give ownership to tom but all sub files and directories still belong to the original owner. The -R will transfer ownership of all sub directories to the new owner.
As you can see, you have several options when it comes to permissions. You have the capability to dictate who can do what & the flexibility to limit usability among users. It may be easier to just give all permission to everyone but this may end up biting you in the end, so choose wisely.

Permission in numeric mode

The above way of changing permissions will work fine but you may also need to know how to change permissions in numeric mode. chmod is used in much the same way, but instead of r, w, or x you will use numbers instead.
What are the numbers?
0 = No Permission
1 = Execute
2 = Write
4 = Read
You basically add up the numbers depending on the level of permission you want to give.
Linux File Permissions 10
Examples:
chmod 777 workfolder
Will give read, write, and execute permissions for everyone.
Linux File Permissions 11
chmod 700 workfolder
Will give read, write, and execute permission for the user, but nothing to everyone else.
Linux File Permissions 12
chmod 327 workfolder
Will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for other users.
Permission numbers
0 = —
1 = –x
2 = -w-
3 = -wx
4 = r—
5 = r-x
6 = rw-
7 = rwx
Either variation of changing permissions will work, just remember how to use the numeric values.
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Adminsitrator
 

Linux Text Editors: Vi and Nano


linux-text-editors_featured-image
When working with text editors, you pretty much choose between Vi or Nano. Vi is old school with a blank layout and no visible controls, which can make it difficult to work with for beginners. However, it is very powerful and once you learn the keystrokes it can be used very quickly to edit config files and used for scripts, etc. Nano has a pseudo-graphical layout that makes it a little easier to jump right into. Both are viable options. Vi is a standard whereas Nano has to be available depending on the Linux OS you use. We will look at both and go over the important commands for both.
Let’s look at the difference.
To start Vi, you just have to type “vi” and then the name of the file, or type any name and the file will be created anew.
Example: “vi newfile”
Linux Text Editors 1
Vi will automatically open in Command mode. On the bottom you will see some info such as the name of the document & info on whether it is a new file or an existing one. Let’s look at an existing file.
Linux Text Editors 2
You will see additional info for existing files and more importantly whether you have to write premissions.

Quitting & Saving

There are three modes to Vi: Command mode, Text mode & Ex Mode. If you tried to start typing in command mode you wouldn’t be able to. You need to hit the “I” in order to get into text mode. You can then get back to command mode by the ESC key. Typng “:” will put you into Ex mode.
Linux Text Editors 3
In order to quit Vi, you have to hit the Esc key and then enter in “:” along with “q” for quit.
Linux Text Editors 4
If you get stuck in a file that is Read-Only and you can’t quit, you can enter “:q!” with the exlamation point to force quit. If you want to save changes, hit the Esc key along with “:w”.
Linux Text Editors 5
Linux Text Editors 6
In short, here are the keys for saving and quiting after hitting Esc (Ex mode):
  • :w – Saves
  • :wq or :x – Save & Quit
  • :q – Quit
  • :q! – Force quit, no save

Navigation in Vi

Navigating in Vi is a little more tricky, and this is what gives new users headaches. You just want to keep your fingers on your keyboard as if you are constantly typing (i.e. h, j, k, l). These keys are the substitute for the arrow keys.
  • j – down
  • k – up
  • l – right
  • h – left
  • gg – Takes you to the beginning of the file
  • G(shift + g) – Will take you to the end of the file
  • xxG – Brings you to a specific line in the file(xx is the line number)
  • ( – Move up to the beginning of the sentence
  • ) – Move to the end of the sentence

Insterting Text

  • i – Insert before cursor position
  • a – append after cursor position
  • r – Replace letter
  • o – Open line below cursor position automatically goes into insert mode
  • O – Open line above cursor in insert mode

Deleting Text

  • x – Deletes the character under cursor position
  • X – Deletes the character before cursor
  • dw – Deletes the word after cursor
  • db – Deletes word before the cursor
  • u – Will undo changes

Copy(yank) & Paste

  • yw – Yanks the word after the cursor
  • yb – Yanks the word before the cursor
  • yy – Yanks the entire line
  • p – Will paste
  • P – Will paste before the cursor position

Search

  • / – Is used to search(:/searchword)
Linux Text Editors 7
Linux Text Editors 8

Setting up Vi with numbers

It might benefit some to view the documents with numbers. What you want to do is go into Exec mode(ESC) and then type in “: set number”. Let’s look at the group file:
Linux Text Editors 9
Linux Text Editors 10

Nano

Let’s take a look at workinig with Nano. You start out the same way as you do with Vi by just typing “nano newfile”.
Linux Text Editors 11
The look is a lot different.
Published By
S.G.Godwin Dinesh.MCA
Sr.System Administrator