Chapter 11 - Working with the Command-Line Tool and Scripts

This chapter shows you how to use scripting to automate a variety of cluster administrative tasks, such as setting members offline, changing load distribution, and deploying applications. The two key supporting technologies that we'll cover in the chapter are the Microsoft Windows Script Host (WSH) and the Microsoft Application Center 2000 (Application Center) command-line tool, both of which are used extensively. These technologies, used separately, or in combination, enable you to manage clusters, work with applications, and work with components.

On This Page

Windows Script Host
The Command-Line Tool: Overview and Reference
Command-Line Example: Setting Up a Staging Environment
Script Samples
Resources

Windows Script Host

Bb734904.spacer(en-us,TechNet.10).gif Bb734904.spacer(en-us,TechNet.10).gif

The Windows Script Host (WSH) is a scripting host for 32-bit Windows operating system platforms that supports several scripting engines, notably the Microsoft Visual Basic script and Java script engines. You can run WSH from either the command shell-based host by using Cscript.exe, or the Windows-based host by using Wscript.exe.

With its support for the Microsoft ActiveX scripting architecture, WSH extends the Windows 2000 command shell and lets you create robust scripts that you can execute directly on the Windows desktop or command console without having to embed scripts in an HTML document via common scripting languages such as Microsoft Jscript development software and Visual Basic Scripting Edition (VBScript).

Note The script action consumer in Microsoft Health Monitor 2.1 does not support the WSH object model, so you can't call WSH scripts as script actions in Health Monitor. In order to use WSH scripts, you need to create a command-line action for Cscript.exe, and then pass in the script file as the first command-line parameter.

WSH Architectural Overview

In the same manner as Microsoft Internet Explorer, WSH serves as a controller of ActiveX scripting engines. Because the scripting host is not a full Internet browser, it has smaller memory demands than the browser and is appropriate for performing simple, quick tasks.

The scripting host reads and passes the specified script file contents to the registered script engine by using the IActiveScriptParse::ParseScriptText method provided by the script engine. Figure 11.1 provides a high-level view of the WSH architecture and illustrates how scripts are processed.

Bb734904.f11uj01(en-us,TechNet.10).gif

Figure 11.1 WSH architecture and execution flow 

The scripting engine does not use the SCRIPT tag, which is used in HTML; instead, it relies on the file name extension to identify which script engine to use. Therefore, you don't have to know the exact ProgID of various script engines. The scripting host maintains a mapping of the script extensions to ProgIDs and uses the Windows association model to launch the appropriate engine.

Note For more information on file extension registration, see the Windows Script Host Object Model at https://msdn.microsoft.com/scripting/default.htm?/scripting/windowshost/doc/wsAboutWSH20.htm.

Running Scripts By Using the Command-Based Scripting Host

You can run the command line version of the script host by entering the following information at the command prompt.

CScript script_name //host_parameters /script_parameters

