Feed aggregator

My Daily Hyper-V Status Email–Part 2 of 5

Virtual PC Guy - Mar, 18/03/2014 - 17:12

Yesterday, I introduced my daily status email.  Today I am going to talk about the first chunk of information that is included in this email: event logs.

The primary goal of my status email is to let me know if anything has gone wrong.  By looking at any errors or warnings in the System and Hyper-V event logs; I can get a pretty good feel for the state of my servers.  Here is a quick screenshot from a recent status email:

This display was generated with this code:

# EventLog $message = $message + "<style>TH{background-color:$($errorColor)}TR{background-color:$($tableColor)}</style>" $message = $message + "<B>Parent EventLog</B> <br> <br>" $message = $message + "Errors: <br>" + ((Get-EventLog system -after (get-date).AddHours(-24) -entryType Error) | ` Select-Object @{Expression={$_.InstanceID};Label="ID"}, ` @{Expression={$_.Source};Label="Source"}, ` @{Expression={$_.Message};Label="Message"} ` | ConvertTo-HTML -Fragment) ` + " <br>"   $message = $message + "<style>TH{background-color:$($warningColor)}TR{background-color:$($tableColor)}</style>" $message = $message + "Warnings: <br>" + ((Get-EventLog system -after (get-date).AddHours(-24) -entryType Warning) | ` Select-Object @{Expression={$_.InstanceID};Label="ID"}, ` @{Expression={$_.Source};Label="Source"}, ` @{Expression={$_.Message};Label="Message"} ` | ConvertTo-HTML -Fragment) ` + " <br>"   # Hyper-V EventLog $message = $message + "<style>TH{background-color:$($errorColor)}TR{background-color:$($tableColor)}</style>" $message = $message + "<B>Hyper-V EventLog</B> <br> <br>" $message = $message + "Errors: <br>" + ((Get-WinEvent -FilterHashTable @{LogName ="Microsoft-Windows-Hyper-V*"; StartTime = (Get-Date).AddDays(-1); Level = 2}) | ` Select-Object @{Expression={$_.InstanceID};Label="ID"}, ` @{Expression={$_.Source};Label="Source"}, ` @{Expression={$_.Message};Label="Message"} ` | ConvertTo-HTML -Fragment) ` + " <br>"   $message = $message + "<style>TH{background-color:$($warningColor)}TR{background-color:$($tableColor)}</style>" $message = $message + "Warnings: <br>" + ((Get-WinEvent -FilterHashTable @{LogName ="Microsoft-Windows-Hyper-V*"; StartTime = (Get-Date).AddDays(-1); Level = 3}) | ` Select-Object @{Expression={$_.InstanceID};Label="ID"}, ` @{Expression={$_.Source};Label="Source"}, ` @{Expression={$_.Message};Label="Message"} ` | ConvertTo-HTML -Fragment) ` + " <br>"

Deep inside this code are two basic cmdlets.  Get-EventLog is used for getting entries from the System event log:

Get-EventLog system -after (get-date).AddHours(-24) -entryType Error

While Get-WinEvent is used for getting entries from the Hyper-V event logs:

Get-WinEvent -FilterHashTable @{LogName ="Microsoft-Windows-Hyper-V*"; StartTime = (Get-Date).AddDays(-1); Level = 2}

The rest of the code around these cmdlets performs the following operations:

  • I use raw HTML to set the color of the table headers.  Errors are put in tables with a red header, warnings get a yellow header.
  • I run the output of these commands through Select-Object with the use of the “Expression” option to set column labels appropriately.
  • Finally, I use ConvertTo-HTML –Fragment to get a nice HTML table outputted.

Tomorrow I will move on to showing how I generate information about the virtual machine state and replication health.


Categorías: Virtualización

My Daily Hyper-V Status Email–Part 1 of 5

Virtual PC Guy - Lun, 17/03/2014 - 17:17

I have spent a fair amount of time creating a reliable and resilient Hyper-V deployment in my house.  For the most part this system runs smoothly, however, the resiliency of the design leads to an interesting problem.

My Hyper-V servers are housed in a small closet off the side of my garage.  And if something goes wrong (hard disk failure, system failure, etc…) everything keeps on running happily.  And that is the problem, it should not run happily, it should tell me that something is wrong.  If something is wrong I needed to know straight away – so I can replace broken parts, etc… before a bigger problem develops.

To address this issue– I have created a PowerShell script that runs on each server and sends me a daily status email.

I have been refining this status email script over the last year or so – and am very happy with the results.  Some of the goals I had with this script were:

  • Should work with my ISPs SMTP server (so it works even if my internal infrastructure is in a bad state)
  • Should tell me everything I need to know about my servers
  • Should allow me to tell the status at a glance

At this point in time, I get a daily status email with all the information I need, handily color coded so I can see quickly if everything is good or not:

This week I am going to step through all the parts of this script (it is quite a large script!) and explain what they do, and why they are there.

Today I am going to cover some of the “trimming” that is necessary to make this script work.  Below is a code snippet which represents to top and bottom sections of my script – with all the data logic pulled out of the middle.

