Tag Archive for powercli

Connect All Virtual Machine Network Adapters With PowerCLI

In this post I will explain how to run a PowerCLI command to connect or disconnect all virtual machine network adapters. Recently I experienced a power failure in one of my data centres that took out one of my SANs as well a host that held my vCenter server. When the kit was powered back on and vCentre was responding, an odd occurrence took place where all virtual machines managed by this vCenter server had the “Connect On Power On” check box enabled but the “Connected” check box wasn’t. At the time the only way to rectify this issue was to manually go though each virtual machine and check the box for the adapter to be connected. Not a fun experience.

To avoid the requirement for manual intervention to solve this issue for each virtual machine in the future, I have put together a PowerCLI command that will run though all virtual machines and connected their respective network adapters.

To do so, first load PowerCLI and connect to your vCenter server with the following command:

Connect-VIServer -Server vcenter.domain.local  -User domain/username -Password yourpassword

Following this, run the below command. This will run through all virtual machines managed by vCentre and connect network adapters 1 and 2. You can add additional adapters to be connected by simply adding more into the command e.g. “Network adapter 3″,”Network adapter 4″ etc.

Get-VM | Get-NetworkAdapter -Name “Network adapter 1″,”Network adapter 2″ | Set-NetworkAdapter -Connected:$true -Confirm:$false

I hope you found this post useful, and remember to look out for my future posts on PowerCLI.

VMware View Scheduled Recompose

In this post we’ll go over writing a View PowerCLI script to schedule a recompose of a desktop pool.

If your like most VMware View administrators you’ll probably use linked clones, and know that now and again these clones will need recomposing to keep up to date with operating system patches or updates for embedded applications. If your organisation is like mine and operates on a 24 hours basis, getting downtime to perform a recompose can end up being headache and is usually scheduled for a unsavory hour.

Unfortunately scheduled tasks was not part of the View v5 release which i imagine left many people in my situation slightly disappointed. To get around this need for functionality, i turned to the View PowerCLI extensions and wrote a script to perform my desired tasks.

Below you will fine my script, along with one of my working examples that allows you to specify a linked clone pool to be recomposed from a specific virtual machine and snapshot at a defined time and date.

 

Script: Get-Pool -pool_id your-pool-id | Get-DesktopVM | Send-LinkedCloneRecompose -schedule ‘yyyy-MM-dd-23 hh:mm’ -parentVMPath “your-parent-vm-path” -parentSnapshotPath “your-snapshot-path

 

Example: Get-Pool -pool_id LC-EXT-H2F | Get-DesktopVM | Send-LinkedCloneRecompose -schedule ’2012-01-23 11:42′ -parentVMPath “/Hangar 1/vm/VMware View/Linked Clones/viewpocmlc” -parentSnapshotPath “/Base Windows 7 Image/Base Windows 7 Tweaked/Windows 7 with Basic Apps”

 

Below is an example desktop pool’s options which details the paths for -parentVMPath shown under Parent VM, and -parentSnapshotPath shown under Image.

Thanks for reading and be sure checkout how to schedule the refresh of a desktop pool Here

VMware View Scheduled Refresh

In this post I will detail how to make use of the VMware View PowerCLI extensions. One feature I has hoping to see in the release of VMware View 5 was the ability to schedule tasks such as refreshing desktops or recomposing entire pools. Unfortunately this feature wasn’t added to View so i seeked my own solution. With View PowerCLI you can perform most if not all main functionality and better still, schedule when you went these commands to run. In this post the relevant commands for scheduling the refresh of a pool at a defined time are outlined.

Script: Get-Pool -pool_id your-pool-id | Get-DesktopVM | Send-LinkedCloneRefresh -schedule ‘yyyy-MM-dd hh:mm’

Example: Get-Pool -pool_id LC-EXT-H2F | Get-DesktopVM | Send-LinkedCloneRefresh -schedule ’2012-01-23 09:12′

PowerCLI What Do I Need?

VMware PowerCLI can be a very powerful tool in managing your vSphere environment. To get started there are two installs you will need to download and execute on to either a server or workstation that has visibility of your vSphere environment. Once installed you’ll be able to experiment with scripting commands and scheduling tasks. Remember to look out for a later post on using PowerCLI scripts with VMware Site Recovery Manager.

 

Microsoft Powershell 2.0

 Direct | Mirror

 VMware PowerCLI 5.0

Direct | Mirror