Archive for the ‘IT Pro’ Category

Using Windows PowerShell as an IT Pro – Part 20

Tuesday, July 12th, 2011

In my last post I finished looking at operators. Now let’s take a look at controlling flow. Up until now most of what we have gone over could be single line commands or commands that are part of a larger script. When you start using flow control then you pretty much have a script on your hands. Of course you don’t have to put any of the code in an actual script file and you can always type\cut and paste it directly into the PowerShell UI (which is what we will show in this blog post).

Like most programming languages, Windows PowerShell allows you to control the flow of your scripts to test and evaluate different conditions. This conditional logic allows you to write dynamic scripts that execute based on the data processed, primarily achieved using the variations of the If statement and different loops. In this blog post I will go over the If statement.

You can use the If statement to run code blocks if a specified conditional test evaluates to true. You can also specify one or more additional conditional tests to run if all the prior tests evaluate to false. Finally, you can specify an additional code block that is run if no other prior conditional test evaluates to true. To explain this further we will use some examples.

This first example uses only a single If statement and does not contain any Elseif statements or any Else statements.

if (6 -gt 4)

{

Write-Host "The value is greater than 4."

}

FlowIf01

In this example, if the If statement is evaluated as false then nothing happens.

For the If statement and other statements in this section, the code has been laid out as if you were writing a script. This means that the code is spread out using multiple lines, making it easier to read. Because the syntax of the statements is free-form in regards to white space (the amount of space between the different components of a command) you can structure your code how you see fit. For example, we could take the code above and place it all on a single line like this:

if (6 -gt 4){Write-Host "The value is greater than 4."}

FlowIf02

In our second example, we added the else statement. This first part of the code executes just as before and the If statement is evaluated as True or False. If it is True, then the Write-Host cmdlet is run like before. By adding the else statement, we can now execute something else if the If statement evaluates to False. In this example, we execute another Write-Host cmdlet.

if (12 -gt 12)

{

Write-Host "The value is greater than 12."

}

else

{

Write-Host "The value is NOT greater than 12."

}

FlowIf03

In our next example, the elseif statement is added. This allows us to evaluate a second condition in addition to the first one. Multiple elseif statements can be used to chain a series of conditional tests so that each test is run only if all the previous tests are false.

if (12 -gt 12)

{

Write-Host "The value is greater than 12."

}

elseif (12 -eq 12)

{

Write-Host "The value is equal to 12."

}

else

{

Write-Host "The value is NOT greater than 12."

}

FlowIf04

In this example we evaluate the first if statement. If it is True, then the first Write-Host cmdlet is executed. If it is False, then the elseif statement is evaluated. If the elseif statement is True, then the second Write-Host cmdlet is executed. If the elseif statement is False, then the else statement is executed and the third Write-Host cmdlet.

In my next post we will look at other flow control statements.

Share

Using Simulations Instead of Videos or Test\Demo Environments for Training – Part 1

Friday, June 24th, 2011

I have been developing technical training and presentations for about 12 years now. Until recently whenever the training or presentation required an application or server I used some version of the real thing. Either it was an actual installation of the application or a real server(s) or a Virtual Machine (VM) of the server(s). Obviously having the real thing gives you the most options for what you can do but it also has a downside. The application might have dependencies that make it difficult to run in a classroom, on your laptop, or just sitting at your desk. Using virtual machines makes building and using servers easier but they can also take up a lot of disk space and require a lot of processing power. Not always things that you have in abundance.

Recently I have been working more and more with simulations instead. These have sometimes been linear click-thrus where you basically follow the dots and perform predetermined tasks, and other times that have been more robust simulations that feel like the real thing. The click-thru simulations look real but you can tell you are not using a live interface. Typically these jump from screenshot to screenshot with hotspots for clicking something on the screen or typing text. These work well for performing specific tasks but it is difficult to go off the map so to speak and do something on the fly. These simulations are similar to what you can build with Captivate or DemoMate.

Other simulations I have been working with lately are more dynamic and can give you as much of the real interface as you want to put into them. With these the interface responds just like the real one and it is hard to tell you are not using the real thing. You don’t have to follow a linear script and you can go off the map if you enabled whatever it is that you are trying to show. These are better if you want to simulate an environment rather than just having a simulation that allows you to perform specific tasks in that environment.