# Variables $filedate = get-date $computer = gc env:computername $metricsData = get-vm | measure-vm $tableColor = "WhiteSmoke" $errorColor = "Red" $warningColor = "Yellow" $FromEmail = "email@email.org" $ToEmail = "email@email.org"   # Establish Connection to SMTP server $smtpServer = "smtp.yourserver.com" $smtpCreds = new-object Net.NetworkCredential("yourUserName", "yourPassword") $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.UseDefaultCredentials = $false $smtp.Credentials = $smtpCreds   # HTML Style Definition $message = "<!DOCTYPE html PUBLIC`"-//W3C//DTD XHTML 1.0 Strict//EN`" `"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd`">" $message = "<html xmlns=`"http://www.w3.org/1999/xhtml`"><body>" $message = "<style>" $message = $message + "TABLE{border-width:2px;border-style: solid;border-color: #C0C0C0 ;border-collapse: collapse;width: 100%}" $message = $message + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}" $message = $message + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}" $message = $message + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}" $message = $message + "H1{font-family:Calibri;}" $message = $message + "H2{font-family:Calibri;}" $message = $message + "Body{font-family:Calibri;}" $message = $message + "</style>"   # Title $message = $message + "<h2>Data for Hyper-V Server '$($computer)' : $($filedate)</h2>"   # # A whole bunch of code goes here... #   $message = $message + "</body></html>"   $email = new-object Net.Mail.MailMessage $email.Subject = "Hyper-V Server Report: $($filedate)" $email.From = new-object Net.Mail.MailAddress($FromEmail) $email.IsBodyHtml = $true $email.Body = $message $email.To.Add($ToEmail)   # Send Email $smtp.Send($email)

This is basically the code that is necessary to send an email using PowerShell.  Note, there are simpler ways to send an email using PowerShell – but I am doing it with the Net.Mail.SmtpClient and Net.Mail.MailMessage objects for two reasons:

  1. My ISP (like many ISPs) requires that I authenticate to their SMTP server in order to send email.  This script supports SMTP authentication.
  2. I really wanted a color coded email – so that problems would be bright red and grab my attention.  To do this properly means that I need to be able to generate a HTML based email, not just a plain text one.

The rough summary of the code above is:

  1. All the necessary variables are established (note – I have removed my email addresses, usernames and passwords – so you will need to swap in appropriate values here).
  2. A connection to the SMTP server is created
  3. A HTML header is created for the email
  4. There is a whole bunch of code removed (that I will be covering over the course of this week)
  5. The email message is constructed, using the HTML message string as the body
  6. Finally, the email is sent using the SMTP server

Over this week I will be covering the sections of this script that:

  1. Gather key event log information
  2. Gather VM and VM Replication health information
  3. Gather Storage health information
  4. Gather utilization data about the virtual machines

The final result – for those who are too impatient to wait out the week – is the script that I have attached to the end of this blog post.  I have this script setup to run once a day using a scheduled task.


Categorías: Virtualización

RFC 7151 - File Transfer Protocol HOST Command for Virtual Hosts

The Official Microsoft IIS Site - Vie, 14/03/2014 - 12:32

I received an email yesterday from the RFC Editor that a new Request for Comments (RFC) document has just been published, RFC 7151, which adds support for a new "HOST" command to FTP. This new command allows hosting multiple FTP sites on a single IP address, much like what Host Headers provide for HTTP.

Here's the URL to the new RFC on the RFC Editor website:

File Transfer Protocol HOST Command for Virtual Hosts

Or you can see the HTML-based version at the following URL:


One minor point which I would like to clarify is that this adds a new command for FTP to specify which virtual host to connect to. I periodically hear people referring to this as "FTP Host Headers", but that is technically incorrect since FTP does not have request headers like HTTP. Here's a simple example of what the communications flow looks like when the HOST command is used:

CLIENT> HOST ftp.example.com SERVER> 220 Host accepted CLIENT> USER foo SERVER> 331 Password required CLIENT> PASS bar SERVER> 230 User logged in

I need to make sure that I thank my co-author for this RFC, Paul Hethmon, who has authored other FTP-related RFCs over the years. For example, Paul wrote RFC 3659, and he co-wrote RFC 2389 with Robert Elz. As a result, the Internet community has Paul and Robert to thank for several great FTP command extensions in the past. (e.g. FEAT, OPTS, MDTM, SIZE, REST, MLST, MLSD, etc.) Paul and I co-wrote RFC 7151 over the past several years, and it was great working with him.

Support for the HOST command has been built-in to Microsoft's FTP service since IIS 7.0, but now that the RFC has been officially published I hope that this feature will be adopted by other FTP servers and clients. That being said, IIS is not the only implementation of the FTP HOST command; at the time of this blog post, these are the server and client implementations that I am aware of which already provide support for this new command. (Note: there may be more than I have listed here; these are just the implementations that I currently know about.)

In addition to the clients listed above, if you have been reading my series on FTP clients over the past few years, I have posted details on how to use the FTP HOST command with some other FTP clients which do not provide built-in support. For example, the Core FTP Client allows you to specific pre-login commands as part of an FTP site's connection properties, so you can manually type in the HOST command and save it along the site's settings.

