background image

VMware, Inc.

2

Extending Virtual Machine Deletion with Scripts

The

 

next

 

example

 

shows

 

how

 

you

 

could

 

extract

 

the

 

name

 

of

 

the

 

virtual

 

machine,

 

and

 

use

 

this

 

value

 

to

 

delete

 

the

 

corresponding

 

entry

 

from

 

Active

 

Directory.

Dim shell
set shell = WScript.CreateObject( "WScript.Shell" )

set vmName = shell.ExpandEnvironmentStrings("%VDM_DeleteVm_VmName%")
set machineObj = GetObject("LDAP://CN=" & vmName & ",CN=Desktops,DC=MYDOMAIN,DC=COM")
machineObj.DeleteObject(0)

This

 

example

 

assumes

 

that

 

the

 

script

 

runs

 

with

 

the

 

administrative

 

rights

 

to

 

update

 

entries

 

in

 

Active

 

Directory.

 

You

 

must

 

modify

 

the

 

script

 

to

 

correspond

 

to

 

the

 

configuration

 

of

 

your

 

local

 

systems

 

in

 

Active

 

Directory.

Add a Windows Registry Entry for a Deletion Script

To

 

make

 

a

 

deletion

 

script

 

available

 

for

 

execution,

 

you

 

must

 

add

 

it

 

to

 

the

 

Windows

 

registry.

 

You

 

must

 

create

 

an

 

entry

 

on

 

each

 

View

 

Connection

 

Server

 

instance

 

where

 

you

 

want

 

View

 

Manager

 

to

 

run

 

the

 

deletion

 

script

 

when

 

you

 

delete

 

a

 

virtual

 

machine.

To add an entry for a deletion script to the registry on a View Connection Server instance

1

Start

 

the

 

Windows

 

Registry

 

Editor

 

by

 

entering

 

regedit

 

at

 

the

 

command

 

prompt.

2

In

 

the

 

registry,

 

navigate

 

to

 

HKLM\SOFTWARE\VMware, Inc.\VMware VDM\ScriptEvents

.

3

In

 

the

 

navigation

 

area,

 

right

click

 

ScriptEvents

,

 

select

 

New

 

>

 

Key

,

 

and

 

create

 

a

 

key

 

named

 

DeleteVm.

4

In

 

the

 

navigation

 

area,

 

right

click

 

DeleteVm

,

 

select

 

New

 

>

 

String

 

Value

,

 

and

 

create

 

a

 

string

 

value

 

that

 

identifies

 

the

 

deletion

 

script

 

to

 

be

 

run.

To

 

run

 

more

 

than

 

one

 

deletion

 

script,

 

create

 

a

 

string

 

value

 

entry

 

for

 

each

 

script

 

under

 

the

 

DeleteVm

 

key.

 

You

 

cannot

 

specify

 

the

 

order

 

in

 

which

 

these

 

scripts

 

run.

 

If

 

the

 

scripts

 

must

 

run

 

in

 

a

 

specified

 

order,

 

invoke

 

them

 

from

 

a

 

single

 

control

 

script.

5

In

 

the

 

topic

 

area,

 

right

click

 

on

 

the

 

entry

 

for

 

the

 

new

 

string

 

value,

 

and

 

select

 

Modify

.

6

In

 

Value

 

data

,

 

enter

 

the

 

command

 

line

 

that

 

invokes

 

the

 

deletion

 

script,

 

and

 

click

 

OK

.

Specify

 

the

 

full

 

path

 

of

 

the

 

deletion

 

script

 

and

 

any

 

files

 

that

 

it

 

requires.

7

If

 

you

 

want

 

the

 

VMware

 

View

 

Script

 

Host

 

service

 

to

 

time

 

out

 

the

 

deletion

 

script,

 

right

 

click

 

on

 

the

 

Default

 

key,

 

select

 

Modify

,

 

enter

 

the

 

timeout

 

value

 

in

 

milliseconds,

 

and

 

click

 

OK

.

8

Exit

 

the

 

Registry

 

Editor,

 

and

 

restart

 

the

 

system.

Configure the VMware View Script Host Service

You

 

must

 

configure

 

the

 

VMware

 

View

 

Script

 

Host

 

service

 

on

 

each

 

View

 

Connection

 

Server

 

instance

 

where

 

you

 

want

 

View

 

Manager

 

to

 

run

 

the

 

deletion

 

script.

 

By

 

default,

 

the

 

VMware

 

View

 

Script

 

Host

 

service

 

is

 

disabled.

To configure the VMware View Script Host service

1

Start

 

the

 

Windows

 

Services

 

tool

 

by

 

entering

 

services.msc

 

at

 

the

 

command

 

prompt.

2

In

 

the

 

details

 

pane,

 

right

click

 

on

 

the

 

VMware

 

View

 

Script

 

Host

 

service

 

entry,

 

and

 

select

 

Properties

.

3

On

 

the

 

General

 

tab,

 

in

 

Startup

 

type

,

 

select

 

Automatic

.

4

If

 

you

 

do

 

not

 

want

 

the

 

local

 

system

 

account

 

to

 

run

 

the

 

deletion

 

script,

 

select

 

This

 

account

,

 

and

 

enter

 

the

 

details

 

of

 

the

 

account

 

to

 

run

 

the

 

deletion

 

script.

5

Click

 

OK

,

 

and

 

exit

 

the

 

Services

 

tool.

C

AUTION

   

Running

 

a

 

deletion

 

script

 

under

 

the

 

local

 

system

 

account

 

could

 

compromise

 

the

 

security

 

of

 

the

 

View

 

Connection

 

Server

 

host.

 

If

 

you

 

configure

 

an

 

account

 

other

 

than

 

the

 

local

 

system

 

account

 

to

 

run

 

a

 

deletion

 

script,

 

verify

 

that

 

the

 

account

 

has

 

read

 

permission

 

on

 

the

 

registry

 

key

 

for

 

the

 

script.

 

You

 

should

 

also

 

limit

 

the

 

administrative

 

rights

 

of

 

a

 

deletion

 

script

 

to

 

those

 

rights

 

that

 

allow

 

it

 

to

 

perform

 

its

 

function.

Отзывы: