Thursday 24 February 2011

Change Owner in SCVMM for multiple VMs

The more I use Powershell the more I like how it simplifies administration. Whether you using it with Windows Operating Systems, Exchange, Hyper-V, SCVMM, VMware or the many other uses it can make life much easier.

One of the ways I have used Powershell recently was to update the Owner property of multiple virtual machines in System Center Virtual Machine Manager (SCVMM). What I really liked was just how short the piece of code was to achieve this.

Change Owner for all VMs

$vms = get-vm *
foreach ($vm in $vms)
{
set-vm $vm -Owner *Domain*\*User or Group*
}

Note: Substitute *Domain* for the AD Domain & *User or Group* for the Username or Group.


That is infinitley quicker than right clicking each VM and then changing the owner!!!

So once I saw how easy this was I started to add to it.

In larger Hyper-V & SCVMM implementations it is likely that one the scenarios below may be useful too:

Change Owner for VMs in a predefined list using an array:

$vms = @("vm1","vm2","vm3","vm4","vm5")
foreach ($vm in $vms)
{
set-vm $vm -Owner *Domain*\*User or Group*
}

Note: Substitute *Domain* for the AD Domain and *User or Group* for the Username or Group.



Change Owner for VMs with specific naming standard:

$vms = get-vm *sql*
foreach ($vm in $vms)
{
set-vm $vm -Owner *Domain*\*User or Group*
}

Note: Substitute *Domain* for the AD Domain and *User or Group* for the Username or Group.

Obviously this is only using the -Owner attribute of set-vm. When you look at just how many different options you have with set-vm, there are numerous possibilities of how to make changes to a larger number of VMs in one hit.

This is a very simple start to hopefully what will become a series of blog posts from me on Powershell scripts.

Below are the list of available options for set-vm, so these can all be used in the ways shown above to alter multiple VMs...

NAME
Set-VM

SYNOPSIS
Changes properties of a virtual machine managed by Virtual Machine Manager.

SYNTAX
Set-VM [-VM] [] -JobGroup [-BootOrder ]
[-CostCenter ] [-CPUCount ] [-CPUMax ]
[-CPUReserve ] [-CPUType ] [-Custom1 ]
[-Custom10 ] [-Custom2 ] [-Custom3 ] [-Custom4 ]
[-Custom5 ] [-Custom6 ] [-Custom7 ] [-Custom8 ]
[-Custom9 ] [-DelayStart ] [-Description ]
[-DiskIO ] [-EnableBackup ] [-Enabled ]
[-EnableDataExchange ] [-EnableHeartbeat ]
[-EnableOperatingSystemShutdown ]
[-EnableTimeSynchronization ]
[-ExcludeFromPRO ] [-ExpectedCPUUtilization ]
[-HighlyAvailable ] [-InstallVirtualizationGuestServices]
[-JobVariable ] [-LimitCPUForMigration ]
[-LimitCPUFunctionality ] [-MemoryMB ] [-Name ]
[-NetworkUtilization ] [-NumLock] [-OperatingSystem ]
[-Owner ] [-PROTipID ] [-QuotaPoint ]
[-RelativeWeight ] [-RemoveSelfServiceUserRole ] [-RunAsSystem]
[-RunAsUserCredential ] [-RunAsynchronously ]
[-StartAction ] [-StopAction ] [-Tag ]
[-UseHardwareAssistedVirtualization ] [-UserRole ]
[-VMwareResourcePool ] []

DESCRIPTION
Changes one or more properties of a virtual machine managed by Virtual Machine
Manager. Properties that you can change include:
* Name, owner, and description of a VM.
* BIOS boot order (for VMs on a Hyper-V host)
* Amount of resources on the host used by a VM. These include:
- Maximum amount of host CPU resources that a VM can use.
- Minimum amount of host CPU resources that a VM can use.
- Expected use of host CPU by a VM.
- Amount of host CPU resources used by one VM relative to
other VMs on the same host.
- Amount of host memory that a VM can use.
- Amount of bandwidth on the host's network that a VM can use.
* Hardware settings for a VM unrelated to host resources. These include:
- Number of CPUs
- Type of CPU
- Number of disk input/output operations per second (IOPS)
- Limiting CPU functionality (for an older operating system,
such as Windows NT 4.0)
* Cost center, tag, and custom settings used to filter VMs by criteria
that you set.
* Settings that enable various optional capabilities, including:
- Enabling or disabling a library object to make it available,
or temporarily unavailable, to users
- Enabling backing up a VM on a Hyper-V host with Volume Shadow Copy
- Enabling a key/value pair for data exchange between a VM and its
Hyper-V host
- Enabling a signal to monitor a VM on a Hyper-V host.
- Enabling shutdown of a VM from teh Hyper-V console.
- Enabling time synchronization between a VM and its Hyper-V host.
- Enabling the BIOS value for NumLock for a VM on a Windows host.
* Setting that identifies whether a VM is highly available, that is,
a VM to be deployed on a node of a Hyper-V host cluster.
* Setting that determines whether virtualization guest services are
installed on a Windows-based VM.
* Number of seconds to delay before starting a VM.
* Setting that identifies the operating system used for a VM.
* Settings that specify whether to run a VM on a Virtual Server host under
the local system account or under a guest account (domain\account).
* Start and stop actions for a VM.
* Setting that determines whether a VM on a Virtual Server host uses
hardware-assisted virtualization.
* Setting that limits the number of VMs self-service users can create.
* Setting used to switch the role that a self-service user who belongs
to multiple roles uses to manage a VM.
* Setting that assigns a VM on an ESX host to a VMware resource pool.

If you want to change the properties of a virtual floppy drive, virtual DVD
drive, virtual network adapter, or virtual SCSI adapter associated with a
specific virtual machine, you can use Set-VirtualFloppyDrive,
Set-VirtualDVDDrive, Set-VirtualNetworkAdapter, or Set-VirtualSCSIAdapter,
respectively.

For more information about virtual machines, type:
Get-Help New-VM -detailed

RELATED LINKS

DisableUndoDisk-VM
DiscardSavedState-VM
Move-VM
New-VM
Refresh-VM
Remove-VM
Repair-VM
Resume-VM
SaveState-VM
Shutdown-VM
Start-VM
Stop-VM
Store-VM
Suspend-VM

REMARKS
To see the examples, type: "get-help Set-VM -examples".
For more information, type: "get-help Set-VM -detailed".
For technical information, type: "get-help Set-VM -full".

1 comment:

bladie said...

Very useful Mark thanks for the blog