A Little Bit of History

When I joined the feature team which was creating the FTP service for Windows Server 2008, one of the things that bothered us was that there was no way at the protocol level to host multiple FTP sites on the same IP address. There were several ways that FTP server implementations were approximating that sort of functionality, for example the User Isolation features that we ship with FTP for IIS, but each FTP server seemed to be implementing its own workaround and there was no standardization.

Because of this limitation, our team received a lot of requests to add "FTP Host Headers," although as I explained earlier FTP has no concept of request headers. To help address some of the questions which I was often seeing, I explained the lack of hostname support for FTP in detail in the comments section of my FTP User Isolation with Multiple User Accounts blog that I posted back in 2006, which was shortly before we began work on implementing the HOST command. I will paraphrase some of my comments here:

While I realize that the ability host multiple FTP sites on the same IP address and port like HTTP is a desired configuration, the simple answer is that FTP does not currently support this at the protocol level. To put things in perspective, RFC 959 is the governing document for FTP, and that was published in October of 1985. FTP was simply not designed for the Internet as we use and understand it today, even though it is a generally reliable protocol that many people will continue to use for some time. HTTP/1.1 was designed much later and resolved this problem, but only for HTTP requests.

There are three ways that you can create unique bindings for a web or HTTP site: IP address, port, or host header. FTP can create unique bindings by IP address or port, but the FTP protocol does not currently provide support for hostnames.

Here's why: HTTP packets consist of a set of request headers and possibly a block of data. Here's an example of a simple GET request:

GET /default.aspx HTTP/1.0 [CrLf] Accept: */* [CrLf] [CrLf]

When HTTP 1.1 was published in RFC 2068 and RFC 2616, it defined a header for specifying a "host" name in a separate name/value pair:

GET /default.aspx HTTP/1.1 [CrLf] Host: example.com [CrLf] Accept: */* [CrLf] [CrLf]

The "Host" header allows multiple HTTP virtual servers ("hosts") on the same IP address and port that are differentiated by host name. While this works great for the HTTP protocol, FTP currently has no comparable functionality. As such, the FTP protocol would have to be updated to allow multiple hosts on the same IP address and port, then FTP servers and clients would need to be updated to accommodate the changes to FTP.

While my explanation may have clarified root cause of the FTP limitation for anyone who was asking about it, I personally thought the situation was unacceptable. This inspired me to research the addition of a new command for FTP which would allow FTP clients to specify hostnames. As I was researching how to propose a new RFC document to the IETF, I discovered that Paul Hethmon had been researching the same problem a few years earlier. I contacted Paul and offered to combine our work, and he agreed. After several years of work and a great deal of supportive assistance from dozens of great people whom I met through the IETF, RFC 7151 has finally been published.

There are a lot of people besides Paul whom I should thank, and we mention them in the acknowledgments section of our RFC, which you can read at the following URL:


One final note - two of my coworkers, Jaroslav Dunajsky and Wade Hilmo, are mentioned in the acknowledgments section of the RFC. Jaroslav is the developer who implemented the FTP HOST command for IIS, and Wade is a senior developer on the IIS team who graciously allowed me to bounce ideas off him while I was doing my research over the past few years. (I probably I owe him a lunch or two.)

