Powershell

Powershell is truly a wondrous giant box of toys. 

Just when you think you’ve figured it out, somebody puts something in front of you. Like the other day when Shay Levy unlocked the secret to Clearing the Windows Event logs.  I had to ask how he did it.

The process is both complex and simple but it DOES show you how you can play with Powershell and unlock the hidden treasures within.

In the case of the GET-WINEVENT Cmdlet (where there was no corresponding CLEAR-WINEVENT) Shay used a GET-MEMBER on the GET-WINEVENT Commandlet.

I didn’t understand at first why until I tried it myself.

Beside EVERY property, Method, Note Property is a reference to the Windows .NET Framework library being used.

 

At this point every IT PRO in the net reading this Blog post just fell asleep!

 

For those of you still awake, think of the Library as the world’s BIGGEST Database of information and systems within Windows.  They all have “funky little names”.

Let’s do one on GET-CHILDITEM to show you. On the right hand side of CreationTime you’ll see a reference to System.DateTime

image

You can go to www.msdn.com to pull up specs on what this Library has and how it can be used.   Just type in the name within the top search box.  You’ll probably see a list pull down below you.  Click on the one that matches what you’re searching for.

image

The next Windows will pull up a HUGE pile of results from the MSDN online Documentation.  You’ll want to filter that out by .NET Framework 3.5 or 3.0 (Depending on whether you’re working with Powershell 1.0 or 2.0, not being a Developer I would suspect there are SOME differences between 3.0 and 3.5, so for best results, choose the version matching your Powershell)

image

 

In the resulting list  odds are the one at the top is your “Holy Grail” of information about that Library, or at least a tablet into it’s knowledge

 

image

The article should give you some indication about what you can do with it.  To me an ITPro? It’s mostly gibberish!  But’s COMPUTER Gibberish, so it’s sort of makes sense!

But here’s a neat trick Shay showed me to find out what you might be able to play with.   Take the Libary name and type it like this in Powershell

 

[System.Datetime]::

 

Yes A square bracket at the Beginning, one at the end and TWO Colons.

Don’t hit Enter, Hit tab, you may see some additional functions appear, sometimes properties.  I chose “DateTime” because it Does give us a few easy ones to play with

It produces with the Tab

[System.Datetime]::Now

[System.Datetime]::Today

Amongst others.   Hitting enter will either yield results or yield an error.  If it’s a feature in Windows that presently does not have a Powershell Commandlet, this is your doorway into unlocking those features.

 

It’s pretty heavy for ItPros I admit.  This is not our world.  But understanding a LITTLE of that world, unlocks a LOT within Windows and helps within the greater Master of Powershell

 

The Power is in YOU. 

Sean
The Energized Tech

Sponsored by ITPro Toronto

Register at http://itprotolotusfoundation.eventbrite.com/ while space is available!

Please note you have to PRE-register for this event in order to gain access as this is held inside IBM’s office.

Lotus Foundation Server UG presentation
Mar 16, 2010

Add to my calendar

WHERE

IBM Canada
Amphitheatre
8200 Warden Avenue
Markham, Ontario L6G 1C7
Canada

Synopsis

Small business is still big business. Every company needs the ability to do e-mail, create, share and centrally manage documents and files and ensure that all their information is backed up and protected. But no one wants the hassle or expense of dealing with complex IT systems. Lotus Foundations is a family of software appliances that provide the essential software businesses need to focus on running the business, not managing computer systems.

Register at http://itprotolotusfoundation.eventbrite.com/

Agenda and Presenters:

6:45 PM - 7:15 PM - Food and Drinks

7:15 PM - 7:20 PM - Introductions (why we are here, why you are here)

7:20 PM - 8:40 PM - Product Demonstration