Simulations are small and can be moved around easily or accessed remotely through a browser. Using a simulation for training purposes requires that the user actually perform the steps rather than just watching them. This helps them retain the knowledge better having done it themselves. Also with a simulation they can use it more than once without a lot of hassle and further increase the chance that they will remember the training. If the simulation is hosted where the user can access it through a browser then they can use it whenever they are unsure of something and make any mistakes in the simulation and not their real environment.

So that gives you a rundown on simulations and why they are useful. In my next post I will go over the reasons why and when you would want to use one instead of a test\demo environment or just a video.

Share

Using Windows PowerShell as an IT Pro – Part 19

Wednesday, June 22nd, 2011

In my last post I looked at comparison operators. Let’s finish by reviewing the logical operators.

The logical operators connect expressions and statements, allowing you to use a single expression to test for multiple conditions. Statements that use the logical operators return Boolean (TRUE or FALSE) values.

Windows PowerShell supports the following Logical operators.

  • -and – returns a TRUE value when both statements are true.
  • -or – returns a TRUE value when one or both statements are true.
  • -xor – returns a TRUE value when one statement is true and the other is false.
  • -not – This one negates, or reverses, the statement that comes after it.  So if you had a statement that would normally return a TRUE value, if you used –not it would now return a FALSE value.

The Windows PowerShell logical operators evaluate only the statements required to determine the truth value of the statement. If the left operand in a statement contains the -and operator is FALSE, the right operand is not evaluated. If the left operand in a statement that contains the -or statement is TRUE, the right operand is not evaluated. As a result, you can use these statements in the same way that you would use the If statement (covered in the next section).

As an example, the following statement uses the -and operator and the -or operator to connect three conditional statements. The statement is true only when 4 is greater than 3, and either 4 or 21 is less than 20.

(4 -gt 3) -and ((4 -lt 20) -or (21 -lt 20))

LogOper01

If we add –not before the first conditional statement then the value returned is reversed since the first condition is negated.

-not(34 -gt 33) -and ((4 -eq 5) -or (19 -lt 20))

LogOper02

In my next post we will move on to controlling the flow.

Share

Using Windows PowerShell as an IT Pro – Part 18

Tuesday, June 14th, 2011

I’m finally getting back to my blog and PowerShell. In my last post I was looking at Comparison Operators. There are a couple more that I want to take a quick look at.

The match operators (-match and -notmatch) find elements that match or do not match a specified pattern using regular expressions, searching only in strings. They cannot search in arrays of integers or other objects. The following examples show some uses of the -match operator.

"Professional", "Baseball" -match "Ball"

CompOper13

 

"Professional", "Ball" -match "Baseball"

CompOper14

The -match and -notmatch operators populate the $Matches automatic variable when the input (the left-side argument) to the operator is a single scalar object. When the input is scalar, the -match and -notmatch operators return a Boolean value and set the value of the $Matches automatic variable to the matched components of the argument.

If the input is a collection, the -match and -notmatch operators return the matching members of that collection, but the operator does not populate the $Matches variable.

For example, the following command submits a single string to the -match operator. The -match operator returns a Boolean value and populates the $Matches automatic variable.

"Baseball" -match "Ball"

$Matches

CompOper15

Replace Operator

The -replace operator replaces all or part of a value with the specified value using regular expressions. You can use the -replace operator for many administrative tasks, such as renaming files. The following example shows a use of the -replace operator:

"PowerShell_1" -replace "1", "2"

CompOper16

In my next post we will look at Logical Operators.

Share

Using Windows PowerShell as an IT Pro – Part 17

Thursday, April 22nd, 2010

In my last post I looked at some Comparison Operators. Now I will examine some more Comparison Operators.

Greater than and Less than operators

The greater than operator (-gt) returns a value of TRUE or the matches when one or more of the input values is greater than the specified pattern. The less than operator (-lt) returns a value of TRUE or the matches when one or more of the input values is less than the specified pattern. When the ‘or equals to’ operators (-ge, -le) are used, they also compare to see if the value is equal to the specified pattern.

