Blog > James Kehr

The official blog of managed hosting provider OrcsWeb.

Fun with PowerShell: Plink, Cisco IOS and PowerShell

Plink, Cisco and PowerShell walk into a bar...wait...I just did that gag.

I've been banging my head against this one for many days. PowerShell automation of Cisco switches through SSH. Easy, right? Not so much. A lot of command line based SSH clients are very old and don't have a scripting language like PowerShell in mind. More modern ones, or SSH cmdlets made for PowerShell, are expensive for commercial use and I prefer to avoid them when possible. With no native SSH in PowerShell or .NET I needed a good, working solution.

I tried a couple of .NET DLLs, but none of them worked consistently so I tried Plink, the command-line version of the tried and true PuTTy SSH client. While it works well for most SSH connections there is a well documented issue with Cisco IOS. Well documented online at least. To sum up the issue, when you use -batch to feed Plink.exe a batch file against Cisco IOS it doesn't work. You usually get an "invalid autocommand" error or something like "only only command per line" if you try to be sneaky and fit it all on one line.

It turns out there is a workaround for this by using StdIn (<) to input the text line by line.  Just one problem. PowerShell doesn't support StdIn redirection.

Read more...

A geek and a hard drive manufacturer's marketing guy walked into a bar...

After a few drinks of root beer the geek turned to the marketing guy and said, "What's the deal with using decimal bytes when determining the capacity of a hard drive? That was so last millennium."

The marketing guy turned to the geek and said, "Huh?"

"You know," the geek replied. "When you sell a hard drive you market the capacity as one terabyte, when the formatted capacity is actually nine hundred and nine gibibytes."

"What's a gibibyte?" the marketing guy asked.

The geek stared at the marketing guy for a long moment, his right foot tapping furiously on the bar stool as the effects of his root beer began affecting his delicate blood sugar balance. "Don't play coy with me you marketing spinster."

While he tried his best the marketing guy couldn't hold in his smile, so he turned and took a sip of his preferred brand of sweetened sarsaparilla and sassafras based carbonated beverage. After controlling his composure he turned to the geek and said, "Listen, I'm a marketing guy. If I were any good at math I wouldn't be in marketing."

"Then let me explain," the geek said.

Read more...

Fun with PowerShell: Domain authentication

The blog drought is over! For me at least.

I've been coding a lot lately but nothing that's been blog worthy until today. One of my latest creations requires credentials be entered in order to perform work. The Get-Credential cmdlet is fabulous for this, but how does the script know for sure whether the credentials are valid or not. It would be very bad if a long, 30+ minute process was broken because of a fat finger. A solution was needed, and here it is.

Read more...

Fun with PowerShell: The less than simple way to scan an IP range.

My last blog post covered a simple, four line, way to scan an IP range.  For a small range of IP addresses this solution works well.  For a large IP range...not so much.

