System_Center_Virtual_Machine_Manager_Scripting_Guide.doc

(670 KB) Pobierz

 

f:\dsbuildroot\wswemdmain\1033\Art\wss_logo\wss_logo.gif

 

Microsoft® System Center Virtual Machine Manager

System Center Virtual Machine Manager Scripting Guide

Microsoft Corporation

Published: October 2007

Abstract

Microsoft System Center Virtual Machine Manager 2007 is a server application for managing a large number of virtual machines and the servers that support those virtual machines. The Virtual Machine Manager command shell is built on Microsoft Windows PowerShell, an administrator-focused interactive shell and scripting language that is integrated into the Windows platform. This guide provides sample scripts illustrating how you can use Windows PowerShell scripting for centralized management of your physical and virtual system infrastructure.

Disclaimer: The sample scripts in this guide are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

 


Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

© 2007 Microsoft Corporation. All rights reserved.

Microsoft, MS-DOS, Windows, Windows Server, Windows Vista, and Active Directory are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

All other trademarks are property of their respective owners.

 

 


Contents

Windows PowerShell Scripting in Virtual Machine Manager              7

Getting Started with PowerShell Scripting for VMM              8

How Windows PowerShell Supports Scripting              9

How to Enable Windows PowerShell Scripting              9

How to Identify Windows PowerShell Script Extensions              10

How To Run a Windows PowerShell Script              10

How to Create Simple Scripts              11

How to Create a Windows PowerShell 'Hello World' Script              11

How to List Only Virtual Machine Manager Cmdlets              13

How to Convert an Existing Cmdlet Help Example to a Script              13

How to Convert an Example for Restart-Job into a Script              14

How to Use the Profile.ps1 Script to Run Your Scripts Without Typing the Path              15

How to Provide User Credentials in a Script              16

How to Store Credentials That a Specific Script Can Re-Use              16

How to Store Credentials That All Scripts in a Session Can Re-Use              18

How WMI Enables Cross-Product Scripting              18

For More Information              18

Sample Scripts for Managing Snap-ins              20

AddVMMSnapin.ps1              21

AddVMMExchSnapins.ps1              21

Before You Start              22

Add-VMMExchSnapins.ps1 - Complete Script              22

AddVMMCmdletsToOpsMgrConsole.ps1              23

Sample Script for Upgrading Hosts and Library Servers              25

UpgradeAgents.ps1              25

How UpgradeAgents.ps1 Works              25

UpgradeAgents.ps1 - Complete Script              26

Sample Script for Managing Hosts              27

AddVSServerAsHost.ps1              27

How AddVSServerAsHost.ps1 Works              27

AddVSServerAsHost.ps1 - Complete Script              32

QuickMigrate-VM.ps1              35

QuickMigrate-VM.ps1 - Complete Script              35

Sample Scripts for Managing Virtual Machines              42

AutomateNewVMCreation.ps1              42

How AutomateNewVMCreation.ps1 Works              42

AutomateNewVMCreation.ps1 - Complete Script              53

InstallVMAdditions.ps1              58

How InstallVMAdditions.ps1 Works              59

InstallVMAdditions.ps1 - Complete Script              63

ConfigureGuestCluster.ps1              66

How ConfigureGuestCluster.ps1Works              66

ConfigureGuestCluster.ps1 - Complete Script              69

NewVMScriptFromWizard.ps1              71

How to Use View Script to Create a Reusable Script              71

NewVMScriptFromWizard.ps1 - Complete Script              74

Sample Job-Related Scripts              76

EnableVMRC.ps1              76

How EnableVMRC.ps1 Works              76

EnableVMRC.PS1 - Complete Script              77

NeedVMAdditions.ps1              78

How NeedVMAdditions.ps1 Works              79

NeedVMAdditions.ps1 - Complete Script              79

TrackJobStatus.ps1              80

How TrackJobStatus.ps1 Works              80

TrackJobStatus.ps1 - Complete Script              84

Sample Scripts for Managing Self-Service Policies              87

Before You Start              87

CreateSelfServicePolicy_AccessVMs.ps1              88

How CreateSelfServicePolicy_AccessVMs.ps1 Works              88

CreateSelfServicePolicy_AccessVMs.ps1 - Complete Script              90

CreateSelfServicePolicy_ManageVMs.ps1              91

How CreateSelfServicePolicy_ManageVMs.ps1 Works              92

CreateSelfServicePolicy_ManageVMs.ps1 - Complete Script              93

CreateSelfServicePolicy_CreateManageVMs.ps1              95

How CreateSelfServicePolicy_CreateManageVMs.ps1 Works              95

CreateSelfServicePolicy_CreateManageVMs.ps1 - Complete Script              97

CreateSelfServicePolicy_CreateManageStoreVMs.ps1              99

How CreateSelfServicePolicy_CreateManageStoreVMs.ps1 Works              99

CreateSelfServicePolicy_CreateManageStoreVMs.ps1 - Complete Script              102

Sample Scripts for Backing Up and Restoring the VMM Database              104

Backup/Recover: What You Need to Know Before You Start              104

BackupLocalVMM.ps1              104

How BackupLocalVMM.ps1 Works              105

BackupLocalVMM.ps1 - Complete Script              105

BackupRemoteVMM.ps1              106

How BackupRemoteVMM.ps1 Works              106

BackupRemoteVMM.ps1 - Complete Script              106

RestoreLocalVMM.ps1              107

How RestoreLocalVMM.ps1 Works              107

RestoreLocalVMM.ps1 - Complete Script              107

RestoreRemoteVMM.ps1              108

How RestoreRemoteVMM.ps1 Works              108

RestoreRemoteVMM.ps1 - Complete Script              109

Sample Script for Integrating VMM with OpsMgr              110

DiscoverVMMComputers.ps1              110

How DiscoverVMMComputers.ps1 Works              110

DiscoverVMMComputers.ps1 - Complete Script              112

Sample Script Summarizing VMM Information              113

SummarizeVMMInformation.ps1              113

Display Information About the Virtual Machine Manager Server              113

Display Information About Host Servers              115

Display Information About Virtual Machines              116

Display Information About Self-Service Policies              116

Display Information About Library Servers              117

Display Information About Host Groups              118

SummarizeVMMInformation.ps1 - Complete Script              119

Appendix A: About Windows PowerShell for Virtual Machine Manager              123

How Virtual Machine Manager Uses Windows PowerShell              123

How a Snap-in Provides Virtual Machine Manager Cmdlets              125

How the Administrator Console Uses Virtual Machine Manager Cmdlets              126

How Objects Represent All Entities in Virtual Machine Manager              126

How Managing Objects Is More Efficient Than Text-Based Processing              127

How to Access an Object              127

How Virtual Machine Manager Cmdlets Work with Objects              128

How Virtual Machine Manager Updates Objects Stored in the Library              129

How Virtual Machine Manager "Live" Objects Work              130

Appendix B: Introductory Command-Line Tutorial              132

How to Find the Virtual Machine Manager Command Shell              132

How to Use Basic Windows PowerShell Cmdlets              133

How to Get Information About Virtual Machine Manager Cmdlets              135

How to Get Information About Virtual Machine Manager              137

How to Use Virtual Machine Manager Help Topics              140

How to Search or Save Cmdlet Help Topics              141

Useful Windows PowerShell Command-Line Help Topics              143

 


 

Windows PowerShell Scripting in Virtual Machine Manager

Microsoft System Center Virtual Machine Manager 2007 is a server application that you can use to manage a large number of virtual machines. This guide provides sample Mic...

Zgłoś jeśli naruszono regulamin