The following examples show the effects of these operators.

8 -gt 7

CompOper05

8 -ge 8

CompOper06

"c" -lt "a"

CompOper07

"a" -le "c"

CompOper08

1, 2, 3 -le 2

CompOper09

Containment Operators

The containment operators (-contains and -notcontains) are similar to the equality operators. However, the containment operators always return a Boolean value, even when the input is a collection.

Also, unlike the equality operators, the containment operators return a value as soon as they detect the first match. The equality operators evaluate all input and then return all the matches in the collection. In a very large collection, the -contains operator returns results quicker than the equal to operator. The following examples show the effect of the -contains operator.

1, 2, 3 -contains 2

CompOper10

"PowerShell" -contains "Shell"

CompOper11

"Windows", "PowerShell" -notcontains "Shell"

CompOper12

In my next post we will finish looking at Comparison Operators.

Share

Using Windows PowerShell as an IT Pro – Part 16

Friday, April 16th, 2010

In my last post I looked at Assignment Operators. Now I will examine Comparison Operators.

Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. To use a comparison operator, specify the values that you want to compare together with an operator that separates these values.

By default, all comparison operators are case-insensitive. To make a comparison operator case-sensitive, precede the operator name with a "c". For example, the case-sensitive version of "-eq" is "-ceq". To make the case-insensitivity explicit, precede the operator with an "i". For example, the explicitly case-insensitive version of "-eq" is "ieq".

All comparison operators except the containment operators (-contains, -notcontains) and type operators (-is, -isnot) return a Boolean value when the input to the operator (the value on the left side of the operator) is a single value (a scalar). When the input is a collection of values, the containment operators and the type operators return any matching values. If there are no matches in a collection, these operators do not return anything. The containment operators and type operators always return a Boolean value.

Windows PowerShell supports the following comparison operators.

Operator

Description

-eq

Equal to. Includes an identical value.

-ne

Not equal to. Includes a different value.

-gt

Greater-than.

-ge

Greater-than or equal to.

-lt

Less-than.

-le

Less-than or equal to.

-like

Match using the wildcard character (*).

-notlike

Does not match using the wildcard character (*).

-match

Matches a string using regular expressions. When the input is scalar, it populates the $Matches automatic variable.

-notmatch

Does not match a string. Uses regular expressions. When the input is scalar, it populates the $Matches automatic variable.

-contains

Containment operator. Includes an identical value that is not part of a value. Always returns a Boolean value.

-notcontains

Containment operator. Does not include an identical value. Always returns Boolean.

-replace

Replace operator. Changes the specified elements of a value.

Equality Operators

The equality operators (-eq, -ne) return a value of TRUE or matches when one or more of the input values is identical to the specified pattern. The entire pattern must match an entire value.

The following examples show the effect of the equal to operator:

"a" -eq "A"

CompOper01

"a" -ceq "A"

CompOper02

1, 2, 3 -eq 2

CompOper03

"Power" -ne "Shell"

CompOper04

In my next post we will examine more Comparison Operators.

Share

Exchange 2010 Server Roles

Monday, April 12th, 2010

Exchange server roles were introduced three years ago with Exchange Server 2007 as a way to group specific Exchange management tasks together often on separate dedicated servers. Think of Exchange Server roles as similar to the Windows Server server roles, you CAN run all the roles on the same server, but generally it is not a good idea in anything other than the smallest deployments. For example, if you download the Hyper-V Evaluation VHD for Exchange 2010 testing, that server has all the roles installed on a single virtual machine.

