{"id":219,"date":"2007-02-27T22:26:26","date_gmt":"2007-02-28T03:26:26","guid":{"rendered":"https:\/\/anildesai.net\/?p=219"},"modified":"2007-10-27T10:35:57","modified_gmt":"2007-10-27T15:35:57","slug":"virtual-server-automation-configuring-the-virtual-server-service","status":"publish","type":"post","link":"https:\/\/anildesai.net\/index.php\/2007\/02\/virtual-server-automation-configuring-the-virtual-server-service\/","title":{"rendered":"Automating Virtual Server, Part 3: Configuring the Virtual Server Service"},"content":{"rendered":"<p><em>This article was first published on <\/em><a href=\"http:\/\/searchservervirtualization.techtarget.com\/\"><em>SearchServerVirtualization.TechTarget.com<\/em><\/a><em>.<\/em><\/p>\n<p>In the first two articles in this series on \u201cAutomating Virtual Server\u201d, I presented details on connecting to an instance of Virtual Server using its COM API. The first focused on accomplishing this using VBScript, and the second focused on using .NET (Visual Basic .NET and C#). The articles stopped a little short of doing anything useful once you\u2019ve connected to a Virtual Server instance. So, that\u2019s where I\u2019ll resume. In this article, I\u2019ll present ways in which you can programmatically manage properties and details related to the Virtual Server service itself.<\/p>\n<h2>The Virtual Server Object<\/h2>\n<p>Understanding the relationships between the major objects and collections is an important first step when working with the Virtual Server COM API. The Virtual Server object represents the host computer\u2019s virtualization service. It contains properties and methods related to the configuration of the virtualization layer. Table 1 provides some examples of commonly-used properties.<\/p>\n<p><a href=\"https:\/\/anildesai.net\/wp-content\/uploads\/2007\/10\/image46.png\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" width=\"467\" src=\"https:\/\/anildesai.net\/wp-content\/uploads\/2007\/10\/image-thumb46.png\" alt=\"image\" height=\"483\" style=\"border-width: 0px\" \/><\/a><\/p>\n<p><strong>Table 1: Commonly-used properties of the Virtual Server object<\/strong><\/p>\n<p>If you\u2019re writing script or application code, these properties can be very helpful. For example, you might want to determine the default path into which a new VM would be placed (which returned by the .<strong>DefaultVMConfigurationPath<\/strong> property). Or, you might want to reference the .<strong>Version<\/strong> property so you can execute different sections of code based on the specific version of the Virtual Server platform that\u2019s running on the system. Finally, the .<strong>GetVirtualMachineFiles<\/strong> method allows you to take a quick inventory of all of the VM-related files that are available within the default search paths.<\/p>\n<h2>Getting Host Details<\/h2>\n<p>When programmatically working with Virtual Server, it\u2019s important to keep track of the details of the platform you\u2019re managing. One particularly useful collection for returning these details is the .HostInfo property of a Virtual Server object. Table 2 provides a listing of the information you can obtain.<\/p>\n<p><a href=\"https:\/\/anildesai.net\/wp-content\/uploads\/2007\/10\/image47.png\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" width=\"471\" src=\"https:\/\/anildesai.net\/wp-content\/uploads\/2007\/10\/image-thumb47.png\" alt=\"image\" height=\"179\" style=\"border-width: 0px\" \/><\/a><\/p>\n<p><strong>Table 2: Properties of the .HostInfo collection<\/strong><\/p>\n<h2>Code Examples: Getting Host Information<\/h2>\n<p>Now that we have an understanding of what information is available, let\u2019s write some simple code that will return the following:<\/p>\n<ul>\n<li>1) Total Uptime for the Virtual Server instance (returned in seconds)<\/li>\n<li>2) The Operating System platform<\/li>\n<li>3) The number of CPUs<\/li>\n<li>4) The CPU Speed<\/li>\n<\/ul>\n<p>The following Listings provide code samples in VBScript, VisualBasic.NET and C# formats, respectively.<\/p>\n<blockquote><p>Set objVirtualServer = CreateObject(&#8220;VirtualServer.Application&#8221;)<\/p>\n<p>Set objHostInfo = objVirtualServer.HostInfo<\/p>\n<p>&#8216;Generate the output string<\/p>\n<p>Output = &#8220;Uptime (sec): &#8221; &amp; objVirtualServer.Uptime<\/p>\n<p>Output = Output &amp; vbCrLf &amp; &#8220;Host OS: &#8221; &amp; objHostInfo.OperatingSystem<\/p>\n<p>Output = Output &amp; vbCrLf &amp; &#8220;# of CPUs: &#8221; &amp; objHostInfo.PhysicalProcessorCount<\/p>\n<p>Output = Output &amp; vbCrLf &amp; &#8220;CPU Speed: &#8221; &amp; objHostInfo.ProcessorSpeedString<\/p>\n<p>WScript.Echo Output<\/p><\/blockquote>\n<p><strong>Listing 1: Getting Virtual Server Host Info using VBScript<\/strong><\/p>\n<blockquote><p>Imports Microsoft.VirtualServer.Interop<\/p>\n<p>Namespace SearchServerVirtualization_VB<\/p>\n<p>Public Class Listing_2<\/p>\n<p>Public Shared Function GetHostInfo() As String<\/p>\n<p>Dim objVirtualServer As New VMVirtualServer<\/p>\n<p>Dim Output As String = &#8220;&#8221;<\/p>\n<p>Output = &#8220;Uptime (sec): &#8221; &amp; objVirtualServer.UpTime.ToString<\/p>\n<p>Output &amp;= vbCrLf &amp; &#8220;Host OS: &#8221; &amp; objVirtualServer.HostInfo.OperatingSystem.ToString<\/p>\n<p>Output &amp;= vbCrLf &amp; &#8220;# of CPUs: &#8221; &amp; objVirtualServer.HostInfo.PhysicalProcessorCount.ToString<\/p>\n<p>Output &amp;= vbCrLf &amp; &#8220;CPU Speed: &#8221; &amp; objVirtualServer.HostInfo.ProcessorSpeedString<\/p>\n<p>Return Output<\/p>\n<p>End Function<\/p>\n<p>End Class<\/p>\n<p>End Namespace<\/p><\/blockquote>\n<p><strong>Listing 2: Getting Virtual Server Host Info using VB.NET<\/strong><\/p>\n<blockquote><p>using Microsoft.VirtualServer.Interop;<\/p>\n<p>namespace SearchServerVirtualization_CSharp<\/p>\n<p>{<\/p>\n<p>namespace ScriptingVirtualServer<\/p>\n<p>{<\/p>\n<p>public class Listing_3<\/p>\n<p>{<\/p>\n<p>public static string GetHostInfo()<\/p>\n<p>{<\/p>\n<p>VMVirtualServer objVirtualServer = new VMVirtualServer();<\/p>\n<p>string Output = &#8220;&#8221;;<\/p>\n<p>Output = &#8220;Uptime (sec): &#8221; + objVirtualServer.UpTime.ToString();<\/p>\n<p>Output += &#8220;\\r\\n&#8221; + &#8220;Host OS: &#8221; + objVirtualServer.HostInfo.OperatingSystem.ToString();<\/p>\n<p>Output += &#8220;\\r\\n&#8221; + &#8220;# of CPUs: &#8221; + objVirtualServer.HostInfo.PhysicalProcessorCount.ToString();<\/p>\n<p>Output += &#8220;\\r\\n&#8221; + &#8220;CPU Speed: &#8221; + objVirtualServer.HostInfo.ProcessorSpeedString;<\/p>\n<p>return Output;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p><\/blockquote>\n<p><strong>Listing 3: Getting Virtual Server Host Info using C#<\/strong><\/p>\n<h2>Coming up next\u2026<\/h2>\n<p>Covering details of the Virtual Server object paves the way for the focus of my next article: creating and managing virtual machines. Stay tuned!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article was first published on SearchServerVirtualization.TechTarget.com. In the first two articles in this series on \u201cAutomating Virtual Server\u201d, I presented details on connecting to an instance of Virtual Server using its COM API. The first focused on accomplishing this using VBScript, and the second focused on using .NET (Visual Basic .NET and C#). The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,23],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-vm-automating-scripting","category-microsoft-virtual-server"],"_links":{"self":[{"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":1,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":688,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions\/688"}],"wp:attachment":[{"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anildesai.net\/index.php\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}