RSS | MY PROFILE | PRIVACY 

WServerNews (formerly W2Knews) - PowerShell Tips

Vol. 17, #30 - July 23, 2012 - Issue #889

PowerShell Tips

  1. Editor's Corner
    • From the Mailbag
    • PowerShell Tips
    • Tip of the Week
    • Recommended for Learning
    • Quote of the Week
  2. Admin Toolbox
    • Admin Tools We Think You Shouldn't Be Without
  3. Events Calendar
    • TechMentor Conference Redmond, Aug 20-24, 2012
    • Americas
    • Europe
    • Asia/Pacific
  4. Webcast Calendar
  5. Tech Briefing
    • The evolution of Small Business Server
    • No more Windows Home Server
    • Mitigating Risk: Why Sticking with Windows XP Is a Bad Idea
    • RSA keys under 1024 bits are blocked
    • UE-V Deployment and Setup (video)
    • Diagnostics and Recovery Toolset (DaRT) (videos)
    • Convert VMware virtual machines to Hyper-V
  6. Windows Server News
    • Business factors of building a private cloud infrastructure
    • VDI benchmark testing: How to boost the virtual desktop user experience
    • Microsoft Windows Server 2012 removes licensing option for Hyper-V
    • Summer reading assignment: Our best VMware performance tips
  7. WServerNews FAVE Links
    • This Week's Links We Like. Fun Stuff.
  8. WServerNews - Product of the Week
    • Free IP Address Tracker from SolarWinds Makes Tracking Easy

 

Free IP Address Tracker from SolarWinds Makes Tracking Easy

Download SolarWinds FREE desktop tool and get a unified view of your IP address space. IP Address Tracker shows you what IP addresses are in use and which arenít. It also eliminates manual errors associated with Excel spreadsheets and ensures IP addresses are listed in the right place.

GET FREE TOOL>>>>

 

Editor's Corner

SAVE THIS NEWSLETTER so you can refer back to it later for tips, tools and other resources you might need to do your job or troubleshoot some problem you're dealing with. And please feel free to FORWARD IT TO A COLLEAGUE who you think might find it useful. Thanks!

From the Mailbag

This week's newsletter is about Windows PowerShell. Why? Because it's the future of Windows Server management. You can quickly automate repetitive tasks with it. And you can do really cool stuff with it. Plus it's easy to learn (up to a point, anyways) especially with the new simplified syntax of PowerShell v3:
http://www.wservernews.com/go/1342690809381

And if you're STILL not sure you need to learn PowerShell, check out what Don Jones has to say:
http://www.wservernews.com/go/1342690815756

And when Don says that Microsoft "wants to push people away from the GUI" you should also note that most of the new administration tools included in Windows Server 2012 are really nothing more than a GUI wrapper for running PowerShell commands under the hood!

But before we go further on this subject, let's dig into our Mailbag.