The server role groups a set of features and components which perform specific functions in the messaging infrastructure. By using server roles you are able to reduce the attack surface of the Exchange Server and allows you to deploy and customize Exchange to fit your business goals and needs.  The Exchange Server 2010 server roles are as follows:

  • Mailbox Server: This is the host server for all mailbox and public folder databases. Address lists and offline address books are also generated and maintained on the Mailbox server. The server indexes all the databases and provides the ability to search across multiple mailboxes and Public folders. The Mailbox server also enforces messaging records management and retention policies for the organization.
  • Client Access Server: The CAS is basically the communication gateway between the messaging client and the mailbox. The server hosts the client protocols for mail access including POP3, IMAP4, HTTPS, Outlook Anywhere, the Availability service, and the Auto-discover service.
  • Unified Messaging Server: Unified Messaging basically refers to the marriage between e-mail and the telephone system. This allows you to access your voice mail through your email client, and allows you to access your e-mail through your telephone (system can read your email to you). Users can also receive faxes through this integration.
  • Hub Transport Server: The Hub Transport server is the router for the Exchange organization. This handles all mail flow inside the organization, applies transport rules, applies journaling policies, and delivers messages to the recipient.
  • Edge Transport Server: This server is your protective layer between the internal messaging environment and the outside world. Anti-spam and Antivirus scanning take place on the Edge Transport server. As such, this server is typically placed on a perimeter network with a firewall on either side of it, meaning a firewall between the Internet and the perimeter and a firewall between the perimeter and the company network.
Share

Using Windows PowerShell as an IT Pro – Part 15

Thursday, April 8th, 2010

In my last post I reviewed Arithmetic Operators. Now I will explore Assignment Operators.

Assignment operators assign one or more values to a variable and perform numeric operations on the values before the assignment. Windows PowerShell supports the following assignment operators.

Operator Description
= Sets the value of a variable to the specified value.
+= Increases the value of a variable by the specified value, or appends the specified value to the existing value.
-= Decreases the value of a variable by the specified value.
*= Multiplies the value of a variable by the specified value, or appends the specified value to the existing value.
/= Divides the value of a variable by the specified value.
%= Divides the value of a variable by the specified value and then assigns the remainder (modulus) to the variable.
++ Increases the value of a variable, assignable property, or array element by 1.
Decreases the value of a variable, assignable property, or array element by 1.

The assignment operator (=) assigns values to variables. If the variable already has a value, the assignment operator (=) replaces the value without warning. Since the assignment operator has been mentioned multiple times in this training, no additional details are included here.

The assignment by addition, subtraction, multiplication, and division operators all work more or less the same way. For numeric types it takes the first part of the operator (+, -, *, /) and performs the appropriate calculation and then it assigns the result. For strings, it appends the specified value to the existing value. The assignment by subtraction and division operators do not work with strings. Let’s take a closer look at several of these operators.

The assignment by addition operator (+=) either increments the value of a variable or appends the specified value to the existing value. The action depends on whether the variable has a numeric or string type and whether the variable contains a single value (a scalar) or multiple values (a collection). First, it adds, and then it assigns.

$a = 5

$a += 2

$a

Operator06

When the value of the variable is a string, the value on the right side of the operator is appended to the string.

$a = "String"

$a += ” Appended”

$a

Operator07

The assignment by subtraction operator (-=) decrements the value of a variable by the value that is specified on the right side of the operator. This operator cannot be used with string variables and it cannot be used to remove an element from a collection. First, it subtracts, and then it assigns.

$a = 5

$a -= 2

$a

Operator08

The increment operator (++) increases the value of a variable by 1. When you use the increment operator in a simple statement, no value is returned.

$a = 6

++$a

$a

Operator09

The decrement operator (–) decreases the value of a variable by 1. As with the increment operator, no value is returned when you use the operator in a simple statement. Use parentheses to return a value.

$a = 6

(–$a)

Operator10

In my next post we will examine Comparison Operators.

Share

Exchange 2010 Deployment Assistant

Thursday, April 1st, 2010

As I’ve been working through some of the new Exchange 2010 material recently, I came across the Exchange 2010 Deployment Assistant. This tool is also called ExDeploy, which if you remember working with Exchange 2003 is the same name as the Deployment Tool from that version. So this is not exactly a new idea, but let’s take a look at what they put together for Exchange 2010.

The Exchange 2010 Deployment Assistant is a web based tool that basically gathers information about your environment and uses that information to create a customized checklist detailing the procedures that will help to simplify your Exchange 2010 deployment.

To access the Exchange 2010 Deployment Assistant, go to the following web site:
http://technet.microsoft.com/en-us/exdeploy2010/default.asp

On the home page, you will choose one of four options:

  • Upgrade from Exchange 2003
  • Upgrade from Exchange 2007
  • Upgrade from Exchange 2003 & 2007
  • New installation of Exchange 2010