(Cross-posted from http://blogs.msdn.com/robert_mcmurray/)

Importing VMs Utilizing The Hyper-V WMI v2 Namespace

Taylor Brown's Blog - Mié, 12/03/2014 - 23:17

I have had a few folks ask me about importing VM’s though our WMI namespace.  The Hyper-V WMI v2 interfaces introduce a new concept of planned virtual machines, this  allows you to create/import virtual machines and make configuration changes prior to realizing them or converting them to real virtual machines that can be started or are even visible in the UI.

I have two samples below, the first one simply imports a VM and the second renames the VM as part of the import.  You can get more information about the ImportSystemDefinition API at http://msdn.microsoft.com/en-us/library/hh850082(v=vs.85).aspx.  We also have some additional samples utilizing planned virtual machines in our common sample code at http://msdn.microsoft.com/en-us/library/hh850032(v=vs.85).aspx.

Importing a VM

#Retrieve the management service
$VmMgmtSvc = Get-WmiObject -Namespace root\virtualization\v2 `
      -Class Msvm_VirtualSystemManagementService

#Import the VM, referencing the VM configuration, snapshot folder
$ImportedSystem_ret = $VmMgmtSvc.ImportSystemDefinition(
    "D:\Demo\Virtual Machines\1B3CDA1D-6FB6-4AAE-8E8D-8BE6BB587BD3.XML",
    $false) #Retaining the VM id

#Retrieve the object referencing the planned VM
$PlannedVM = [WMI]$ImportedSystem_ret.ImportedSystem

#Realize the planned VM

Modifying a VM as part of import

#Retrieve the management service
$VmMgmtSvc = Get-WmiObject -Namespace root\virtualization\v2 `
      -Class Msvm_VirtualSystemManagementService

#Import the VM, referencing the VM configuration, snapshot folder
$ImportedSystem_ret = $VmMgmtSvc.ImportSystemDefinition(
    "D:\Demo\Virtual Machines\1B3CDA1D-6FB6-4AAE-8E8D-8BE6BB587BD3.XML",
    $false) #Retaining the VM id

#Retrieve the object referencing the planned VM
$PlannedVM = [WMi]$ImportedSystem_ret.ImportedSystem

#Retrieve the setting data for the planned VM
$VmSetData = ($PlannedVM.GetRelated("Msvm_VirtualSystemSettingData", `
      "Msvm_SettingsDefineState", `
      $null, `
      $null, `
      "SettingData", `
      "ManagedElement", `
      $false, $null) | % {$_})

#Modify the name of the VM
$VmSetData.ElementName = "NewVMName"

#Realize the planned VM


Categorías: Virtualización

Protected Networks in Windows Server 2012 R2

Virtual PC Guy - Mié, 12/03/2014 - 01:11

One of the new features in Hyper-V in Windows Server 2012 R2 is the concept of a protected network:

In Windows Server 2012 R2 any network adapter that is added to a virtual machine is automatically configured as a protected network adapter.  This means nothing if you are not using Hyper-V clustering, but if you are using Hyper-V clustering it has an important effect.

Basically, we will monitor this network connection for any link failures. 

If we detect that the virtual switch that is used for this virtual network adapter no longer has a functioning network connection – we will move the virtual machine to another node in the cluster.  Before we do this though, we check to make sure that the destination computer does have a functioning network connection on the corresponding virtual switch (this is important to avoid mass virtual machine migrations in the event of a switch failure).

If you are using network teaming in the host environment, you are unlikely to suffer complete link failure – but this functionality gives you an extra level of protection for network connectivity.


Categorías: Virtualización

Huge growth in Microsoft’s market share for web servers!

The Official Microsoft IIS Site - Mar, 11/03/2014 - 19:07
Millions of people out there are using IIS to host their websites, but we all know it’s not the only product on the market. For many years, Apache was leading with a significant margin, but things are finally starting to change. According to NetCraft, a research company from the UK which specializes in analyzing the web and hosting market, IIS has had a huge spike in market share recently. According to the report they released a few days ago, IIS had almost 50 million new sites during February, increasing...(read more)

Monitor a site’s downtime…for free!

The Official Microsoft IIS Site - Vie, 07/03/2014 - 15:33
You have a really cool website that you or someone else designed, right? That’s great but it doesn’t do you much good if the site is down. Nobody can get to it and learn about your product or service, or even worse, buy something from you if it’s an ecommerce site. I know, it’s hosted by someone and they monitor it, right? Probably not. You can check with them, but most hosts don’t monitor sites by default. In many cases you should consider an external monitoring service. There are many out there...(read more)

IIS: Using Windows Authentication with Minimal Permissions Granted to Disk

The Official Microsoft IIS Site - Lun, 03/03/2014 - 20:37
I had a question asked me recently regarding Windows auth and NTFS permissions. Here’s the question: When I run an IIS site using Windows Authentication, is there a way to let the Application Pool account access files in disk instead of the logged in Read More......(read more)

FTP Clients - Part 13: WinSCP

The Official Microsoft IIS Site - Sáb, 01/03/2014 - 07:57

For this next installment in my series about FTP clients, I want to take a look at WinSCP, which is an open source FTP/SFTP client that is available from the following URL:


For this blog post I used WinSCP 5.5.1, and it was available for free when I wrote this blog post. That being said, WinSCP's author (Martin Prikryl) takes donations. (And I think that it's a worthy cause; I like to support independent development work.)

WinSCP 5.5 Overview

When you open WinSCP 5.5, you will first see the Login dialog box, which will be empty until you add some sites to the list. The Login dialog allows you to create folders so you can categorize your sites, and the user interface is comparable to what you would expect in a Site Manager for other FTP clients.

Fig. 1 - The opening Login dialog in WinSCP 5.5.

