Hyper-V – Child is trapped in “Starting”

Once, once in a Blue moon you’ll run into a situation where the Hyper-V Child is “starting” and shows a stuck status of 0%.   You can’t stop it.  You can’t access it.

You’re stuck!

No.  No you’re not.  It’s an easy fix.  Just kill the VMWP.EXE associated with the Child.   But how do you tell?

Believe it or not it’s incredibly easy.  Just use Process Explorer from www.sysinternals.com

Use the Process Explorer on your problematic host to see all the VMWP.EXE processes.    When you examine the details you’ll notice that the working VMWP.EXE processes contain a reference to the Physical VHD file.   The ones that are stuck have no reference to anything. 

If you look at them in Process Explorer you will see references to files, but NONE with a reference to the configuration or the VHD data.   Those are safe to “End Process”.

Once you do that the problematic Children in Hyper-v will start.

Yes a restart will fix you, but the fact is not everybody can reboot a host Server.   Key word “Production Environment”.  Second key word “Downtime”

Your best setup involves of course a clustered setup with failover.  But in some situations you can’t do that.  Budget can be one.

Knowing you CAN patch the situation without killing the host?  Very important.

Strive for the redundancy.  But remember, recovery should always be under YOUR control

The Power is YOURS

Sean
The Energized Tech

PowerCORE – Server 2008R2 and Powershell Unleashed Part 4

Powershell

So we now have a Server 2008R2 core box, Powershell enabled that can easily Add/Remote Roles and Features.  Let’s make this a useful box.

One of the simpler roles you’ll typically run is the File Server so you can share files.   Using the Powershell module “ServerManager” makes adding or removing these changes very easy.  

Just execute in Powershell

IMPORT-MODULE ServerManager
ADD-WINDOWSFEATURE “File-Services”

It will require one reboot after it’s done to allow it to take foot properly

Once done you now have a potential file server.   I say “Potential” since you still have to create Shares, Files and Permissions.

Well generally once you have a Folder you can create a Share Correct?

So we’re going to place a Folder at the root of the C: Drive called “DATA”

NEW-ITEM –path C:DATA –type directory –force

Now to create a Network share in Powershell we’re going to leverage the built in WMI libraries in Windows to create them.  WMI (Windows Management Instrumentation) allows you to not only View but manipulate many features of Windows.  

[wmiclass]”win32-share”

Is the technique you can use in Powershell to access the Keying in a

[wmiclass]”win32-share” | get-member

Will show us all the available members of this object.  There is one in particular called “Create”. 

