Posts

Showing posts from January, 2015

Weird Spaces Between Characters in PowerShell Output

Have you ever redirected output from PowerShell into a file, only to find that there are spaces between every character?  Have you ever redirected output from PowerShell into a config file that the program just absolutely refuses to read in, even through it looks exactly the same as a known-good config file?  If so, you probably have encoding issues.  The good news?  They're really easy to fix, once you know what's going on.

So, by default that nice ">" output redirect uses Unicode.  Most of the time, that works just fine... but sometimes, especially if you're working with legacy software, it's going to cause you problems.  Here's a TechNet article on the issue.  Let's take a quick look at some examples - run this command in PowerShell to generate an example file:

echo "Hello World" > test.txt

Then open up test.txt in Notepad, hit "Save As" and look at the bottom of the window.  There's an "Encoding" section tha…

PowerCLI Wildcards

It seems like every day I'm reminded just how helpful PowerShell (and specifically PowerCLI) is during normal server administration.  Sure, you can do those tasks in the GUI with a few mouse clicks (and a moderate amount of waiting for the web interface to draw windows...), but PowerCLI can get it done so much faster!

For example, one of my customers had a collection of ESXi hosts that needed to be moved into a cluster.  Rather than dragging each one into it, I looked up the PowerCLI command (get-vmhost ESXiServer | move-vmhost -destination ClusterName).  Once you can do it for one host, it takes even fewer characters to do it to all hosts (get-vmhost | move-vmhost -destination ClusterName).  The part that made me smile was that it was also trivial to select the specific range of hosts that I wanted to move by simply using: get-vmhost *esx0[1-8]* | move-vmhost -destination ClusterName.

What that command did, for anyone who isn't familiar with that syntax, is to move into the …