When you are adding FTP sites, you have three choices for the protocol: FTP, SCP, and SFTP; you also have four choices for encryption: No encryption, TLS/SSL Implicit encryption, TLS Explicit encryption, and SSL Explicit encryption. (I'll discuss those later.)

When you open a site for which you did not save the password, (which I highly recommend), you will be prompted for your password.

Fig. 2 - The WinSCP 5.5 Password dialog.

Once your FTP site is opened, the main application window is displayed, and it resembles a two-column file explorer interface with local and remote folders, which you might expect from a GUI-based FTP client. (Note: WinSCP refers to this as it's "Commander" interface.)

Fig. 3 - Local and Remote Folders.

That being said, if you change your application preferences, you can change the user interface so that it uses a single-column file explorer interface with a folder tree, which might be useful if you would rather use the FTP client as a drag-and-drop repository. (Note: WinSCP refers to this as it's "Explorer" interface.)

Fig. 4 - Remote Folder Tree and Files.

WinSCP 5.5 has support for automation through .NET and COM, and documentation about automating WinSCP 5.5 programmatically is available on the WinSCP website at the following URL:

WinSCP .NET Assembly and COM Library

There are several detailed automation examples on the WinSCP website that are written in C#, VB.NET, PowerShell, JavaScript, VBScript, etc., and the documentation is quite good. If you need to do a lot of FTP scripting and you are looking for a good way to automate your FTP sessions, you might want to consider this FTP client.

If you don't want to write a bunch of code, you can also automate WinSCP from a command line, and the documentation about that is available on the WinSCP website at the following URL:

WinSCP Command-line Options

Another great feature about WinSCP is that it can be downloaded as portable executables, which makes it easy to copy between systems. This is a great feature for me since I like to keep a collection of handy utilities in my SkyDrive/OneDrive folders.

Using WinSCP 5.5 with FTP over SSL (FTPS)

WinSCP 5.5 has built-in support for FTP over SSL (FTPS), and it supports both Explicit and Implicit FTPS. To specify which type of encryption to use for FTPS, you need to choose the appropriate option from the Encryption drop-down menu for an FTP site.

Fig. 5 - Specifying the FTPS encryption.

Once you have established an FTPS connection through WinSCP 5.5, the user experience is the same as it is for a standard FTP connection. That being said, I could not find a way to drop out of FTPS once a connection is established, so FTPS is an all or nothing option for your sessions.

Using Using WinSCP 5.5 with True FTP Hosts

True FTP hosts are not supported natively, and even though WinSCP 5.5 allows you to send post-login commands after an FTP site has been opened, I could not find a way to send a custom command before sending user credentials, so true FTP hosts cannot be used.

Using Using WinSCP 5.5 with Virtual FTP Hosts

WinSCP 5.5's login settings allow you to specify the virtual host name as part of the user credentials by using syntax like "ftp.example.com|username" or "ftp.example.com\username", so you can use virtual FTP hosts with WinSCP 5.5.

Fig. 6 - Specifying an FTP virtual host. Scorecard for WinSCP 5.5

This concludes my quick look at a few of the FTP features that are available with WinSCP 5.5, and here are the scorecard results:

ManagerExtensibility WinSCP 5.5.1 Rich Y Y Y N Y N/A Note: I could not find anyway to extend the functionality of WinSCP 5.5; but as I said
earlier, it provides rich automation features for .NET, COM, and the command-line.

That wraps things up for today's blog. Your key take-aways should be: WinSCP 5.5 is good FTP client with a lot of options, and it has a very powerful automation story. As I mentioned earlier, if you have to do a lot of FTP automation, you should really take a look at this FTP client.

(Cross-posted from http://blogs.msdn.com/robert_mcmurray/)

Adding Additional Content Types to my Classic ASP and URL Rewrite Samples for Dynamic SEO Functionality

The Official Microsoft IIS Site - Sáb, 01/03/2014 - 02:43

In December of 2012 I wrote a blog titled "Using Classic ASP and URL Rewrite for Dynamic SEO Functionality", in which I described how to use Classic ASP and URL Rewrite to dynamically-generate Robots.txt and Sitemap.xml or Sitemap.txt files. I received a bunch of requests for additional information, so I wrote a follow-up blog this past November titled "Revisiting My Classic ASP and URL Rewrite for Dynamic SEO Functionality Examples" which illustrated how to limit the output for the Robots.asp and Sitemap.asp files to specific sections of your website.

That being said, I continue to receive requests for additional ways to stretch those samples, so I thought that I would write at least a couple of blogs on the subject. With that in mind, for today I wanted to show how you can add additional content types to the samples.


Here is a common question that I have been asked by several people:

"The example only works with *.html files; how do I include my other files?"

That's a great question, and additional content types are really easy to implement, and the majority of the code from my original blog will remain unchanged. Here's the file by file breakdown for the changes that need made:

FilenameChanges Robots.asp None Sitemap.asp See the sample later in this blog Web.config None

If you are already using the files from my original blog, no changes need to be made to your Robots.asp file or the URL Rewrite rules in your Web.config file because the updates in this blog will only impact the output from the Sitemap.asp file.

Updating the Sitemap.asp File

My original sample contained a line of code which read "If StrComp(strExt,"html",vbTextCompare)=0 Then" and this line was used to restrict the sitemap output to static *.html files. For this new sample I need to make two changes:

  1. I am adding a string constant which contains a list of file extensions from several content types to use for the output.
  2. I replace the line of code which performs the comparison.

Note: I define the constant near the beginning of the file so it's easier for other people to find; I would normally define that constant elsewhere in the code.

<% Option Explicit On Error Resume Next Const strContentTypes = "htm|html|asp|aspx|txt" Response.Clear Response.Buffer = True Response.AddHeader "Connection", "Keep-Alive" Response.CacheControl = "public" Dim strFolderArray, lngFolderArray Dim strUrlRoot, strPhysicalRoot, strFormat Dim strUrlRelative, strExt Dim objFSO, objFolder, objFile strPhysicalRoot = Server.MapPath("/") Set objFSO = Server.CreateObject("Scripting.Filesystemobject") strUrlRoot = "http://" & Request.ServerVariables("HTTP_HOST") ' Check for XML or TXT format. If UCase(Trim(Request("format")))="XML" Then strFormat = "XML" Response.ContentType = "text/xml" Else strFormat = "TXT" Response.ContentType = "text/plain" End If ' Add the UTF-8 Byte Order Mark. Response.Write Chr(CByte("&hEF")) Response.Write Chr(CByte("&hBB")) Response.Write Chr(CByte("&hBF")) If strFormat = "XML" Then Response.Write "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf Response.Write "<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">" & vbCrLf End if ' Always output the root of the website. Call WriteUrl(strUrlRoot,Now,"weekly",strFormat) ' -------------------------------------------------- ' This following section contains the logic to parse ' the directory tree and return URLs based on the ' files that it locates. ' -------------------------------------------------- strFolderArray = GetFolderTree(strPhysicalRoot) For lngFolderArray = 1 to UBound(strFolderArray) strUrlRelative = Replace(Mid(strFolderArray(lngFolderArray),Len(strPhysicalRoot)+1),"\","/") Set objFolder = objFSO.GetFolder(Server.MapPath("." & strUrlRelative)) For Each objFile in objFolder.Files strExt = objFSO.GetExtensionName(objFile.Name) If InStr(1,strContentTypes,strExt,vbTextCompare) Then If StrComp(Left(objFile.Name,6),"google",vbTextCompare)<>0 Then Call WriteUrl(strUrlRoot & strUrlRelative & "/" & objFile.Name, objFile.DateLastModified, "weekly", strFormat) End If End If Next Next ' -------------------------------------------------- ' End of file system loop. ' -------------------------------------------------- If strFormat = "XML" Then Response.Write "</urlset>" End If Response.End ' ====================================================================== ' ' Outputs a sitemap URL to the client in XML or TXT format. ' ' tmpStrFreq = always|hourly|daily|weekly|monthly|yearly|never ' tmpStrFormat = TXT|XML ' ' ====================================================================== Sub WriteUrl(tmpStrUrl,tmpLastModified,tmpStrFreq,tmpStrFormat) On Error Resume Next Dim tmpDate : tmpDate = CDate(tmpLastModified) ' Check if the request is for XML or TXT and return the appropriate syntax. If tmpStrFormat = "XML" Then Response.Write " <url>" & vbCrLf Response.Write " <loc>" & Server.HtmlEncode(tmpStrUrl) & "</loc>" & vbCrLf Response.Write " <lastmod>" & Year(tmpLastModified) & "-" & Right("0" & Month(tmpLastModified),2) & "-" & Right("0" & Day(tmpLastModified),2) & "</lastmod>" & vbCrLf Response.Write " <changefreq>" & tmpStrFreq & "</changefreq>" & vbCrLf Response.Write " </url>" & vbCrLf Else Response.Write tmpStrUrl & vbCrLf End If End Sub ' ====================================================================== ' ' Returns a string array of folders under a root path ' ' ====================================================================== Function GetFolderTree(strBaseFolder) Dim tmpFolderCount,tmpBaseCount Dim tmpFolders() Dim tmpFSO,tmpFolder,tmpSubFolder ' Define the initial values for the folder counters. tmpFolderCount = 1 tmpBaseCount = 0 ' Dimension an array to hold the folder names. ReDim tmpFolders(1) ' Store the root folder in the array. tmpFolders(tmpFolderCount) = strBaseFolder ' Create file system object. Set tmpFSO = Server.CreateObject("Scripting.Filesystemobject") ' Loop while we still have folders to process. While tmpFolderCount <> tmpBaseCount ' Set up a folder object to a base folder. Set tmpFolder = tmpFSO.GetFolder(tmpFolders(tmpBaseCount+1)) ' Loop through the collection of subfolders for the base folder. For Each tmpSubFolder In tmpFolder.SubFolders ' Increment the folder count. tmpFolderCount = tmpFolderCount + 1 ' Increase the array size ReDim Preserve tmpFolders(tmpFolderCount) ' Store the folder name in the array. tmpFolders(tmpFolderCount) = tmpSubFolder.Path Next ' Increment the base folder counter. tmpBaseCount = tmpBaseCount + 1 Wend GetFolderTree = tmpFolders End Function %>

That's it. Pretty easy, eh?

I have also received several requests about creating a sitemap which contains URLs with query strings, but I'll cover that scenario in a later blog.

(Cross-posted from http://blogs.msdn.com/robert_mcmurray/)

Hosting Providers and HRM

Virtualization Team Blog - Mié, 19/02/2014 - 04:33

If you are a hosting provider who is interested in offering DR as a service – you should go over this great post by Gaurav on how Hyper-V Recovery Manager (HRM) helps you build this capability http://blogs.technet.com/b/scvmm/archive/2014/02/18/disaster-recovery-as-a-service-by-hosting-service-providers-using-windows-azure-hyper-v-recovery-manager.aspx

The post provides a high level overview of the capability and also a detailed FAQ on the common set of queries which we have heard from our customers. If you have any further questions, leave a comment in the blog post.

Categorías: Virtualización

WAWS - WebJob to upload FREB files to Azure Storage using the WebJobs SDK

The Official Microsoft IIS Site - Mar, 18/02/2014 - 07:41

After writing my earlier post on creating a simple WebJob to upload the Failed Request Tracing logs automatically to Windows Azure Blob Storage account, I was discussing this with the awesome development team of the WebJob SDK, Amit Apple, and Mike Stall. And, the outcome is, getting my sample modified to use the awesome WebJobs SDK that eases a lot of tasks. And there is more to it – cool Azure Jobs Dashboard with your Windows Azure Web sites giving you a cool dashboard of your WebJobs messages getting processed. With the WebJobs SDK, there is automatic way of……….

Read the complete post here.

Updated Hypervisor Top Level Functional Specification

Virtual PC Guy - Lun, 17/02/2014 - 19:55

We have recently published a new version of the Hypervisor Top Level Functional Specification for Windows Server 2012 R2 / Windows 8.1.  You can grab a copy here:

http://download.microsoft.com/download/A/B/4/AB43A34E-BDD0-4FA6-BDEF-79EEF16E880B/Hypervisor Top Level Functional Specification v4.0.docx

Now, when you first open this document and start looking through it – you are probably going to think to yourself “Good grief! This is much too detailed for me!”.  And yes, it is a very technical document.  It is essentially a guide to how to build your own virtualization solution on our hypervisor.  That said, a couple of times a year I direct people to read this document so they can get answers to questions such as:

  • Can I discover the hypervisor version from inside the virtual machine?
  • How are virtual processors actually scheduled by the hypervisor?
  • How does the hypervisor handle machine check events?

There is a lot of good information in there – so I would recommend taking the time to read it through.


Categorías: Virtualización

Hyper-V Replica Certificate based authentication and Proxy servers

Virtualization Team Blog - Lun, 17/02/2014 - 14:45

Continuing from where we left off, I have a small lab deployment which consists of a AD, DNS, Proxy server (Forefront TMG 2010 on WS 2008 R2 SP1), primary servers and replica servers. When the primary server is behind the proxy (forward proxy) and when I tried to enable replication using certificate based authentication, I got the following error message: The handle is in the wrong state for the requested operation (0x00002EF3)

That didn’t convey too much, did it? Fortunately I had netmon running in the background and the only set of network traffic which was seen was between the primary server and the proxy. A particular HTTP response caught my eye:

The highlighted text indicated that the proxy was terminating the connection and returning a ‘Bad gateway’ error. Closer look at the TMG error log indicated that the error was encountered during https-inspect state.

After some bing’ing of the errors and the pieces began to emerge. When HTTPS inspection is enabled, the TMG server terminates the connection and establishes a new connection (in our case to the replica server) acting as a trusted man-in-the-middle. This doesn’t work for Hyper-V Replica as we mutually authenticate the primary and replica server endpoints. To work around the situation, I disabled HTTPS inspection in the proxy server

and things worked as expected. The primary server was able to establish the connection and replication was on track.

Categorías: Virtualización

Windows Azure Websites - WebJob to upload FREB logs to Azure Blob Storage

The Official Microsoft IIS Site - Sáb, 15/02/2014 - 08:06

Currently in Windows Azure Web sites, there is an option to store your website logs to Azure Blob Storage, but however, the FREB logs – failed request tracing logs, can only be stored in the file system. You will then grab them via your favorite FTP tool, and do the analysis. One of my co-worker asked this question on if we can store the Failed Request Tracing logs in the blog storage, and Richard Marr gave this interesting idea of using WebJobs to move the files to Azure Blob Storage. I tried this quickly, and have a beta version of a similar webjob ready for you if you want to try it.

 Read the complete post here.

Using Compare-VM on Compare-VM

Virtual PC Guy - Jue, 13/02/2014 - 18:49

I have been spending a lot of time this week looking at all the functionality that is available in the Compare-VM PowerShell cmdlet in Hyper-V.  The core concept of Compare-VM is that it returns a “virtual machine compatibility report” that lets you know about any problems that exist with the virtual machine.

Once you have the virtual machine compatibility report, you can fix the problems and then pass the report to the cmdlet that you actually wanted to use.

However, what if you are not sure that you have really fixed the problems with the virtual machine compatibility report?  Simple – you can just pass the compatibility report back into Compare-VM.

This will recheck the virtual machine and let you know if there are any problems remaining.  You can keep on doing this until you get a compatibility report with no incompatibilities.  This is very handy if you are just messing around at the PowerShell prompt and want to double check yourself.


Categorías: Virtualización

Using PowerShell to Live Migrate to a Computer with a Different Virtual Switch

Virtual PC Guy - Mié, 12/02/2014 - 17:11

So far this week I have shown you how to register and how to import virtual machines with configuration problems using PowerShell.  However, the question I most often hear is this one: how do I use PowerShell to live migrate a virtual machine to another computer – where the virtual switch names do not match?

Once again – the answer is: “Use Compare-VM”

Here you can see that I try and use Move-VM to live migrate a virtual machine, and I get an error because the virtual switch names do not match.  And just like in the other cases, I call Compare-VM and give it the same parameters as when I tried to use Move-VM.

After doing this I just need to fix the incompatibilities and pass the results into Move-VM.


Categorías: Virtualización

Importing an Incompatible VM with PowerShell

Virtual PC Guy - Mar, 11/02/2014 - 18:46

Yesterday I stepped through the process of registering an incompatible virtual machine with PowerShell.  But what if you want to import the virtual machine instead of registering it?  Well, the process is pretty much identical.  Replace Import-VM with Compare-VM, fix the incompatibilities on the virtual machine report, and import it.

You see, Compare-VM supports all the parameters supported by Import-VM:

So whatever the problem is, you can get it to work with Compare-VM.


Categorías: Virtualización

Registering an Incompatible VM with PowerShell

Virtual PC Guy - Lun, 10/02/2014 - 18:32

If you have ever tried to register a virtual machine in Hyper-V Manager, and the virtual machine was not compatible with your current computer, you would have seen something like this:

This is a GUI experience that allows you to make changes to the incoming virtual machine in order to make it work on the physical computer in question.  We use this same GUI in a couple of places – and internally we refer to it as “the fix-up wizard”, as it allows you to fix a virtual machine and make it compatible with your computer.

But what about when you want to use PowerShell?  There is no concept of a wizard in PowerShell – and sure enough when I try and register the same virtual machine in PowerShell I just get an error message:

So how do you make this work?  Well the answer is in the error message: use Compare-VM.  Compare-VM is the PowerShell equivalent of the fix-up wizard.

In this case I need to call Compare-VM and provide it with exactly the same parameters that I was using for Import-VM.  This returns a virtual machine compatibility report – which I will store in the variable $vmReport.

As you can see, the virtual machine compatibility report has a property called “Incompatibilities”.  This property is a collection of everything that is wrong with the virtual machine.  Here I have a virtual network adapter that is connected to a missing virtual network, and too many virtual CPUs.

There are two ways that you can fix up these problems.  The first way is to change the configuration on the object that is stored in the “source” property of the incompatibility in question.  The second way is to reconfigure the virtual machine object that is attached to the virtual machine compatibility report itself.  Below I show you how to do both:

Once you have fixed all the incompatibilities you can successfully register the virtual machine by using Import-VM and passing it the corrected compatibility report.


Categorías: Virtualización

Hyper-V Replica & Proxy Servers on primary site

Virtualization Team Blog - Dom, 09/02/2014 - 01:00

I was tinkering around with my lab setup which consists of a domain, proxy server, primary and replica servers. There are some gotchas when it comes to Hyper-V Replica and proxy servers and I realized that we did not have any posts around this. So here goes.

If the primary server is behind a proxy server (forward proxy) and if Kerberos based authentication is used to establish a connection between the primary and replica server, you might encounter an error: Hyper-V cannot connect to the specified Replica server <servername> due to connection timed out. Verify if a network connection exists to the Replica server or if the proxy settings have been configured appropriately to allow replication traffic.

I have a Forefront TMG 2010 acting as a proxy server and the logs in the proxy server

I also had netmon running in my primary server and the logs didn’t indicate too much other than for the fact that the connection never made it to the replica server – something happened between the primary and replica server which caused the connection to be terminated. The primary server name in this deployment is prb8.hvrlab.com and the proxy server is w2k8r2proxy1.hvrlab.com.

If a successful connection goes through, you will see a spew of messages on netmon

When I had observed the issue the first time when building the product, I had reached out to the Forefront folks @ Microsoft to understand this behavior. I came to understand that the Forefront TMG proxy server terminates any outbound (or upload) connections whose content length (request header) is > 4GB.

Hyper-V Replica set a high content length as we expect to transfer large files (VHDs) and it would save us the effort to re-establish the connection each time. A closer inspection of a POST request shows the content length which is being set by Hyper-V Replica (ahem, ~500GB)

The proxy server returns a what-uh? response in the form of a bad-request

That isn’t superhelpful by any means and the error message unfortunately isn’t too specific either. But now you know the reason for the failure – the proxy server terminates the connection the connection request and it never reaches the replica server.

So how do we work around it – there are two ways (1) Bypass the proxy server (2) Use cert based authentication (another blog for some other day).

The ability to by pass the proxy server is provided only in PowerShell in the ByPassProxyServer parameter of the Enable-VMReplication cmdlet - http://technet.microsoft.com/en-us/library/jj136049.aspx. When the flag is enabled, the request (for lack of better word) bypasses the proxy server. Eg:

Enable-VMReplication -vmname NewVM5 -AuthenticationType Kerberos -ReplicaServerName prb2 -ReplicaServerPort 25000 -BypassProxyServer $true Start-VMInitialReplication -vmname NewVM5

This is not available in the Hyper-V Manager or Failover Cluster Manager UI. It’s supported only in PowerShell (and WMI). Running the above cmdlets will create the replication request and start the initial replication.

Categorías: Virtualización
Distribuir contenido