Definition : System.Management.ManagementBaseObject Create(System.String Path, System.String Name, System.UInt32 Type, System.UInt32 MaximumAllowed, System.String Description, System.String Password, System.Management.ManagementObject#Win32-SecurityDescriptor Access)

For us non Programmers it breaks down to this.  The Create Method will take up 5 particular parameters in this order.

PATH, NAME,PermissionFlags, MaximumAllowedConnections, DescriptionOfShare,SharePassword,

Creating a share is just a matter of passing some basic information to this class.  Namely the Name of the Share, the physical location and the maximum allowed users.

So if I have a potential folder called “C:Powershell” and I’d like to share it out to my network as “POWERSHELL” as a fileshare I just fire up this command.

([wmiclass]”win32-share”).create(“C:Powershell”,”Powershell”,0)

Why the “0”? You don’t just have file shares.  You also have Printer shares and IPC as well.   The same command is used to create and mange them all

But just as easily, we can make this into a function to add to out Powershell profile.   Just substitute in what we need to change on a regular basis.

function global:NEW-SHARE($Location,$Name) {
    ([wmiclass]”win32-share”).Create($Location, $Name)

}

This is of course a very simple function but one we can build on later.    Like the ability to set share security and the maximum number of allowed users.  As well we should check the status of whether it was created successfully.

But that’s where Powershell is just fantastic.  We can build the tool to MEET our needs in the short term and later on add on to it.

Next time we’ll dig into some more features of Server 2008R2 Core and how we can use Powershell to manage them.  

The Power of Shell is in YOU

Sean
The Energized Tech

Powershell – Easily Remove Blank Folders and Clean Up Files

Powershell

Today I had something that was just BUGGING me.   Like many people I have a collection of Music.   And like many, that folder structure justs SITS for the most part unmaintained.  The only maintenance being whatever the music software did.

I started going through the pile and found I had a series of folders that no longer contained MP3 files (I deleted it from the collection at one point with the supplied software).  However it left behind .INI, Thumbs.DB or .JPG files

Well I wasn’t worried about the JPG files in the music folder collection since most of the time they would redownload from the source site.  So I decided to get thiings clearned up ONCE and FOR ALL without spending $$$.

So I used Powershell 🙂

GET-CHILDITEM FolderName –recurse –include *.EXT | REMOVE-ITEM

Will easily remove all offending items (like say .TMP files?) but certain file types are automatically hidden by the O/S.  Rather than editing my default folder settings globally, I can tack on a –force which “FORCES” the Commandlet to show me everything.

So phase one.  REmove all those .JPG files in the Music Collection.

GET-CHILDITEM C:Music –recurse –include *.jpg,Desktop.ini,thumbs.db –force

Once I could see it was pulling up what I wanted successfully I patched on REMOVE-ITEM.  Now since I trust MYSELF but NOT “Murphy’s Law” I tacked on a –whatif just to be safe.  Also since many of the items I was going to removewere hidden, I have to tack on an additional –force to make sure REMOVE-ITEM is allowed to see them. 

If you don’t, you will get an error about lack of access, security denied, cows falling from the sky, blah blah blah….

GET-CHILDITEM C:Music –recurse –include *.jpg,Desktop.ini,thumbs.db –force | REMOVE-ITEM –force -whatif

So now once I can see it will remove all the correct data I remove the –whatif and the let the command do it’s work in Powershell.  Now a new problem surfaces.  I have folders that are now empty wasting space.

Again in Powershell this is not a problem.  For within the Objects for Filesystem are Methods to see how many files OR Directories are within a folder.  So by adding in a .GETFILES().COUNT or GETDIRECTORIES().COUNT to a particular object I can see, literally if it’s empty!

So I make second script than can remove the dead folders

GET-CHILDITEM C:Music –recurse –force | where { $-.PSISContainer } | foreach { IF { $-.Getfiles().Count –eq 0 –and $-.GetDirectories.Count –eq 0) { REMOVE-ITEM $- }}

Now the tricky part.   Since we know each time we clean this up, we may have NEW empty folders.  so we’ll have to repeat this process until we have no empty ones.  So we’ll need to add in a counter to track how many empty folders.  So at this point, let’s just make a script so it’s all viewable and clean.

————— Begin Cleanup Script ——————————

Do {

# Get of all the directories in the Target tree, ONLY the Directories

$LIST=GET-CHILDITEM C:Music –recurse –force | where { $-.PSISContainer }

# We Flag the $DONE variable.  If even ONE folder is removed (Empty)
# It will flag as $FALSE

$DONE=$TRUE

foreach ($Directory in $LIST) {

# Check the count of folders and Directories in THIS directory
# If it’s a total of 0 for both, we remove the directory and flag at least ONE $FALSE
#
# If no Blank folders ever get found, $DONE will be $TRUE and the loop will exit
#

IF { $Directory.Getfiles().Count –eq 0 –and $Directory.GetDirectories.Count –eq 0)
     { REMOVE-ITEM $Directory
     $DONE=$FALSE
}
}

} until ($DONE –eq $TRUE)

—————– End Cleanup Script ——————————

So now what do we have?  A simple way to go through a list of folders and purge blanks.  You could tweak this script any way that suits you as well,  tacking in Date/Time filters.  Even prompting where to start.

Remember, the Power of Shell is in YOU

Sean
the Energized Tech