Where

  • The value for script_name is the name for the script file. 

  • The value for host_parameters is command line switches that are used to enable or disable various WSH options. The host_parameters are always preceded by two slash marks (//). 

  • The value for script_parameters is switches that are passed to the script. The script_parameters are always preceded by a one slash mark (/). 

Each parameter is optional, but you can't specify script-parameters without specifying a script. If you do not specify parameters, Cscript.exe displays the Cscript.exe syntax and the valid host parameters that you can use.

Cscript.exe supports the host parameters described in Table 11.1.

Table 11.1 Command Line Options 

Option

Description

//B

Specifies batch mode, which will not display alerts, scripting errors, and input prompts.

//D 

Enables active debugging.

//E: engine 

Use the specified engine (the value for engine) for executing script.

//H:CScript 

Changes the default script host to CScript.exe.

//H:WScript 

Changes the default script host to WScript.exe, which is the default.

//I

Specifies interactive mode, which displays alerts, scripting errors, and input prompts. This is the default and the opposite of //B.

//Job: xxxx 

Run the specified job (the value for xxx).

//Logo

Display an execution banner at execution time (the default, opposite of //NoLogo).

//Nologo

Prevent logo display; no banner will be shown at execution time.

//S

Save the current command line options for this user.

//T:nn 

Specifies the maximum time the script can run in seconds (the value for nn). You can specify up to 32,767 seconds. The default is no time limit.

//X 

Execute the script in the debugger.

//U

Use Unicode for redirected I/O from the console.

The following example shows a valid script host command:

C:\>cscript //logo %windir%\mysamples\testscript.vbs

Running Scripts by Using the Windows-Based Scripting Host

There are three ways to run scripts under Windows by using the Windows-based script host. You can:

  • Double-click files and icons in the My Computer, Explorer, and Find windows. 

  • Use the Windows Run command, and then type the full name of the script to be executed. 

  • Use the Windows Run command to run Wscript.exe and specify the script name and optional parameters. 

Note You can use the Windows Run command to specify which host application, Cscript.exe or Wscript.exe, is used by default by Cscript with the //H: script_hostname parameter. For example, if you set Wscript.exe as the default, this host will be used when you specify any files that have the .vbs extension.

The Windows Script Host Properties dialog box provides the options listed in Table 11.2. You can access this dialog box by entering wscript from the command line.

Table 11.2 WSH Properties and Options 

Property

Use to...

Cscript.exe equivalent

Stop script after nn seconds

Specify a maximum number of seconds that a script may run. (The default is no limit.)

//T:nn

Display the logo when scripts are executed in a command console.

Display an execution banner at execution time. (The default is the opposite of //NoLogo.)

//logo or //nologo

The .wsh File

In addition to setting global scripting options for all the scripts that are executed on the local computer, you have the ability to set script properties on a per-script basis. By creating a .wsh file for a script, you can specify script settings that give you control over how a specific script will execute. (A .wsh file contains custom script settings and is similar to a .pif file for 16-bit applications.) Because you can create several versions of a script .wsh file, you can manage how different users within your organization use your scripts.

What Is Stored in a .wsh File?

A .wsh file is a text file that has a format similar to that of an .inf file. The following example shows the contents of a .wsh file:

[ScriptFile]
Path=C:\WINNT\Samples\WSH\showprop.vbs
[Options]
Timeout=0
DisplayLogo=1
BatchMode=0

The Path setting in the [ScriptFile] section points to the script file that this .wsh file affects. The settings found under the [Options] section correspond to settings on the Script tab in the Windows Script Host Properties dialog box.

Creating a .wsh File

In order to set per-script properties and create a .wsh file, simply right-click the script file (.vbs or .js) within Explorer, and then choose Properties. Set specific script properties, such as the amount of seconds the script should execute, and then choose OK. You will notice that a .wsh file is created in the same directory as the original script and is created by using the same name as the original script.

Using a .wsh File

To use a .wsh file, in Explorer, double-click the .wsh file icon or at a Windows command prompt, use Cscript.exe or Wscript.exe to execute that script. For example:

C:\> cscript Myscript.wsh 

When you double-click the .wsh file or execute the .wsh from the command line, the appropriate engine (Cscript.exe or Wscript.exe) reads the .wsh file to determine the script settings that should be used to execute the script. Cscript and Wscript execute the original script, passing in the properties that are defined within the .wsh file.

Note You must have the original script file present when executing the .wsh file. If the .wsh file fails to execute the script, check the Path= entry in the .wsh file to ensure that it is pointing to the correct script that you are attempting to run.

The .wsf File

The Windows script file (.wsf) is a text document containing XML code that incorporates several features that provide increased scripting flexibility. Because Windows script files are not engine-specific, they can contain script from any ActiveX-compliant scripting engine.

With .wsf files, you can take advantage of the following benefits as you create your scripts:

  • Support for Include statements—allows you to incorporate previously written functions from VBScript or JScript files into your WSH project. 

  • Support for multiple engines—allows you to use more than one scripting language in each file—for example, VBScript and Perl. 

  • Support for Type libraries—allows you to use constants in your scripts. 

  • Support for tools—allows you to edit files with any XML editor. 

  • Support for multiple jobs in one file—allows you to store all of your script code in a single location. 

These benefits are described in more detail in the following excerpt from the WSH online documentation that is available at the Windows Script Technologies Web site:

https://msdn.microsoft.com/library/en-us/script56/html/vtoriMicrosoftWindowsScriptTechnologies.asp.

Include Statements

If you have .js and .vbs files from previous WSH projects, a .wsf file enables you to use them with WSH. A .wsf file encapsulates a library of functions that can in turn be used by multiple .wsf files.

The following example shows the contents of a .wsf file that includes a JScript file (Fso.js), plus a VBScript function that calls a function (GetFreeSpace) in the included file. The contents of Fso.js are also provided.

<Job id="IncludeExample">
<Script language="JScript" src="FS0.JS"/>
<Script language="VBScript">
' Get the free space for drive C.
s = GetFreeSpace("C:")
WScript.Echo s
</Script>
</Job>

The contents of Fso.js are:

function GetFreeSpace(drvPath) {
var fs, d, s;
fs = new ActiveXObject("Scripting.FileSystemObject");
d = fs.GetDrive(fs.GetDriveName(drvPath));
s = "Drive " + drvPath + " – ";
s += d.VolumeName;
s += "Free Space: " + d.FreeSpace/1024 + "Kbytes";
return s;
}
Multiple Engine Support

Because one scripting language might not provide all of the functionality you need, WSH allows you to combine multiple languages in a single .wsf file. The following example shows the contents of a .wsf file that includes both VBScript and Perl script code:

<job id="PERLandVBS">
<script language=PerlScript RUNAT=Server>
sub PerlHello
{
my $str = @_[0];
$Wscript ->Echo($str);
}
</script>
<script language="VBScript">
Wscript.Echo "Hello from VBScript"
PerlHello "Hello from PERLScript"
</Script>
</Job>
Type Library Support

In the following example, MyComponent was developed with Visual Basic version 5.0. MyComponent defines the constant MyError with the following statement:

Public Const MyError = "You are not using MyComponent correctly."

The type library is contained in Mycomponent.lib, which you have installed in C:\MyComponent.

<JobId="IncludeExample">
<Reference progid="MyComponent.MyClass">
<Script language="VBSCript">
Dim MyVar
Set MyVar = CreateObject("MyComponent.MyClass">
Currentreturn = MyVar.MyMethod
If Currentreturn= False then
Wscript.Echo MyError
End If
</Script>
</Job>
Tools Support

Because .wsf files are in XML format, you can use any editor that supports XML to edit .wsf files. You can also use any text editor, such as Notepad.

Multiple Jobs in One File

Instead of keeping all of your scripts in separate files, you can incorporate them into one .wsf file, and then organize them into several different jobs. You can then run each job separately by using syntax similar to the following example, where MyFirstJob is the name of the job contained in the MyScripts.wsf file:

Cscript //Job:MyFirstJob MyScripts.wsf

The Command-Line Tool: Overview and Reference

Bb734904.spacer(en-us,TechNet.10).gif Bb734904.spacer(en-us,TechNet.10).gif

The Application Center command-line tool supports automated administration and management of Application Center by providing commands that can be executed from the command line or from within a script or batch file.

The command-line tool is implemented in the form of an executable file named AC.EXE. Because the Application Center Setup program adds the program path to the Application Center installation directory, which is in the operating system path, you can execute the command-line tool from any directory. AC.EXE can be executed locally on any computer that has Application Center installed.

Warning If you run AC.EXE locally with the /USER and /PASSWORD parameters, command execution will fail when running commands for the local server. You can only supply credentials when you're administering remote servers.

The command-line tool supports remote execution by allowing you to provide the appropriate security credentials for executing commands against other cluster members. This capability is not limited to full installations of Application Center but extends to Administrative client-only installations as well.

Note If security credentials are not supplied in the remote case, the command-line tool defaults to the current logon information when possible.

Command Overview

The command-line tool supports the following commands:

  • CLUSTER—enables you to manage a cluster by providing parameters that let you perform tasks such as create or disband a cluster, add and remove cluster members, and list all cluster members. 

  • LOADBALANCE—enables you to manage Network Load Balancing (NLB) on a cluster by providing parameters that let you perform tasks such as enable or disable load balancing for a cluster member, drain server connections, set NLB weights for a member, and obtain load-balancing related status information. 

  • CLB—enables you to manage Component Load Balancing (CLB) on a cluster by providing parameters that let you perform tasks such as create a CLB routing list on the controller of a Web/COM+ routing cluster, add or remove entries in the routing list, and obtain routing list information. 

  • DEPLOY—enables you to manage application deployment and synchronization on a cluster by providing parameters that let you perform tasks such as deploy an application, specify deployment targets, set deployment options, enable/disable synchronization on cluster members, and obtain deployment status information. 

  • APPLICATION—enables you to manage applications on a cluster by providing parameters that let you perform tasks such as create applications, identify application resources (which allows you to create or delete an application on a cluster or member), list applications, and add or remove resources from an application. 

  • HELP—provides descriptions of the available command-line tool commands and their syntax. 

General Syntax Rules

The Application Center command-line tool syntax is similar to the NET command syntax, and has the following syntax rules:

  • Capital letters represent words that must be typed as shown. Lowercase letters represent names of items that may vary, such as server names. 

  • Brackets ([ and ]) enclose optional items that can be supplied with the command. 

  • Braces ({ and }) enclose lists of items where you must supply at least one of the items with the command. 

  • The vertical bar (|) separates items in a list. Only one of the items can be supplied with the command. 

  • Ellipsis within brackets ([...]) mean that you can repeat the previous item. Separate items with spaces. 

  • A comma (,) or semi-colon (;) followed by an ellipsis enclosed within brackets([…]) mean that you can repeat the previous item, but you must use the punctuation shown before the ellipsis, not spaces, to separate items. 

  • When typed at the command prompt, names of two words or more must be enclosed in quotation marks. 

Command-line execution times 

Several of the Application Center commands can take longer than expected to complete. The following list provides an estimate for the length of time that certain commands may take to complete.

Timeout

Commands for

35 minutes

Create cluster and add member.

20 minutes

Disband cluster, clean cluster, and remove member.

Command-Line Execution Confirmation

Several of the Application Center commands that have a high impact on cluster operations require execution confirmation. When these commands are used, you will be prompted for additional input to confirm the execution of the specified command. In this case you will see the following prompt:

"Are you sure (Y/N)?"

You can bypass the confirmation dialog box by specifying the /Y parameter with the command. When this parameter is used, the command will execute as if you had answered "Y" to the prompt. This parameter only has to be used once for the command, even if the command produces more than one confirmation prompt.

Warning The execution confirmation prompt is implemented as a safety mechanism for commands whose result might directly impact the cluster. You should be careful when using this parameter on commands, because it might have an impact on the cluster in ways that you did not intend.

Command Reference

The following reference information provides usage information, parameter descriptions, and examples for each of the commands supported by AC.EXE.

Note The examples that are provided use the test clusters and members that were described in Chapter 8, "Creating Clusters and Deploying Applications."

Command: AC HELP

The HELP command provides the user with a description of the available Application Center commands, syntax, and usage. HELP covers the following commands:

  • LOADBALANCE 

  • DEPLOY 

  • CLUSTER 

  • CLB 

  • APPLICATION 

Usage

The first form of the HELP command provides general information about the available help commands:

AC HELP

The second form of the HELP command provides information about the specified command:

AC HELP [command]

Alternatively, you can use the following syntax to access specific help information about a command:

AC [command] /?
-or-
AC [command] /HELP
Parameters

Table 11.3 HELP Parameters 

Parameter

Description

command

Contains the name of the command that the user requires additional information about.

Examples

The following line shows how you would obtain help for the DEPLOY command:

AC HELP DEPLOY or AC DEPLOY /?

Note If the command parameter is not specified, a listing of available commands and the basic syntax for the commands is displayed.

Command: AC LOADBALANCE

The AC LOADBALANCE command enables you to manage load balancing for a cluster by supporting the following activities:

  • Enabling or disabling load balancing for a cluster member. As a result of the preceding action the member is either online or offline for load balancing. 

  • Setting the NLB weights for a cluster member. 

  • Draining active connections to the member. 

  • Obtaining NLB-related status information. 

Usage
AC LOADBALANCE /ONLINE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
AC LOADBALANCE /ONLINE
/MEMBERONLY
AC LOADBALANCE /OFFLINE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
[/DRAIN:time]
AC LOADBALANCE /OFFLINE 
/MEMBERONLY
[/DRAIN:time]
AC LOADBALANCE /SETNLBWEIGHT:weight
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
AC LOADBALANCE /STATUS [:All]
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
Parameters

Table 11.4 LOADBALANCE Parameters 

Parameter

Description

/ONLINE

Enables load balancing for the specified cluster member. This does not affect the member's state if it is already in the enabled state. This functionality is available for NLB and CLB clusters only, by default.

/MEMBER:member_name

Specifies the cluster member on which to apply the specified action. If omitted, the local member is assumed.

/USER:username

Specifies the user name to use for authentication, which can be supplied as "domain\username".

/PASSWORD:password

Specifies the password to use for authentication.

/MEMBERONLY

Sets the server:
· Online from a suspended state.
· Offline to a suspended state.
Note When this parameter is used, the LOADBALANCE command must be executed locally. Specifying the /MEMBER parameter in addition to the /MEMBERONLY parameter will result in an error.

/OFFLINE

Disables load balancing for the specified cluster member. This does not affect the member's state if it is already in the disabled state. Connections will not be drained from the member unless the /DRAIN parameter is specified. This functionality is available for NLB and CLB clusters only, by default.

/DRAIN:time

Drains the specified cluster member of connections. The value given indicates, in minutes, the timeout value for draining connections. If you do not specify time, the default time specified in the cluster properties is used. If you specify zero, no draining will occur (the same effect as if /OFFLINE was specified without /DRAIN).

/SETNLBWEIGHT:weight

Sets the relative weight of an NLB cluster member. Valid values are from 0 through 100. (Note that these values do not represent percentages.) This functionality is available for NLB clusters only.

/STATUS

Provides load-balancing status information for the specified cluster member. If you specify [:All], status is provided for all cluster members. This functionality is available for NLB and CLB clusters only, by default.

Note If NLB or CLB isn't implemented on a cluster, the /ONLINE, /OFFLINE, and /STATUS parameters only work with the load-balancing devices that are documented in Chapter 13, "Third-Party Load Balancer Support."

Examples

The following example shows how you would set the NLB weight of server1 to 60.

AC LOADBALANCE /SETNLBWEIGHT:60 /MEMBER:server1

The next example shows how a user, working on a remote server, can retrieve status information for any cluster member. Whenever you submit a request from a server outside of the cluster, you have to explicitly provide credentials or the wildcard character, the asterisk (*), shown in our example. In this particular case, a prompt is displayed in response to the wildcard.

AC LOADBALANCE /STATUS:All /MEMBER:server1 /username:user1 /password:*
Command: AC DEPLOY

The AC DEPLOY command lets you perform several application deployment tasks on a cluster. You can deploy applications from a cluster controller or a cluster member. AC DEPLOY supports the following activities:

  • Deploying Application Center applications within a cluster or from outside the cluster, as in the case of stagers. 

  • Listing deployments. 

  • Synchronizing an entire cluster or specific member(s). 

  • Enabling or disabling automatic synchronization for specific cluster members. 

  • Terminating a deployment job. 

Usage

The following lines show different ways of using the DEPLOY command with parameters:

AC DEPLOY /START
[/DEPNAME:depname]
[/SOURCE:sourcename
/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
[/TARGETS:targetname1[,...]
/TARGETUSER:username /TARGETPASSWORD:*|pwd]
[/APPNAME:appname1[,...] | /APPGUID:appguid1[,...]]
[/NOACL]
[/COMPLUS]
[/WAIT] 
AC DEPLOY /LISTDEPLOYMENTS
[/SOURCE:sourcename]
[/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
AC DEPLOY /TERMINATE
{/JOBID:jobid | /DEPNAME:depname}

Note You should specify /JOBID or /DEPNAME, but not both.

[/SOURCE:sourcename
/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
AC DEPLOY /ENABLESYNC
[/SOURCE:sourcename
/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
AC DEPLOY /DISABLESYNC
[/SOURCE:sourcename
/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
AC DEPLOY /STATUS[:All]
[/SOURCE:sourcename
/SOURCEUSER:username /SOURCEPASSWORD:*|pwd]
Parameters

Table 11.5 DEPLOY Parameters 

Parameter

Description

/START

Starts the deployment job.

/DEPNAME:depname

Specifies a friendly name for the deployment.

/SOURCE:sourcename

Specifies the source (the cluster controller or cluster member) for deployment. Also specifies the member on which to enable or disable automatic synchronization or obtain status. If you want to authenticate on the source computer, use the /SOURCEUSER and /SOURCEPASSWORD options with /SOURCE. If omitted, the source is assumed to be the local computer.

/SOURCEUSER:username

Specifies the user name to use for credentials when authenticating on the source computer, which can be supplied as "domain\username".

/SOURCEPASSWORD:*|pwd

Specifies the password to use for credentials when authenticating on the source computer.

/TARGETS:targetname1[,...]

Specifies a list of targets on which to deploy the specified applications.
Note If this parameter is omitted, the application will be deployed to the members of the source cluster.

/TARGETUSER:username

Specifies the user name to use for credentials when authenticating on the target computer, which can be supplied as "domain\username".

/TARGETPASSWORD:*|pwd

Specifies the password to use for credentials when authenticating on the target computer.

/APPNAME:appname1[,...]

Specifies a list of applications to deploy (by application name). If no applications are specified, the command will deploy all applications from the source.

/APPGUID:appguid1[,...]

Specifies a list of applications to deploy (by application GUID). If no applications are specified, the command will deploy all applications from the source.

/NOACL

Specifies that Access Control Lists (ACLs) should not be deployed. ACLs are deployed by default.
Note ACLs are not deployed on partitions that do not support ACLs (for example, FAT), or in nondomain configurations.

/COMPLUS

Specifies that COM+ applications should be deployed as part of the deployment job.

/WAIT

Indicates that the deployment should happen synchronously; that is, the command should not return until the deployment is complete. The default behavior happens asynchronously; that is, the command returns immediately.

/LISTDEPLOYMENTS

Lists the current ongoing deployment jobs and their identifiers, which have been started on the source computer.

/TERMINATE

Terminates the deployment job. This parameter requires execution confirmation.

/JOBID:jobid

Specifies the job identifier of the deployment job to terminate. This parameter requires execution confirmation.

/ENABLESYNC

Turns on synchronization for the specified cluster member. This places it in the synchronization loop. This parameter is not allowed if the cluster controller is specified as the source.

/DISABLESYNC

Turns off synchronization for the specified cluster member, taking it out of the synchronization loop. This parameter is not allowed if the cluster controller is specified as the source. This parameter requires execution confirmation.

/STATUS[:All]

Displays the current deployment-related status information. If :All is specified, status is given for all members.

Examples

The following example shows how to deploy applications app1, app2, and app3 from controller0 to server1 and server2.

AC DEPLOY /START /SOURCE:controller0 /TARGETS:server1,server2 
/APPNAME:app1,app2,app3 /SOURCEUSER:dba018 /SOURCEPASSWORD:********
/TARGETUSER:dba018 /TARGETPASSWORD:**********

Remember, if you enter an asterisk (*), rather than a password for the SOURCEPASSWORD and TARGETPASSWORD, the command-line tool will prompt you for both passwords and validate this information before executing the entire command string.

Command: AC CLUSTER

The AC CLUSTER command provides several parameters that enable you to manage a cluster. This command supports:

  • Creating a cluster. 

  • Disbanding a cluster. 

  • Changing the cluster controller. 

  • Adding or removing a member from a cluster. 

  • Listing the cluster members. 

  • Listing the network adapters on a computer that can be used for load balancing. 

  • Removing all of the Application Center cluster settings from a computer. 

Usage

Note Different usages are shown for the /CREATE, /ADD, and /REMOVE parameters. Following each parameter are instructions on how to use the parameter.

AC CLUSTER /CREATE
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:web | complusrouting
/LOADBALANCING:nlb
/CLUSTERIP:cluster_ip
/CLUSTERIPSUBNETMASK:ip_subnetmask
[/DEDICATEDIP:dedicated_ip
/DEDICATEDIPSUBNETMASK:ded_subnetmask]
[/AFFINITY:single | class_C | none]
/LBNIC:nic_id
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a Web or COM+ routing cluster with NLB and a clean installation.

AC CLUSTER /CREATE
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:web | complusrouting
/LOADBALANCING:nlb
/KEEPNLBSETTINGS
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a Web or COM+ routing cluster with NLB when upgrading NLB.

AC CLUSTER /CREATE 
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:web | complusrouting
/LOADBALANCING:other
[/LBNIC:nic_id]
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a Web or COM+ routing cluster when using a load-balancing method other than NLB.

AC CLUSTER /CREATE 
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:web | complusrouting
/LOADBALANCING:none
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a Web or COM+ routing cluster with no load balancing.

AC CLUSTER /CREATE 
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:complusapp
/LOADBALANCING:clb
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a COM+ application cluster when using CLB.

AC CLUSTER /CREATE 
[/CONTROLLER:controller_name]
[/USER:username /PASSWORD:password]
/NAME:cluster_name
[/DESCRIPTION:cluster_desc]
/TYPE:complusapp
/LOADBALANCING:nlb
/CLUSTERIP:cluster_ip
/CLUSTERIPSUBNETMASK:ip_subnetmask
[/DEDICATEDIP:dedicated_ip 
/DEDICATEDIPSUBNETMASK:ded_subnetmask]
/LBNIC:nic_id
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters for a COM+ application cluster with NLB and a clean installation.

AC CLUSTER /DELETE
/CONTROLLER:controller_name
[/USER:username /PASSWORD:password]
AC CLUSTER /ADD
/CONTROLLER:controller_name
[/MEMBER:member_name] 
/USER:username /PASSWORD:password | *
[/DEDICATEDIP:dedicated_ip
/DEDICATEDIPSUBNETMASK:ded_subnetmask]
[/NOSYNCONADD]
[/DISABLELOADBALANCING]
[/LBNIC:nic_id]
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters only when adding a new member to a cluster that is using NLB.

AC CLUSTER /ADD
/CONTROLLER:controller
[/MEMBER:member_name] 
/USER:username /PASSWORD:password | *
[/NOSYNCONADD]
[/DISABLELOADBALANCING]
[/LBNIC:nic_id]
/MANAGEMENTNIC:nic_id

Use the preceding set of parameters only when adding a new member to a cluster that is using CLB or a load-balancing method other than NLB.

AC CLUSTER /ADD
/CONTROLLER:controller_name
[/MEMBER:member_name]
/USER:username /PASSWORD:password | *
[/NOSYNCONADD]
[/DISABLELOADBALANCING]
/MANAGEMENTNIC:nic_id

The preceding set of parameters only applies when adding a new member to a cluster with no load balancing.

AC CLUSTER /REMOVE
[/MEMBER:member_name]
/USER:username /PASSWORD:password | *
AC CLUSTER /REMOVE
/MEMBER:member_name
/CONTROLLER:controller_name
/USER:username /PASSWORD:password | *

Use the preceding set of parameters to remove a cluster member that does not have Application Center installed or to remove a cluster member that cannot be reached.

AC CLUSTER /SETCONTROLLER
[/MEMBER:member_name]
[/USER:username /PASSWORD:password | *] 
[/FORCE]
AC CLUSTER /CLEAN
[/KEEPIPS]
AC CLUSTER /LISTMEMBERS
[/MEMBER:member_name]
[/USER:username /PASSWORD:password | *]
AC CLUSTER /LISTNICS
[/COMPUTER:computer_name]
[/USER:username /PASSWORD:password | *]
Parameters

Table 11.6 CLUSTER Parameters 

Parameter

Description

/CREATE

Create a new cluster

/CONTROLLER:controller_name

Specifies the computer to be used as the cluster controller.

/USER:username

Specifies the user name to use for authentication, which can be supplied as "domain\username".

/PASSWORD:password

Specifies the password to use for authentication.

/NAME:cluster_name

Specifies a friendly name for the cluster that will be created.

/DESCRIPTION:cluster_desc

Provides a text description of the cluster.

/TYPE:web | complusapp | complus-routing

Specifies one of three cluster types to create:
· web: a Web cluster.
· complusrouting: a COM+ routing cluster.
· complusapp: a COM+ application cluster.

/LOADBALANCING:NLB | clb | other | none

Specifies which type of load balancing to use for the cluster:
· nlb: Network Load Balancing.
· clb: Component Load Balancing, which is valid for a COM+ application cluster only.
· other: third-party load balancing.
· none: no load balancing supported.

/CLUSTERIP:cluster_ip

Specifies the cluster (shared or virtual) IP address. This parameter is valid only for NLB clusters.

/CLUSTERIPSUBNETMASK: ip_subnetmask

Specifies the subnet mask of the cluster IP address.

/DEDICATEDIP:dedicated_ip

Specifies the dedicated IP address of the cluster controller. This parameter is valid only for NLB clusters.

/DEDICATEDSUBNETMASK: ded_subnetmask

Specifies the dedicated subnet mask of the cluster controller. This parameter is valid only for NLB clusters.

/AFFINITY:single | class_c | none

Specifies the NLB affinity of the cluster. This parameter is valid only for NLB clusters.

/KEEPNLBSETTINGS

Indicates that an NLB upgrade should be performed and to maintain existing NLB settings. This is valid only if the load balancing type is NLB, the cluster type is not complusapp, and NLB is already being used on the computer on which the cluster is being created.

/MANAGEMENTNIC:nic_id

Specifies the instance number of the management network adapter to use on the computer. This identifier can be obtained by executing the command AC CLUSTER /LISTNICS.

/LBNIC:nic_id

Specifies the instance number of the load balancing network adapter to use on the computer. This identifier can be obtained by using /LISTNICS.

/DELETE

Disband a cluster.

/ADD

Adds the given computer to the cluster. Once the computer is added to the cluster, it will be synchronized with the cluster controller unless /NOSYNCONADD is specified. Note that a different set of options applies depending on whether you are adding a member to an NLB cluster or a non-NLB cluster.

/MEMBER:member_name

Specifies a cluster member. If omitted, the local computer is assumed.

/NOSYNCONADD

Specifies that once a member is added to a cluster, it should not be synchronized with the controller.

/DISABLELOADBALANCING

Specifies that the newly added member should not be set online once it is added to the cluster.

/REMOVE

Specifies that a member should be removed from the cluster it currently belongs to.
Note Two sets of syntax are shown for use with /REMOVE. Use the second set to remove a cluster member that does not have Application Center installed. You can also use the second set of syntax to remove a member that cannot be reached; in that case, the message "Some settings in the member could not be removed" may be displayed. Use AC CLUSTER /CLEAN to remove these settings from the removed member.

/FORCE

Specifies that a controller change should be forced even if the existing controller is not available. This flag must be used in conjunction with /SETCONTROLLER.

/SETCONTROLLER

Specifies that the member identified by /MEMBER should be promoted to cluster controller for the cluster to which it currently belongs.

/CLEAN

Specifies that all cluster information should be removed from the local computer. Use this option on computers that are no longer part of a cluster. If the computer on which you want to use /CLEAN is part of cluster, first use AC CLUSTER /REMOVE to remove the member from the cluster. You can also use this command to remove a cluster member while the controller is unavailable. The parameter is available locally only and cannot be executed remotely. This parameter requires execution confirmation.

/KEEPIPS

Indicates that when cleaning a computer the cluster IP addresses should not be removed. You can only use this parameter with NLB clusters. Use this parameter only on the cluster controller (when it is the last member in the cluster) or it may result in IP address conflicts.

/LISTMEMBERS

Displays a list of all cluster members in the cluster containing the specified member. When you execute the AC CLUSTER command with /LISTMEMBERS, you receive the following output:
· Server name.
· Online status, which can be online, offline, or UNKNOWN
· Drain status, which can be draining, blank (if the server is not draining), or UNKNOWN.
· Alive status, which can be alive, dead, or UNKNOWN.
· Synchronization status, which can be replicating, blank (if synchronization is not taking place on the computer), or UNKNOWN.
· Member status, which can be controller, blank (if the computer is a member rather than a controller), or UNKNOWN.
Column headings are not shown in the output. If there are any ambiguities (because of blank or UNKNOWN values), use the order specified in the preceding list to ascertain which status values correspond to which properties.

/LISTNICS

Displays a list of all network adapters on the computer that can be used for load balancing or management traffic.
Note The following sample output identifies, in bold type, the location of the network adapter id:
Network adapters on <machine>
0: [00000000] <description>
1: [00000001] <description>

/COMPUTER:computer_name

Specifies a computer name to use for listing network adapter information. If this parameter is omitted, the local computer is used.

Examples

The following example shows how to designate server2 as the new controller for the cluster RKWebCluster.

AC CLUSTER /SETCONTROLLER /MEMBER:server2
Command: AC CLB

The AC CLB command enables you to work with the CLB routing list on a Web or COM+ routing cluster. By using this command with parameters you can:

  • Set the CLB routing list on the cluster controller. 

  • Add members to or remove members from the CLB routing list. 

  • Load all of the cluster members in which a specified member exists to the CLB routing list for a specified cluster. 

  • List all the servers in a CLB routing list. 

Usage
AC CLB /SETCLBMEMBERS
[/ROUTINGMEMBER:routing_member]
[/ROUTINGUSER:username /ROUTINGPASSWORD:*|pwd]
/COMPLUSMEMBERS:member[,...]
AC CLB /LOADCLBMEMBERS
[/ROUTINGMEMBER:routing_member]
[/ROUTINGUSER:username /ROUTINGPASSWORD:*|pwd]
/COMPLUSMEMBER:clbmember
[/COMPLUSUSER:username /COMPLUSPASSWORD:*|pwd]
AC CLB /ADDCLBMEMBER
[/ROUTINGMEMBER:routing_member]
[/ROUTINGUSER:username /ROUTINGPASSWORD:*|pwd]
/COMPLUSMEMBER:clbmember
AC CLB /REMOVECLBMEMBER
[/ROUTINGMEMBER:routing_member]
[/ROUTINGUSER:username /ROUTINGPASSWORD:*|pwd]
/COMPLUSMEMBER:clbmember
AC CLB /LISTCLBMEMBERS
[/ROUTINGMEMBER:routing_member]
[/ROUTINGUSER:username /ROUTINGPASSWORD:*|pwd] 
Parameters

Table 11.7 CLB Parameters 

Parameter

Description

/SETCLBMEMBERS

Sets the CLB routing list on the controller of the cluster to which the routing member belongs. The routing list is updated with a list of members specified by /COMPLUSMEMBERS. No verification is performed in the list specified by /COMPLUSMEMBERS.

/LISTCLBMEMBERS

Lists all of the members contained in the CLB routing list.

/ROUTINGMEMBER: routing_member

Specifies the name of a member in the COM+ routing cluster. If not specified, routing_member is assumed to be the local computer.

/ROUTINGUSER: username

Specifies the user name to use for credentials when authenticating on the routing cluster.

/ROUTINGPASSWORD: *|pwd

Specifies the password to use for credentials when authenticating on the routing cluster.

/COMPLUSMEMBERS:member[,...]

Specifies the COM+ application cluster members used in the CLB routing list.

/LOADCLBMEMBERS

Loads all the members of the cluster that /CLBMEMBER is in to the routing list for the cluster that /ROUTINGMEMBER is a member of.

/COMPLUSMEMBER: clbmember

Specifies a member of the COM+ application cluster.

/COMPLUSUSER: username

Specifies the user name to use for credentials when authenticating on a COM+ application cluster.

/COMPLUSPASSWORD: *|pwd

Specifies the password to use for credentials when authenticating on the back-end COM+ application cluster.

/ADDCLBMEMBER

Specifies that the clbmember should be added to the routing list on the controller of the cluster to which the routing member belongs.

/REMOVECLBMEMBER

Specifies that the clbmember should be removed from the CLB routing list on the controller of the cluster to which the routing member belongs.

Examples

The following example shows how you can retrieve a list of members contained in the CLB routing list. Additionally, the example shows how to provide a user name for authentication and request a prompt to enter a password:

AC CLB /LISTCLBMEMBERS /ROUTINGMEMBER:machine1 /ROUTINGUSER:user1 
/ROUTINGPASSWORD:*
Command: AC APPLICATION

The AC APPLICATION command allows you to manage applications on a cluster. An application is defined as a collection of resources and can include:

  • Web sites and certificates. 

  • COM+ applications. 

  • Registry keys. 

  • Files and DSNs. 

The AC APPLICATION command allows you to:

  • Create an application on or delete an application from a cluster or member. 

  • Add resources to or remove resources from an application. 

  • List applications and resources. 

Usage
AC APPLICATION /CREATE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
/NAME:appl_name
[/MEMBERONLY]
AC APPLICATION /DELETE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
{/NAME:appl_name | /GUID:appl_guid}
[/MEMBERONLY]
AC APPLICATION /LIST
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
[/MEMBERONLY]
AC APPLICATION /ADDRESOURCE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
{/NAME:appl_name | /GUID:appl_guid} 
/RESOURCETYPE:resource_type
/RESOURCEPATH:resource_path
[/MEMBERONLY]
AC APPLICATION /REMOVERESOURCE
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
{/NAME:appl_name | /GUID:appl_guid} 
/RESOURCETYPE:resource_type
/RESOURCEPATH:resource_path
[/MEMBERONLY]
AC APPLICATION /LISTRESOURCES
[/MEMBER:member_name]
[/USER:username /PASSWORD:password]
{/NAME:appl_name | /GUID:appl_guid}
[/MEMBERONLY]
Parameters

Table 11.8 APPLICATION Parameters 

Parameter

Description

/CREATE

Specifies that you want to create an application on an existing cluster or member.

/MEMBER:member_name

Specifies a cluster member. If omitted, the local member is assumed.

/USER:username

Specifies the user name to use for authentication, which can be supplied as "domain\username".

/PASSWORD:password

Specifies the password to use for authentication.

/NAME:appl_name

Specifies the name of the application being managed.

/MEMBERONLY

Specifies that the command should be run on the specified member, not on the controller.

/DELETE

Indicates that you want to delete an application on a cluster member.

/GUID:appl_guid

Specifies the GUID of the application being managed.

/LISTRESOURCES

Displays a list of all existing resources for a given application.

/ADDRESOURCE

Indicates that you want to add a single resource to a single application on the controller of the cluster to which the specified member belongs. You must specify the fully qualified path to the resource to add it to the designated application. If /MEMBERONLY is specified, the resource is added only to the specified member, not to the controller.

/RESOURCETYPE:resource_type

Specifies the resource to be added to or removed from the application. The following are valid resource types:
· FileSystem
· IIS
· Registry
· DSN
· COMPlusApp

/RESOURCEPATH:resource_path

Specifies the path to the resource to add to or remove from the application. Paths are specified as follows:
· IIS: the complete metabase path. For example, "/LM/W3SVC/3" or site name ("My Web Site").
· Registry: the complete registry path. For example, "HKEY_CURRENT_USERS \Software \Microsoft Active Setup\{guid}".
· FileSystem: the complete file system path. For example, "C:\Program Files\Misc\ MyResource.txt".
· DSN: the friendly name of the DSN (for example, "My DSN") or unique registry path, such as "My Computer\HKEY_LOCAL _MACHINE\Software\ODBC\ODBC.INI\Name".
· COMPlusApp (COM+ application): the friendly name of the COM+ application or its GUID (CLSID).

/REMOVERESOURCE

Indicates that you want to remove a single resource from a single application on the controller of the cluster to which the member belongs. If /MEMBERONLY is specified, the resource is removed only from the specified member, not from the controller.

Examples

The following example shows how to create an application named gamescentral on all the members for an existing cluster.

AC APPLICATION /CREATE /NAME:gamescentral

The following example shows how to add a Web site resource to the application salesui.

AC APPLICATION /ADDRESOURCE /NAME:salesui /RESOURCETYPE:iis
/RESOURCEPATH:host1/b_svc/2/root/myvirtualdirectory

The following example shows how to remove a file resource from the application salesui.

AC APPLICATION /REMOVERESOURCE /NAME:salesui /RESOURCETYPE:filesystem
/RESOURCEPATH:"c:\Program Files\Resources\MyFile.txt"

Command-Line Example: Setting Up a Staging Environment

Bb734904.spacer(en-us,TechNet.10).gif Bb734904.spacer(en-us,TechNet.10).gif

In this section we'll use the command-line tool to work with the clusters and servers that were described in Chapter 8, "Creating Clusters and Deploying Applications." You'll see how this tool, used in one-off situations, or in batch files, can assist you with various cluster administration tasks. Let's use this scenario for illustrating how the command-line tool works:

  • Create a staging cluster. 

  • Create a new Application Center application. 

  • Deploy the new application to a Web cluster. 

Because we're going to use the environment from Chapter 8 for our scenario, we have to do some cleanup work on the existing environment. This consists of:

  • Disbanding the staging cluster. 

  • Removing the Preflight Check application from the Web cluster. 

Preparation

Let's start our preparation by disbanding the staging cluster, which as you may recall is named RKStager and consists of a single member, ACDW822AS.

  1. Log on to the system as the administrator, and then run the following command to disband the cluster: 

AC CLUSTER /DELETE

After pressing ENTER, you'll get the following prompt: 

"Are you sure (Y/N)?" 
  1. Press Y, and then press ENTER. 

Note Because the existing staging cluster was a cluster of one, consisting of a single member, we don't have to worry about removing individual members first. By the same token, because NLB wasn't enabled, we don't have to worry about retaining IP addresses on the network adapter.

The next steps involve removing the Preflight Check application, ACPFApp, from the Web cluster (RKWebCluster).

  1. After logging onto the controller (ACDW516AS) with administrative privileges, we obtained a list of the current applications by entering the following command at the command prompt: 

AC APPLICATION /LIST

The results of this command are displayed next. 

<pre IsFakePre="true" xmlns="https://www.w3.org/1999/xhtml">

Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. D:\Documents and Settings\rktest>ac application /list AC Command Line Utility V1.0 (c) 2000 Microsoft Corporation Applications on ACDW516AS Name ID ACPFApp {586676A0-8A57-4B2B-B194-D3D304817D2A} Administration Web Site {030BABE5-DE57-4411-9DCE-4FDE6227225A} AllSites {2E3D9AEB-26BD-4F33-8EC4-D6907F0F152D} Application Center 2000 Administrative S {AA6209B3-A402-4967-9AFD-58F7E1F0DD33} Default Web Site {95354A7E-F7FD-4F3A-9A7A-F2A8DC4B107B}

  1. To delete the Preflight Check application from the controller, enter 

AC APPLICATION /DELETE /NAME:ACPFApp

Note Remember, when you delete the application you are only deleting a named resource manifest that exists in the Application Center user interface. The installed COM+ components, source directories, and Web site virtual directories are not removed from the system.

As a final cleanup step, you could force synchronization on the Web cluster, but it's not really required because removing the application triggers synchronization. (In our case, we also removed the COM+ components and ACPF directory on the Web cluster controller to ensure that we had a completely clean target for the test.)

Create the Staging Cluster and Preflight Check Application

Now we'll create a cluster named RKStager on the server that was used as a stager. First, we'll log on to the server with an account that has administrative privileges.

  1. To create the staging cluster, we'll use the following command: 

AC CLUSTER /CREATE /NAME:RKSTAGER /TYPE:WEB /LOADBALANCING:NONE

This command uses the appropriate parameters to create the staging cluster. In this case, because we're logged on the system with administrative privileges and the command-line defaults to **localhost**, we didn't have to provide either authentication information or the machine name to create the cluster. 

Before creating the Preflight application on the stager, verify that the application components that were installed for the Chapter 8 scenarios exist on the server. The server should have:

  - The ACPF source directory 

  - The two COM+ applications (AC\_PF\_VB, AC\_PF\_VC) 

  - The virtual directory (ACPFWeb) defined in the default Web site's root 

**Note** If any of the preceding elements are missing, you can install them by using the instructions provided in the "Automated setup" sidebar in Chapter 8. 

Now we'll create the ACPFApp, and then identify its resources. 
  1. Create the application by entering the following command: 

AC APPLICATION /CREATE /NAME:ACPFApp

  1. Identify the application's virtual directory resource by entering the following command: 

AC APPLICATION /ADDRESOURCE /NAME:ACPFApp /RESOURCETYPE:IIS /RESOURCEPATH:/LM/W3SVC/1/root/ACPFWeb

  1. Identify the application's source directory by entering the following command: 

AC APPLICATION /ADDRESOURCE /NAME:ACPFApp /RESOURCETYPE:FileSystem /RESOURCEPATH:C:\ACPF

  1. Identify the two COM+ applications by entering the following commands: 

AC APPLICATION /ADDRESOURCE /NAME:ACPFApp /RESOURCETYPE:COMPlusApp /RESOURCEPATH:AC_PF_VB AC APPLICATION /ADDRESOURCE /NAME:ACPFApp /RESOURCETYPE:COMPlusApp /RESOURCEPATH:AC_PF_VC

**Tip** Validate the preceding steps by using the following command: 

<pre IsFakePre="true" xmlns="https://www.w3.org/1999/xhtml">

AC APPLICATION /LISTRESOURCES /NAME:ACPFApp

Deploy the Preflight Check Application

At this stage we can deploy the ACPFApp application to the Web cluster. We used the following command:

AC DEPLOY /START /DEPNAME:Preflight /SOURCE:ACDW822AS /SOURCEUSER:ASTTEST 
/SOURCEPASSWORD:* /TARGETS:ACDW516AS /TARGETUSER:ASTTEST /TARGETPASSWORD:* 
/APPNAME:ACPFAPP /COMPLUS /WAIT

Notice that rather than providing a password for the /SOURCEPASSWORD and /TARGETPASSWORD parameters, we used a wildcard, the asterisk (*), to trigger a prompt for each password. If you were running batch jobs for deployments, you'd likely hard code the password in the batch job. You should be fully aware of the security risk that this approach causes.

Security alert 

We observed that using the Application Center command-line tool in conjunction with the Windows 2000 Scheduler Service could expose user credentials in plain text. Specifically, if you invoke the Scheduler Service with the AT command and specify an Application Center command that requires administrative credentials, those credentials will be put in a .job file that resides on the local disk.

For example, note the following command line:

C:\WINNT>at \\appctr1 4:00PM /interactive ac cluster /add /member:appctr2 
/user:Administrator /password:password1 
Added a new job with job ID = x

The preceding command will create a task that, at 4:00 P.M., invokes the AC CLUSTER command to add another member to the cluster. Because the /USER and /PASSWORD parameters are a part of the command, they are also placed in a .job file on the disk (% windir %\Tasks). If you open up this .job file in a text editor, you will see:

G 2ÐÊCÁ@I›(tm)...† [7JF ê < 
s À €! a c c l u s t e r / a d d / m e m b e r : 
a p p c t r 2 / u s e r : A d m i n i s t r a t o r / 
p a s s w o r d :p a s s w o r d 1 0 Ð

As long as the .job file remains on the disk, the administrator's password is available in plain text.

Presumably, only trusted individuals would have access to % windir % for a cluster member, mitigating the risk from this issue. Nevertheless, best practices strongly discourage keeping any plain-text passwords on disk, especially administrative-level passwords.

Script Samples

Bb734904.spacer(en-us,TechNet.10).gif Bb734904.spacer(en-us,TechNet.10).gif

We've included some scripts to illustrate how scripting, using the Windows Script Host, can be used in the Application Center environment to help you automate administrative tasks, as well as extend the product's feature set.

Script: Asynchronously Trap an Event

This script illustrates how you can asynchronously trap an Application Center event and write a notification to the screen. The event in this example is fired when a member goes offline and is no longer in the load-balancing loop. The script uses the Windows Management Instrumentation (WMI) method ExecNotificationQueryAsync to select the fields in the MicrosoftAC_Cluster_LoadBalancing_ServerOffline_Event class.

Dim objService, objSink
Set objService = GetObject("winmgmts:root\MicrosoftApplicationCenter")
Set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
objService.Security_.ImpersonationLevel = 3
objService.ExecNotificationQueryAsync objSink, "SELECT * FROM " & _
"MicrosoftAC_CLuster_LoadBalancing_ServerOffline_Event "
WScript.Echo "Waiting for events."
Sub SINK_OnCompleted(iHResult, objErrorObject, objAsyncContext)
WScript.Echo "Asynchronous operation is done."
End Sub
Sub SINK_OnObjectReady(objObject, objAsyncContext)
WScript.Echo "Server " & objObject.ServerName & " taken offline"
End Sub
To Use This Script

Using Notepad, or another text editor, copy and paste the preceding code into a new file, and then save the file as AsyncEvents.vbs. You can run this script by either double-clicking the file name or by executing it from the command line with cscript.exe AsyncEvents.vbs or wscript.exe AsyncEvents.vbs.

Script: Synchronously Trap an Event

This script illustrates how you can synchronously trap an Application Center event and write a notification to the screen. The event in this example is fired when a member goes offline and is no longer in the load-balancing loop. The script uses the WMI method ExecNotificationQuery to select the fields in the MicrosoftAC_Cluster_LoadBalancing_ServerOffline_Event class. The script then uses the ServerName, TimeGenerated, and DrainTime fields to return information about the offline event. After 10 server events, the script terminates.

Dim intEvent, objEvents, evtEvent
Set objEvents = GetObject("winmgmts:root\MicrosoftApplicationCenter") _
.ExecNotificationQuery ("select * " & _
"from MicrosoftAC_CLuster_LoadBalancing_ServerOffline_Event ") 
WScript.Echo "Waiting for Server to go offline..."
For intEvent = 1 to 10
Set evtEvent = objEvents.NextEvent
WScript.Echo "Server " & evtEvent.ServerName & _
" was " & "taken offline" & " at " & OfflineEvent.TimeGenerated
WScript.Echo "with a drain time of " & evtEvent.DrainTime
Next
To Use This Script

Using Notepad, or another text editor, copy and paste the preceding code into a new file, and then save the file as GetOfflineEventInfo.vbs. You can run this script by either double-clicking the file name or by executing it from the command line with cscript.exe GetOfflineEventInfo.vbs or wscript.exe GetOfflineEventInfo.

Script: Obtain the Available Disk Space and Directory Listing

This script is used in a custom action (Script) that's associated with the data collector LogicalDisk.

When the data collector crosses its threshold, which is based on the amount of free space (less than 10 percent), the custom action is triggered and this script prepares a notification about the amount of available disk space. In addition to displaying a message about the available space, the script also provides a prompt that asks if you want to see a directory listing.

Dim fsoFSys, fsoDrive, strName
Set objShell= CreateObject ("WScript.Shell")
Set fsoFSys = GetObject("winmgmts:").ExecQuery("select FreeSpace,Size,Name from WIN32_LogicalDisk where drivetype = 3")
For Each fsoDrive In fsoFSys
WScript.Echo "Space available: " & fsoDrive.FreeSpace
if MsgBox ("Directory listing?", vbYesNo) = vbYes Then
objShell.Run "cmd /C dir " & fsoDrive.Name & "\ >" & Left(fsoDrive.Name,1) & "-dir.txt",0
End If 
Next
To Use This Script

Using Notepad, or another text editor, copy and paste the preceding code into a new file, and then save the file as DiskSpace.vbs. Specify this script in a custom action, and then associate this action with a data collector.

You can run this script manually by either double-clicking the file name or by executing it from the command line with cscript.exe DiskSpace.vbs or wscript.exe DiskSpace.vbs.

Script: Save ACLog Database as CSV Text File

This script establishes a connection to the specified database, extracts all the records, and writes the records, with comma-separated fields, to a text file. You can have this script associated with a data collector that either has a threshold based on the size of ACLog, or is date- and time-based.

Dim fsoOutput, fsoStream, objConnection, objRecords
Dim strName, strFields
Set fsoOutput = CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open = "Provider = SQLOLEDB; Data Source = cfurlin0;" _
& "Initial Catalog = Pubs; User ID = sa; Password =;"
Set objRecords = objConnection.Execute("select * from stores")
For Each strName In objRecords.Fields
strFields = strFields + strName.Name + ","
Next
Set fsoStream = fsoOutput.CreateTextFile("output.csv", True)
fsoStream.WriteLine Left(strFields, Len(strFields) - 1)
fsoStream.WriteLine Replace(objRecords.GetString, vbTab, ",")
objConnection.Close
To Use This Script

Using Notepad, or another text editor, copy and paste the preceding code into a new file. Edit the file to provide the required data source, database name, user identifier, and password. Save the file as SQLToCSV.vbs. Specify this script in a custom action, and then associate this action with a data collector.

You can run this script manually by either double-clicking the file name or by executing it from the command line with cscript.exe SQLToCSV.vbs or wscript.exe SQLToCSV.vbs.

Script: Backup the ACLog Database

This next script is a variation of the SQLToCSV script. It also enables you to dump the contents of a member database to a text file. You can have this script associated with a data collector that either has a threshold based on the size of ACLog, or is date- and time-based.

Because Application Center uses a named instance of the Microsoft SQL Server 2000 Desktop Engine (SQL desktop engine) on each member, you must specify the named instance (for example, ACDW516AS\MSAC).

'
' DMOOpen Function – Opens the database
'
Function DMOOpen(Server)
Dim oServer, InstanceName
InstanceName = Server & "\MSAC"
Set oServer = CreateObject("SQLDMO.SQLServer")
oServer.LoginSecure = True
oServer.Connect InstanceName , "", ""
Set DMOOpen = oServer
End Function
'
' DatabaseBackup – Writes the data to a file
'
Sub DatabaseBackup(Server, DBName, FileName)
Dim oServer, oBackup
Set oServer = DMOOpen(Server)
Set oBackup = CreateObject("SQLDMO.Backup")
oBackup.Action = 0 ' SQLDMOBackup_Database
oBackup.Database = DBName
oBackup.Files = FileName
oBackup.SQLBackup oServer
End Sub
To Use This Script

Using Notepad, or another text editor, copy and paste the preceding code into a new file. Save the file as DumpACLog.vbs. In DatabaseBackup(Server, DBName, FileName) provide values; for example, ACDW516AS, ACLog, and ACDW516AS.bak. Execute the file on the member whose database you want to archive. Specify this script in a custom action, and then associate this action with a data collector.

You can run this script manually by either double-clicking the file name or by executing it from the command line with cscript.exe DumpACLog.vbs or wscript.exe DumpACLog.vbs.

Batch File: Clean ACLog Tables

You can create a batch file to clean out the Application Center Events and Performance Logging database after you've archived the database on the local member. When you run this batch file, each command line in the file connects to one of the tables that constitute ACLog and truncates the table to clean out the existing data.

@ECHO OFF
IF "%1" == "" THEN GOTO HELP
IF "%1"=="/?" THEN GOTO HELP
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE PerfHistory"
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE PerfHistory2"
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE PerfHistory3"
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE PerfHistory4"
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE PerfHistory5"
Osql -E -d ACLOG -S %1\msac -Q "TRUNCATE TABLE Events"
To Use This Batch File

Using Notepad, or another text editor, copy and paste the preceding code into a new file. Save the file as CleanACLog.bat. Execute the file on the member whose database you want to archive by running CleanACLog.bat from the command prompt.

Additional Samples

In addition to the preceding samples, the Resource Kit CD also contains a diverse collection of script samples. After you install the Resource Kit from the CD, you can access these samples by using the following default installation path:

C:\Program Files\Microsoft Application Center 2000 Resource Kit\ Command line scripts

Resources

Bb734904.spacer(en-us,TechNet.10).gif Bb734904.spacer(en-us,TechNet.10).gif

https://msdn.microsoft.com/library/en-us/script56/html/vtoriMicrosoftWindowsScriptTechnologies.asp.

The Microsoft Windows Script Technologies site is the main resource for obtaining information about scripting technologies, such as VBScript, Jscript, and WSH.

Bb734904.spacer(en-us,TechNet.10).gif