Feeling Green (Issue #888)

A reader named Bruce had some practical suggestions to make concerning saving power in server rooms:

I would like to suggest that motion sensors and LED lights in server rooms for the lighting would save double - the light bill would be reduced and the air conditioning bill would be reduced by a little and considering the number of server rooms around, that can add up to a lot of power saving country and worldwide. A humorous aspect of this is that an overworked admin would get a bit more sleep on occasion which might mean short term loss of production but greater efficiency the rest of the time. When thinking of saving power, think outside your own area and pass on your thoughts to management. In our civic exhibition facility we have four public washrooms and our potential power saving by turning off the fluorescent lights when nobody is in the building is $400 a year. Our electrical bill dropped $1000 a month in the first 4 months of this year when we turned off the outside parking lights and non-security exterior building lights. With a management change at the beginning of the year, we were mandated to save as much money as possible when the billing switched to the management instead of the city. As employees we had always been conscious of expenses and practiced frugality but re-focusing and asking ourselves: 'Why is this needed?' let us find further savings than just doing it casually. An annual or quarterly repeat of this question and or a suggestion box at each elevator could boost savings also.

Keyboard Conundrums (Issue #886)

Carl, a consultant and Citrix Technology Professional, had some good advice concerning keyboards that make nice, reassuring clicks when you type on them:

I love my clickity-clackity Unicomp keyboards. I have one PS/2 and one USB. They are not cheap but they are worth every penny. I have a UB4044A and a UB40446 and they are great for all the writing I do. BUT - when I am on a conference call or GoToMeeting, I have to remember to mute my connection when I need to type or no one can hear anything but my keyboard!

Tom, a reader from Ohio USA, says that last bit even stronger:

If someone near to my office had a clickity-clack keyboard, they would find it missing the next day. If you’re within hearing distance to anyone, don’t use an annoying keyboard. It’s like whistling in the office, but worse.

Backup Blues Redux (Issue #875)

Tony from the UK shared the following story about how he makes sure his SBS 2008 server is backed up and that he can recover data from it in a pinch if he needs to:

Here is what I typically use for SBS 2008

  1. Three partitions - one for O/S, one for data and one for WSUS data (but not the actual database).
    • This last one is because it is the biggest data hog, and after a few months probably stores as much as 100G which is the typical monthly data limit. This means that backing up the WSUS data is not so critical, and you know that data can just be downloaded.
    • In my case it is not RAID because I run it on an SSD as a VM
  2. I also use a cheap pluggable hard driver carrier for a local disk for backups
    • This is "backup 1" and several disks rotate
  3. A NAS (Synology) with mirrored disks and backup over the network to this; I also backup things like firewall and router configs to the NAS and critical desktops to the NAS
  4. The NAS has an external disk and the NAS does backups of data (including some backups) to the external disk
  5. In addition, I also use Microsoft's "SyncToy" in "contribute" mode to replicate certain user data files into the "chain"

Thus, I have

The key is partitioning what you need to back up, making sure that you can restore that data to something other than the original hardware and software (this is where Microsoft backup from Vista onwards is great - the backup is a VHD format file which you can actually mount as a disk under Windows 7 and just copy files off - also, it can provide a means of fixing a broken system by manipulating the files in the VHD backup before restoring - handy for dealing with files that are otherwise locked). Secondly, having more than one copy and for this you need a flow, but at the start it should be in parallel - otherwise you have the potential that all you do is propagate faulty backups.

There are good reasons for this flow - if you delete a file, it can easily be recovered from the pipeline. If the delete has propagated all the way through the pipeline, then that is where the "SyncToy" copy comes in - this doesn't delete files.

Finally is the issue of testing. You cannot normally run the risk of doing a test restore of a backup to your one and only working system. That is where the backup to VHD works - you can mount the backup and examine the "disk" to see what is on it.

It may seem like "belt and braces" but I remind myself of two things - hard disks fail (and the real rate according to various studies is an order of magnitude worse than the manufacturers claim, and this accords with my own observations; I also once built a server with mirrored disks and a hot spare and all three disks failed in the first month) and the fact that there are two sorts of people - those who have lost data, and those who will.

Make sure you re-read that last bit from Tony's final sentence above! And you can download SyncToy from here:
http://www.wservernews.com/go/1342690901880

Now on to this issue's main topic.

PowerShell Tips

Back in February in Issue 866 we listed a number of helpful resources for learning PowerShell, and if you haven't yet begun your journey towards PowerShell proficiency, you might want to refer back to that issue and check out some of the resources listed there:
http://www.wservernews.com/go/1342690918396

But before we examine how PowerShell can be used to manage Windows servers, did you know that SERVERS CAN HAVE A SHORT ATTENTION SPAN?
http://www.wservernews.com/go/1342690923521

When was Windows installed?

When it comes to getting detailed information concerning a Windows server, good-old Windows Management Instrumentation (WMI) is still your friend.

For example, say you're wondering when Windows was installed on your system. To find out, you could try using the Get-WmiObject cmdlet to retrieve information from the win32_operatingsystem WMI class on the system like this:

PS C:\> Get-WmiObject win32_operatingsystem

SystemDirectory : C:\Windows\system32
Organization  :
BuildNumber   : 8400
RegisteredUser : Windows User
SerialNumber  : 00133-30010-00805-AA162
Version     : 6.2.8400

Unfortunately I don't see what I'm looking for here, so let's pipe the output to the Format-List cmdlet (using its alias "fl") to show everything in the class like this:

PS C:\> Get-WmiObject win32_operatingsystem | fl *

PSComputerName              : SEA-HOST-1
Status                  : OK
Name                   : Microsoft Windows Server 2012 Release Candidate
                      Datacenter|C:\Windows|\Device\Harddisk0\Partition2
FreePhysicalMemory            : 23289328
FreeSpaceInPagingFiles          : 3407872
...
...
...
InstallDate                : 20120620092210.000000-420
...
...
...

Ah, there it is, the property I'm looking for is InstallDate, so let's pipe the output into the Select-Object cmdlet (using its alias "select") like this:

PS C:\> Get-WmiObject win32_operatingsystem | select InstallDate

InstallDate
-----------
20120620092210.000000-420

Now I've got just what I wanted, but unfortunately the date/time shown here isn't human-friendly. Fortunately, I can use the ConvertToDateTime() method to make it readable as follows:

PS C:\> Get-WmiObject win32_operatingsystem | select @{Name="Install Date"; Expression={$_.ConvertToDateTime($_.InstallDate)}}

Install Date
------------
6/20/2012 9:22:10 AM

The above example makes use of a PowerShell feature called "calculated properties". For more info on this feature, see here:
http://www.wservernews.com/go/1342690932177

By the way, what if you want to retrieve this information from a remote computer? Just include the -ComputerName parameter with the Get-WmiObject cmdlet, and if your current logon credentials aren't sufficient you can include the -Credential parameter to specify credentials for the remote computer. For example:

PS C:\> Get-WmiObject -Computer SEA-HOST-1 -Credential SEA-HOST-1\Administrator win32_operatingsystem | select @{Name="Install Date"; Expression={$_.ConvertToDateTime($_.InstallDate)}}

But what if I don't know WMI?

If WMI terminology like classes, properties and methods stumps you, check out this series of articles I wrote several years ago for WindowsNetworking.com:
http://www.wservernews.com/go/1342690937427

Some of the articles are a bit dated now, but most of the information in them still applies to current versions of Windows.

REDUX: When was Windows installed?

Wait a minute, here's another way of using the Get-WmiObject cmdlet to determine when Windows was installed on your system:

PS C:\> [System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject win32_operatingsystem).InstallDate)

Wednesday, June 20, 2012 9:22:10 AM

Here we're using the ToDateTime() method of the .NET class called System.Management.ManagementDateTimeConverter to convert the value of the InstallDate property returned by using the Get-WmiObject cmdlet to query the win32_operatingsystem WMI class on the system.

The square brackets are needed for calling or using static members of a .NET class, and the double colon separates the class name from the static method or property being called or used. More details here:
http://www.wservernews.com/go/1342690943380

Is the server physical or virtual?

You can also use PowerShell to query the win32_computersystem WMI class to determine whether your server is a physical server or is running in a virtual machine on a Hyper-V host. Here are a couple of examples I just tried using different servers:

PS C:\> (get-wmiobject win32_computersystem).model
Virtual Machine

PS C:\> (get-wmiobject win32_computersystem).model
PowerEdge T300

Managing WSUS with PowerShell

Windows Software Update Services (WSUS) lets you manage the distribution of software updates for Windows servers, Windows clients and Microsoft applications. Boe Prox, a senior systems administrator with BAE Systems, wrote a terrific series of articles for Ed Wilson's Hey Scripting Guy column on TechNet on how to use PowerShell to perform basic WSUS admin tasks such as approving/declining updates and finding missing updates on WSUS clients:
http://www.wservernews.com/go/1342690949177

http://www.wservernews.com/go/1342690953817

http://www.wservernews.com/go/1342690956223

http://www.wservernews.com/go/1342690958489

http://www.wservernews.com/go/1342690960833

http://www.wservernews.com/go/1342690963442

With Windows Server 2012 however, this will be even easier because of the new WSUS cmdlets included in the new platform:
http://www.wservernews.com/go/1342690966864

I have to confess I'm actually pretty hyped about the extensive new PowerShell support in Windows Server 2012 as it will make automating remote management of Windows servers much easier. That's obviously something important for both datacenter management and for cloud computing environments.

Allowing users to run PowerShell commands against remote servers

By default, in PowerShell 2.0 on Windows Server 2008 R2 only members of the built-in Administrators group on a remote server can remotely run PowerShell commands against that server. You can get around this however by using the Set-PSSessionConfiguration cmdlet to grant permissions to other groups or users to do this, as Jeffrey Snover described awhile back in this blog post:
http://www.wservernews.com/go/1342690972223

In Windows Server 2012, it looks like you can also do this by adding users to the built-in domain local group called Remote Management Users:

 Image

Just be careful when you do this because there are obvious security issues involved when you grant non-admins the capability of performing administrative actions.

Unblocking downloaded files

So you've downloaded a dozen Excel workbooks from a SharePoint site and you want to work on them but they all have file block enabled on them. So you right-click on the first file and select Properties and click the Unblock button, then you repeat with the second file and the third and fourth...

Frustrating, right? Well, with Windows Server 2012 (and probably Windows 8 as well, though I haven't checked) you can now use the Unblock-File cmdlet to remove the file block from a downloaded file like this:

PS C:\> Unblock-File C:\downloads\project01.xlsx

But what if you want to remove the file block from ALL files in a particular directory? You can do this by using the Get-ChildItem cmdlet to get all the files in the directory and pipe the result into the Unblock-File cmdlet like this:

PS C:\> Get-ChildItem C:\downloads | Unblock-File

Neat, eh?

Favorite PowerShell Tricks

To conclude, here are ten useful nuggets from Ed Wilson a.k.a. The Scripting Guy:
http://www.wservernews.com/go/1342690980411

http://www.wservernews.com/go/1342690985364

http://www.wservernews.com/go/1342690987770

Tip of the Week

I've been using Bing for awhile as my default home page in Internet Explorer. But I'm sometimes annoyed by the photos Bing displays on its home page as they seem to make the page load more slowly. The result is that when I open IE and start typing JUSTIN BIEBER to find out what's happening with him (just kidding) I find that Bing ends up searching for TIN BIEBER instead, because by the time the page opens and displays properly I've already typed a couple of characters that are too late to have been entered into the search box.

Anyways, today I found the answer: instead of making http://www.bing.com my home page, I can make http://www.bing.com/?rb=0 the "no image" Bing my home page instead. Trying it out by clicking here:
http://www.wservernews.com/go/1342690991504

Got any search tips of your own to share with our readers? Email me at wsn@mtit.com

Recommended for Learning

CCNA ICND2 640-816 Official Cert Guide (3rd Edition) from Cisco Press helps you prepare for the CCNA exams. Several chapters have been completely revised including the ones on VLSM, route summarization, and IP access control lists:
http://www.wservernews.com/go/1342690999051

CCNP Security Secure 642-637 Official Cert Guide from Cisco Press helps you prepare for the Cisco SECURE certification exam, which focuses on security in Cisco IOS routers, switches and VPN devices:
http://www.wservernews.com/go/1342691003426

Quote of the Week

"It was one of the holidays from business that kept me young and happy--worth all the medicine in the world."

--from the Autobiography of Andrew Carnegie
http://www.wservernews.com/go/1342691023614

Another great quote by Andrew Carnegie from his autobiography, this time concerning the importance of taking vacations. How many of us in the IT industry feel like we're plugged into the network 24x365? We must take a break sometimes, a real break that involves going away and leaving your cellphone behind. When is your next vacation?

Until next week,

 

Admin Toolbox

Admin Tools We Think You Shouldn't Be Without

Download a free, fully functioning 30-day trial of Patch Manager from SolarWinds and get visibility into patch compliance with an extensive collection of simple, built-in reports.
http://www.wservernews.com/go/1342691988936

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting:
http://www.wservernews.com/go/1342691028848

Discover and import Outlook PST files into Exchange Server or Exchange Online using this free tool from Microsoft:
http://www.wservernews.com/go/1342691031645

SyncToy 2.1 is a free application that synchronizes files and folders between locations:
http://www.wservernews.com/go/1342691038614

 

Events Calendar

TechMentor Conference Redmond, Aug. 20-24, 2012

TechMentor, the top conference for IT professionals, is coming to the Microsoft campus! Register with code TMRTU for a $300 discount:
http://www.wservernews.com/go/1342691063301

Americas

Europe

Asia/Pacific

Add your event

Contact Michael Vella at michaelv@techgenix.com to get your conference or other event listed in our Events Calendar.

 

Webcast Calendar

This Week's Webcasts

Register for Webcasts

 Add your Webcast

Contact Michael Vella at michaelv@techgenix.com to get your webcast listed in our Webcasts Calendar.

 

Tech Briefing

The evolution of Small Business Server

Windows Small Business Server Essentials is now going to be called Windows Server 2012 Essentials; you can read about its capabilities here:
http://www.wservernews.com/go/1342691104785

No more Windows Home Server

In other news, it looks like Windows Home Server 2011 will be the final version of Microsoft's Home Server operating system:
http://www.wservernews.com/go/1342691109504

Mitigating Risk: Why Sticking with Windows XP Is a Bad Idea

Download a white paper from IDS examines the operational costs for large organizations of continuing to run Windows XP and compares this with the costs associated with running Windows 7:
http://www.wservernews.com/go/1342691113832

RSA keys under 1024 bits are blocked

Microsoft is hardening their criteria for using the RSA algorithm with key length less than 1024 bits on Windows platforms:
http://www.wservernews.com/go/1342691119613

UE-V Deployment and Setup (video)

Watch this TechNet video and see how Microsoft User Experience Virtualization (UE-V) can help you provide a constant, personalized Windows experience for your users regardless of how Windows or their applications are delivered:
http://www.wservernews.com/go/1342691121941

Diagnostics and Recovery Toolset (DaRT) (videos)

This series of video tutorials takes you through creating DaRT boot media to performing tasks like resetting passwords, recovering files and repairing systems:
http://www.wservernews.com/go/1342691131738

Convert VMware virtual machines to Hyper-V

Download the Release Candidate of the Microsoft Virtual Machine Converter (MVMC) which converts and deploys virtual machines from VMware hosts to Hyper-V hosts running Windows Server 2012 Release Candidate:
http://www.wservernews.com/go/1342691133629

 

Windows Server News

Business factors of building a private cloud infrastructure

Private cloud is an intriguing option for companies that need to maintain control of certain types of IT workloads while taking advantage of the scalability and flexibility of a cloud environment. But is it worth the trouble compared to other cloud options? There are three factors you need to consider before making the move to private cloud – find out what they are in this popular tip.
http://www.wservernews.com/go/1342691141582

VDI benchmark testing: How to boost the virtual desktop user experience

End users don't care about the underlying technology, they just want it to work. That's especially fitting when it comes to the virtual desktop user experience. So, what can you do to ensure a good virtual desktop user experience? Find out in this expert tip.
http://www.wservernews.com/go/1342691145925

Microsoft Windows Server 2012 removes licensing option for Hyper-V

When Microsoft’s Windows Server 2012 ships, Hyper-V shops will have fewer licensing options. Some IT pros say that’s a good thing. Learn more in this featured article.
http://www.wservernews.com/go/1342691149925

Summer reading assignment: Our best VMware performance tips

With the heat of summer on the way, it’s tempting to pack it in, but this summer take the initiative and read these tips to help your organization improve its VMware performance.
http://www.wservernews.com/go/1342691155066

 

WServerNews FAVE Links

This Week's Links We Like. Tips, Hints And Fun Stuff

In an ancient Chinese temple, two female martial artists face off in a battle for the power outlet:
http://www.wservernews.com/go/1342691160019

Next time you redecorate your living room, try this new invention: The room is continually redecorated using two projectors and state-of-the-art software:
http://www.wservernews.com/go/1342691166785

Rally car champion Ken Block demonstrates his fast and precise driving skills, skidding through San Francisco in a 252-hp Ford Focus ST:
http://www.wservernews.com/go/1342691169425

An "almost perfect" emergency landing in a sailplane, until an unnoticed mailbox catches the right wing:
http://www.wservernews.com/go/1342691175113

A symphonic flash mob at the town square of Sabadell, Spain with an uplifting performance of the "Ode to Joy" by Ludwig van Beethoven.
http://www.wservernews.com/go/1342691178285

The Earth as You've Never Seen it Before: Atmosphere, Airglow and Aurora
http://www.wservernews.com/go/1342691181878

 

WServerNews - Product of the Week

Free IP Address Tracker from SolarWinds Makes Tracking Easy

Download SolarWinds FREE desktop tool and get a unified view of your IP address space. IP Address Tracker shows you what IP addresses are in use and which arenít. It also eliminates manual errors associated with Excel spreadsheets and ensures IP addresses are listed in the right place.

GET FREE TOOL>>>>

 

WServerNews - Editors

Mitch Tulloch is Senior Editor of WServerNews and is a widely recognized expert on Windows administration, deployment and virtualization. Mitch was lead author of the bestselling Windows 7 Resource Kit from Microsoft Press and has published hundreds of articles for IT pros. Mitch is also a seven-time recipient of Microsoft's Most Valuable Professional (MVP) award for his outstanding contributions in support of the global IT pro community. Mitch owns and runs an information technology content development business based in Winnipeg, Canada. For more information see www.mtit.com

Ingrid Tulloch is Associate Editor of WServerNews and was co-author of the Microsoft Encyclopedia of Networking from Microsoft Press. Ingrid is also Head of Research for our content development business and has co-developed university-level courses in Information Security Management for a Masters of Business Administration program.