Just to see how detailed the checklist is, let’s explore the Upgrade from Exchange 2003 & 2007 option. On the first page, we are asked three questions:

  1. Are you running a disjointed namespace?
  2. Are you planning to deploy an Exchange 2010 Edge Transport server role?
  3. Are you planning to deploy an Exchange 2010 Unified Messaging server role?

Now the Assistant doesn’t expect you to be an expert at all things Exchange (though a little knowledge goes a long way) so each question can be expanded to show a full explanation of why the topic is important during the Exchange deployment. So for these questions, I’m answering No, Yes, No.

Surprisingly, the Deployment Assistant is able to create a checklist based on just the answers to these three questions. The checklist include the following steps along with detained explanations on what to do along the way:

  • Confirm prequisties steps are done (stuff like making sure all the installation minimum requirments are satisfied on the existing Exchange Servers and in Active Directory).
  • Install the Client Access server role (insert the disk, run through the installation wizard).
  • Add digital certificates on the Client Access server (to secure external access to Exchange, including an exportable private key in X.509 format).
  • Enable Outlook Anywhare (allowing remote users to access their mail without them needing to VPN into the network).
  • Configure OAB and Web Services virtual directories (allowing Outlook Anywhere clients to discover and automatically connect to Exchange 2010).
  • Configure settings on virtual directories (used for Autodiscover, ActiveSync, OWA, Exchange Control Panel, PowerShell, Exchange Web Services, and public folders).
  • Install the Hub Transport server role (responsible for mail flow).
  • Configure a legacy host name (to allow coexistance with Exchange 2003 and 2007).
  • Install the Mailbox server role (host for mailbox and public folder databases).
  • Change the OAB generation server (for creating and updating the OAB).
  • Install the Edge Transport server role (anti-spam and antivirus filtering, and applies messaging and security policies).
  • Subscribe the Edge Transport server (enables internet mail flow).
  • Move mailboxes from Exchange 2003 or Exchange 2007 to Exchange 2010 (self explanatory, but be aware that users cannot send or receive email while the mailbox is being moved so this should only be performed when would otherwise be sleeping).
  • Post-installation tasks (just a list of items to check on each server such as making sure that the servers have been activated with a valid product key).

And that is the complete upgrade path. Seems pretty easy. What I like about this checklists is that it can be used directly because it only lists the step needed for your specific environment. When working through many of the Deployment whitepapers, you need to determine whether many of the steps are relevant to your situation. Using the Exchange Server Deployment Assisstant reduces or removes this problem.

Share

Exchange 2010: OWA

Wednesday, March 31st, 2010

Outlook Web Access has gone through many improvements over the years, starting as a very basic web interface and has been building up to a thin client replica of the Microsoft Outlook client. With Exchange Server 2010, OWA appears to be a fully mature edition.

OWA now lets you group messages by conversation, grouping all messages that originated from a single message and all the resulting replies. This is not a big deal if you are just going back and forth between one other person in the organization, but if you are receiving feedback from 10 or 100 people in your organization, you’ll can easily keep those messages together.

To help protect people from sending damaging or embarrassing messages, Exchange Administrators can configure Mail Tips. This feature is implemented similar to how Outlook Rules work and can provide users with a warning when an email is being sent to an external recipient, to a large distribution group, or to someone who is currently Out of Office.

User can now perform more powerful searches from Outlook Web Access, similar to what is available in the full Outlook client. You can search by recipient, whether attachments were included, and many other common search criteria. You can also set your favorite searches so that you can reuse them with a single click of the mouse.

Presence information is now integrated into Outlook Web Access allowing you to immediately know whether a person is available, busy, or not available using a green, yellow, red color coding. Depending on how important your message is and the recipient’s status, you can decide to Instant Message the person, another feature that is integrated directly into OWA when the Microsoft Office Communications Server is also implemented.

Finally, one of my favorite features now is the SMS Sync feature. By using Exchange ActiveSync, you can configure the server to automatically send out SMS text messages to your cell phone. This feature is also configured using rules, so whenever you get an email from a particular client, you can have a notification sent directly to your phone.

Share