One clarification before moving on.  This and the previous post require PowerShell 2.0 (#requires -version 2.0).  Why? The test-connection cmdlet is new to PowerShell 2.0.  While you could write a function using ping.exe or the .NET method of pinging it's much easier to just use test-connection.

http://go.microsoft.com/fwlink/?LinkID=135266

Back to business.

Read more...

Fun with PowerShell: Simple IP range scanner

Quick! How do you scan an IP range with PowerShell 2.0?  Quite easily.  This is a four line version, but it can be done in one if you manually enter the data on the last line instead of using variables.

[string]$firstThree = "192.168.1"

[int]$startRange = 1

[int]$endRange = 10

$startRange..$endRange | %{if (!(test-connection "$firstThree`.$_" -count 2 -quiet)) {write-host -f Red "$firstThree`.$_ is not responding"} else {write-host -f Green "$firstThree`.$_ is responding"}}

Now, wasn’t that easy? We’re in the business of simplifying complex matters, whether it means migrating your site and architecting the perfect scenario or identifying site configuration issues and helping you resolve them. To put a name to it, we’ve developed Complete Care Managed Services (CCMS). We have something for everyone, so check out our Windows cloud server hosting or our Windows dedicated server hosting options.

James

Fun with PowerShell: How to get SQL Server information

While I like the SQL Server PowerShell provider I have two issues with it.  First, it’s kind of limited, and second, it only installs with 2008 versions of SQL Server.  For these reasons I prefer to use the good old fashion SQL Server SMO namespace to do my dirty work.  That and we have a lot of SQL Server 2005 in our environment.

http://msdn.microsoft.com/en-us/library/ms162169.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx

Digging around in the SQL Server SMO, Server namespace, I noticed there was this lovely “Information” property list and thought, “I bet I could do something pretty cool with that.”  Now when I say cool, I mean cool in the I’m-a-geek definition of the word, not in the I-was-cool-and-popular-in-high-school version of the word.  And so I wrote a nifty little program, which can easily be turned into a function, that pulls all your basic SQL Server information from a system.

Read more...

iSSD and other small things

I picked this up from Engadget today and thought it was worthy enough to break my PowerShell blogging obsession long enough to blog about my real technology passion: hardware.

http://sandisk.com/about-sandisk/press-room/press-releases/2010/2010-08-18-sandisk-introduces-world’s-smallest-64gb-solid-state-drive—first-in-new-embedded-ssd-category

The iSSD is a new boot drive from SanDisk.  The iSSD is a postage stamp sized—for those old enough to remember postage stamps—solid state drive (SSD) that is soldered to the motherboard instead of inserted into a MiniPCI slot or SATA drive bay.  This is not a new idea, simply a better implementation of an old concept.

Sizes range from 4GB to 64GB and boast speeds up to 160 MB/sec seq. read and 100 MB/sec seq. write.  Not the fastest thing in the world, but plenty fast for a boot drive.

These little guys should do wonders for the tablet and ultra-slim notebook markets.  Devices like the iPad help get their small size from soldering the NAND flash directly to the motherboard.  The iSSD takes it a step further by providing a simple, all-in-one package that should make adding tiny boot storage to the motherboard cheap and easy for everyone.  Yay competition!

#James Kehr
Get-Member $OW | ?{$_.title -eq "System Administrator"`
-and $_.certification -contains 'MCITP:SA 2008, MCSE 2000, MCDST, Network+, A+'}

New-Variable -name company -value 'ORCS Web, Inc.' -description www.orcsweb.com | 1.888.313.9421’

Fun with PowerShell: Hyper-V Virtual Machine details

Before I begin I will make a full confession.  This code isn’t actually mine.  Not really.  I chopped most of it out of the PowerShell Management Library for Hyper-V.

http://pshyperv.codeplex.com/

Why would I do such a thing?  I generally dislike calling external files in my PowerShell scripts.  Not always, but most of the time.  The more external files you have the harder it is to make a script highly portable, and, under most circumstances, scripts should be highly portable with as few external dependencies as possible.  And so I ripped out Get-VM from hyperv.ps1 and turned it into a self-standing function called getVmDetails.

Read more...

Introducing the Advanced Virtual PC Controls for Windows 7

Last year I got a nice gift from Microsoft for attending TechEd in the form of a TechNet subscription.  After receiving my activation code I promptly upset my ISP by downloading everything I could get my hands on.  It was enough that I’m honestly shocked I didn’t get a call or get turned off.  Among those downloads was a product I had toyed with in the past but never really gotten in to, Windows Home Server (WHS).

For those not familiar with WHS it’s basically Miscrosoft’s home backup tool based off the Windows Server 2003 SBS operating system.  It includes the ability to backup your home computers, store shared files, stream audio/video, remote control your home machines from the Internet, and much more.  I had never really played with it before because I lacked the spare change to buy the necessary hardware.  Enter virtualization… 

Read more...

Saving perfmon templates in Windows Server 2008 [R2], Vista and 7

Managed Windows Server Performance Tip

Here is a great tip for someone looking to review some performance information on their managed Windows dedicated server or Windows Cloud server. Also, don't forget that included in our Complete Care Managed Services (CCMS) is enhanced monitoring and even personal system and data reviews by your Microsoft Certified support team.

There is a slight change in the way perfmon (the lovingly short way of saying Windows Performance Monitor) templates work once you leave the XP/2003 domain.  In the old days Microsoft likes to put everything in these hard to dissect, custom bin files that you couldn't easily, or at all, modify without the aid of the Microsoft application.  Luckily they are leaving that model behind for one that is open and easy for administrators to automate with.  Enter the XML Dragon.

Perfmon in Windows Server 2008 [R2], Vista and 7 now uses easy to edit XML templates to store custom made templates.  To change the template simply edit the document in your XML editor of choice, mine is UltraEdit, then create a new data collection set with your custom template.

I'm not going to re-invent the wheel here, so if you are not familiar with creating manual/custom data collector sets, or perfmon in general, please check out this very detailed TechNet article: http://technet.microsoft.com/en-us/library/cc749249.aspx.  Once you are done creating your set simply right-click on the set and select Save Template... from the menu.  Now it's time for a beautiful snippet with a wonderfully drawn red arrow pointing out the location on the menu, for those visual learners among us.

 

 

My art skills are awesome, I know.

As you save the template you may noticed the file type is a simple old .XML file.  As long as you don't mess with the structure you can edit the XML data to your heart's content.

In one scenario, load testing a six node webfarm with two SQL servers, I was able to setup all eight data collector sets in just a few minutes by creating a master template, making a copy for each server, opening the XML in UltraEdit (Notepad works well too), and using the replace text tool to change the server name.  Save and create a new data collector set from a template for each server and done.  I even wrote a few PowerShell lines start and stop the collectors.

$collectors = "DataCollectorSet01","DataCollectorSet02","DataCollectorSet03", ...  (and so on until all the data collector set names are listed)

To mass start the collectors:

foreach ($collector in $collectors) {logman start $collector}

To mass stop:

foreach ($collector in $collectors) {logman stop $collector}

Easy as can be.  Drop me a comment if you have any questions.

To find out more about our solutions, check out the links below our contact us at sales@orcsweb.com.

Managed Windows Dedicated Server Hosting
Managed Windows Cloud Server Hosting
Managed Shared Windows Hosting