- Architectural Overview (and why it's different)

- Getting running in no-time flat

- Integrated Base Capabilities and Functionality

- Backup, Network Router, Firewall, FTP, Web Server, File Server, DHCP, etc...

- Integrated Enhanced

- Antivirus, Antispam

- Add-ons and the role of Autonomics and Integration

- Start

- Reach

- 3rd Party

8:40 PM - 9:00 PM - Q & A

Host:

Hiep Vuong

Hiep Vuong leads up the HW Platform Strategy and Development and Technical Business Development for the IBM Lotus Foundations Team. Hiep has extensive background in appliances for the Small Business space having lead up development and operations at both SonicWALL and Net Integration Technologies (acquired by IBM in 2008).

Presenters:

Julie Reed

Julie Reed leads the IBM Lotus Foundations engineering team. She has over 25 years experience in the software industry spanning various application server environments and collaboration platforms. Julie came to IBM with the Net Integration Technologies acquisition in 2008.

Larry Menard

Larry Menard is a Quality Assurance Team Lead for the IBM Lotus Foundations products. He began his career with IBM in 1979 and has held a wide variety of positions within the company. Prior to joining the Lotus Foundations team, Larry's most recent positions included Quality Assurance and Information Development for the IBM DB2 relational database product.

Register at http://itprotolotusfoundation.eventbrite.com/ while space is available

I just had a complete Jaw drop.  Another Teaser

“TRON”

 

“TRON”, one of the very movies that gave me that gentle nudge into Geekdom.

 

“TRON” Legacy is making it’s way towards theatres.  Another Trailer released. 

I

CAN’T

WAIT!

 

Are you a Developer?  Interested in Code?  Do you Live Sleep and BREATHE in nothing but Binary?

Do you friends find you huddled in a corner of the house drooling over the latest .NET libraries?

Do you REALLY have to think hard about whether to spent your money on a new compiler or your wife?

Did you DROOL all over the table when somebody said “AZURE”?

If this sounds like you, you REALLY need to sign up for the Toronto Code Camp!

It’s a Free All day event held on a SATURDAY!  A Perfect excuse to leave your wife and kids behind

 

“…I’m sorry honey… *sniff* … but I HAVE to go for Training … *sniff*…”

 

Details are STILL up in the air for what sessions will be there but it’s GUARANTEED to make Developers ‘W00000T!’ and ITPros run in terror.  (Unless they Script in Powershell, in which case they might only cringe)

 

CODE has never been this fun!

 

Curious?

Watch for Details on www.torontocodecamp.net

Be there or ADMIT you know how to calculate SUBNET Masks!

Saturday May 1st 2010 – BRING on the DATA BONDAGE!

Powershell

Within Windows 7 / Vista and Server 2008 / R2 there is a set of Event logs.

Not the “Classic ones” we are used to but a whole new Class of of logs that can be expanded on simply called the Windows Event Logs.

You can access their contents in Powershell using the GET-WINEVENT CommandLet in the following fashion.

GET-WINEVENT –Logname Setup

or

GET-WINEVENT –Logname ‘Microsoft-Windows-WindowsUpdateClient/Operational’

 

To get a list of these logs that are available you key in

GET-WINEVENT –ListLog *

for a complete list or you can type in Wildcards as well such as

GET-WINEVENT –Listlog S*

For all those Starting with the letter “S”

But oddly somebody forgot an important CommandLet … the one to CLEAR the logs!

Now they can also be managed from the Command prompt using WEVTUTIL.EXE which works very nicely.  But we people in Powershell land like to keep everything on the same page.

 

So thanks to Shay Levy for pointing out the proper Acclerator and technique, we now have a NEW commandLet we can add to Powershell.   There are a number of ways to bring it in, the choice is yours.

I could do it as a Module but I got lazy today and just opened up my $PROFILE for Powershell and added it in.

Here’s the code so YOU TOO can “Share and Enjoy” as the Nutrimatic would say.

-----------------------------------------------------------------------

Function Global:Clear-Winevent ( $Logname ) {
<#

.SYNOPSIS
Given a specific Logname from the GET-WINEVENT Commandlet
it will clear the Contents of that log

.DESCRIPTION
Cmdlet used to clear the Windows Event logs from Windows 7
Windows Vista, Server 2008 and Server 2008 R2

.EXAMPLE
CLEAR-WINEVENT -Logname Setup

.EXAMPLE
Get-WinEvent -listlog * | foreach { clear-winevent -logname $_.Logname }

Clear all Windows Event Logs

.NOTES
This is a Cmdlet that is not presently in Powershell 2.0
although there IS a GET-WINEVENT Command to list the
Contents of the logs.  You can utilize this instead of
WEVTUTIL.EXE to clear out Logs.  Special thanks to Shay Levy
(@shaylevy on Twitter) for pointing out the needed code

#>

[System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("$Logname")

}

------------------------------------------------------------

Thanks a bunch Shay! We owe you BIG! :)

Sean
the Energized Tech

Certification as an MCP, MCT sets a bar for others to not only Aspire to, but sets a standard employers can work with.

There are many certifications out there that beautifully serve this purpose.

But there is one lacking.  One for “Scripters” or I like to think as “Environment Automation”

There is some rumbling that stirs up whenever it is mentioned in the Community.   Powershell scripters crave for it.   There is nothing right now that sets the bar.

But I’m thinking a lot more specific on “Scripting” or “automation” as a skill set that ENHANCES what an MCP is.

Some people in Microsoft think it’s ok that Powershell or vbScript is touched on lightly in the Certs as part of the exam structure.   But that isn’t the case.  Having had to start implementing these techniques in my most recent position I recognize something truly important.

A person that understands automation as a specialization is as EQUALLY as Important as having somebody who knows how to Architect the system.  But not knowing whether an Administrator is qualified on some level makes it difficult to gauge those abilities.   And in today's Economy, Employers are going to want EFFICIENCY.  Not so much to get more done, but to get that “More” done quickly, effectively and most importantly CONSISTENTLY.

Proper automation and the ability to leverage those technologies (and more importantly WHICH ones) changes a Network Administrator or Systems Administrator from a simple manager that can get things running, to a key technologist that can spend more time looking into long term solutions on the Infrastructure.   Knowing how to deploy these technologies in a more Automated and Seamless fashion on a day to day basis allows for a much greater level of consistency than somebody that lightly touches on Powershell, vbScript or GPO.

But presently there is no way (other than field use) to determine what Level a potential Administrator is.

And so I propose this.   I propose Microsoft Development AND Microsoft Learning team up together to promote the creation of a New certification.   It may not set aside the individual as an actual MCP but it SHOULD complement existing certifications (IE: MCITP or MCTS in Server) to identify the Individual as a competent “Scripter”.  Competent in a good range of Technologies, GPO, Powershell, vbScript and classic Commands.

With this type of enhancement on a certificate (As a separate Single Exam) Microsoft could identify individuals that not only know the server for installation, but are ESPECIALLY qualified to maintain those systems.

Such an exam would involve more simulation or practical application questions.   Such a certification would help employers identify people best suited to manage their networks in the most Efficient and Consistent fashion.

And so to you, the Community.   The IT Professionals, the Scripters, the Powershell Experts, the GPO Gurus and all Future Network administrators, I send you a task.

I have been told, if we can get the attention of Microsoft corporation, and more importantly, Steven Ballmer’s attention.  Something could happen.  We have to ring the bells LOUD

So we as a community need to contact steveb@microsoft.com directly.  Do NOT spam him.  Take two minutes (or three) compose and EMAIL and put in the TITLE of that email ATTENTION: IT Community Demand for MCP Certification in Scripting and Automation Technologies. 

CLICK HERE to COMPOSE EMAIL

Our target is no less than 5,000 emails.  I want to see it happen.  We can do this.  vbScripters, Powershell, GPO, Command specialists.

And it all starts with us

Sean
The Energized Tech

One of the big reasons people would back away from NTBACKUP was Server 2000.   It’s a great simple utility but it didn’t have ONE REALLY IMPORTANT feature.

Open File Option.

The Open File Option (What Full Veritas BackupExec had an a $1000 Add on) was the ability to backup files that were in use.   If you had important Word documents or a particular Quickbooks database open, they wouldn’t backup.

Then along came Server 2003.  Server 2003 introduced “Shadow Copy” which was actually a technology which contained a built in “Open File Option” that NTBackup just used.

Some people didn’t realize this! 

Yes, if you’re a small Business Owner looking into options for Backup and you don’t have the budget for Veritas Backup Exec, NTBACKUP is a viable option now.  Even if you’re a large Corporation, the fact that you can leverage a solution to backup those open files WITHOUT incurring additional cost is a great boon.

Now I am NOT knocking Veritas Backup Exec.  It is NOT an overpriced boondoggle.  It IS the BIG BROTHER to NTBackup.   It logs in GREAT detail how to the backup ran.  If even ONE file does not backup, Veritas considers the backup a fail so you’re on your toes.   Veritas will make your Backup far more compliant for SOX with the built in reports.

But keep in mind that if you have a Server 2003 computer (or even Windows XP Pro!) that built in NTBACKUP can backup your open files.   I’ve even seen it backup Exchange 2003 Databases with Open File

Now THAT’s Power! Free Power to “Boot”

Sean
The Energized Tech

As anybody knows me, I consider myself a “Scripter”, a creature not quite ITPro nor Dev and as such, a halfling from both words.

In short, I a “computer Hobbit”.

Scripters work in a world of Automation, in an attempt to make their jobs more efficient by PROGRAMMING repeated tasks rather than “click click clicking away” into Tedium Hell.

When you step into the world of Scripting and Automation you will probably find one solution you’re comfortable with, whether it be Powershell, vbScript, Group Policy or even the venerable and Classic Command prompt.

And you may (Like I did) have a tendency of Guardedly sticking to ONLY ONE solution and doggedly refusing to look at other options no matter what happens.

But the thing to keep in mind, why did you get into Automation?  Was it to make your job more difficult? Of course not!

So, when DO you look at other solutions?

Honestly it’s a little combination of “What are you comfortable with”,“Just how much time *DO* you want to spend at it” and “Are you spending the extra time to LEARN for fun or just out of dogged frustration”

I am reasonably certain that if you sat down, dug through the internet, you might find a solution for just about everything you can in Powershell (not all but just about) within a Command Prompt.   You could also go completely bonkers trying to ensure everything works via vbScript.   Or you could go Powershell nuts and try to become a .NET developer overnight and do everything in oneliners.

 

But in this mad process, you often overlook some excellent and very obvious solutions.  And there are situations where you can leverage multiple solutions against each other.

 

So here’s what I do.  I have one “Axe”, one solution I am comfortable with. Powershell.  I LOVE working with Powershell.  If it feels enjoyable to find a solution in Powershell because it’s fun or challenging, I’ll do it without question.

 

However again, there are tons of prebuilt Command prompt applications, Group Policies and vbScripts I can leverage.   For me, sometimes I’ll try to see if there is a WMI solution already existing in vbScript and try to port that to Powershell.   There are situations that NETSH makes far more sense than reading the registry to get an IP address along with many other built in goodies.   Using GPO makes more sense many times to deploy or remove rather than running from logon script.

My overall opinion is this.   Learn. 

Learn what makes YOU more productive.  Don’t tie yourself into a box saying “I can’t” because your “main Axe” doesn’t easily do it.  Don’t be afraid to see if there are more than two solutions to a problem (There often are).  Sometimes in learning a different solution as well, you may find a way to produce the answer in what you’re comfortable with.

Remember.  Computing should be fun, try to keep it that way whenever possible.

And the job, should always feel less like a “Job”

Sean
The Energized Tech

Powershell

I opened up Pandora's box and found more goodies! 

Did you know you can easily Enable and Disable Monitoring on your Windows drives with Powershell?  the same feature which offers “Shadow Copy restores” ?

By default it’s normally enabled on Drive C:, but let’s say this is a Server Environment.   You deploy them on a habitual basis, and like any good IT Pro, you keep the DATA from the SYSTEM.

But out of the Box, anything other than C: does not have system Restore enabled.  So normally that means, GUI, Right click, find option… AIGHAHGAHHHGA!!

 

But not with Powershell

In Powershell it’s just run as Administrator and

ENABLE-COMPUTERRESTORE DriveLetter

and

DISABLE-COMPUTERRESTORE DriveLetter

 

EASY!

So if you’re running a Domain Controller by default you might want to shut off the Volume tracking feature because you DON’T want “previous versions” available to alter your SYSVOL structure.  That’s just a mess waiting to happen.

So

DISABLE-COMPUTERRESTORE C:

And if all of your data is sitting on the new Drive E: and needs to be monitored so you CAN do “Previous versions”

ENABLE-COMPUTERRESTORE E:

There!

Your work is done! Now relax and break out the bubbly!

Sean
The Energized Tech

Part 1 – Hello Free backup, I never knew you so well

In a previous life I spent my days working with clients and using the native backup solution from Windows “NTBACKUP”

Now a lot of people look down upon NTBACKUP as the poor man’s backup.  Stripped down, hurt.

Let’s take a second look at NTBACKUP.  In Server 2003 with NTBACKUP you had the following features

Licensing cost – NIL (Free to use with the O/S)
Open File option – Built in (Yes, thanks to Shadow Copy you can backup many if not all open files)
Exchange agent – Built in
Media supported – Tapes and Physical Media
Ability to Email logs – programmable

You have to remember that “NTBACKUP” is really just a stripped down version of BackupExec (owned by Symantec now) and really ISN’T that bad of a backup.

You can run it from a command line, the configuration files are pure text (and easy to edit) and if you leverage just a few of the features built into Windows you, as an Administrator can have a backup system capable of emailing, printing and archiving logs.

“But I have an SQL Server!” (I hear a voice in the background scream)

And SQL has it’s OWN built in backup which can be scheduled and will co exist with NTbackup.

So feeling a little less nervous? Good

Follow along with me as I try to lightly touch on leveraging the built in Backup solutions provided by Microsoft to extend your abilities and pad your wallet with savings.

Sean
The Energized Tech