Archive for PowerCLI

Set Datastore Multipathing Policy Automaticly with PowerCLI

You may find when you add a new host to your vSphere environment and discover any datastores presented to the host, the multipathing policy will be automatically set to MRU (Most Recently Used). For best performance it’s recommended to change this policy to Roundrobin, however this is a very manual and tedious task of adjusting each datastore on each host.

To speed this process up, below you can find a PowerCLI command that will set all datastores on a specific host to Roundrobin.

Get-Cluster “clustername” | Get-VMHost -Name “hostname” | Get-ScsiLun -LunType “Disk” | Set-ScsiLun -MultipathPolicy “roundrobin”

Equally you can use the same command for setting your datastores to MRU as shown below.

Get-Cluster “clustername” | Get-VMHost -Name “hostname” | Get-ScsiLun -LunType “Disk” | Set-ScsiLun -MultipathPolicy “MostRecentlyUsed”

How To Install VMware Tools Without Rebooting

This post will detail how to upgrade VMware tools on virtual machines without having to reboot by using PowerCLI. Personally I have found this quite useful when having to upgrade VMware tools on production servers that require 24×7 up time. I have tried this update method on Windows Server 2008/R2 and RHEL 5/6 with success.

First you need to connect to your vCenter server via PowerCLI and choose one of the two methods of deployment detail below.

Upgrade VMware tools on a singular virtual machine:

Get-VM “yourvm” | Update-Tools –NoReboot

Upgrade VMware tools on all virtual machines:

Get-VM | Update-Tools –NoReboot

Thanks for reading and remember to lookout for my other posts on PowerCLI.

How To Export PowerCLI vCenter Reports

This is a quick post on how to generate some reports from vCenter through PowerCLI.

Log in to your vCenter server via PowerCLI and run a report of your choice:

Virtual Machine Report:

Get-VM | Export-Csv -Path “c:\vmreport.csv”

Snapshot Report:

Get-VM | Get-Snapshot | Export-Csv -Path “c:\snapshotreport.csv”

Datastore Report:

Get-Datastore | Export-Csv -Path “c:\datastorereport.csv”

Host Report:

Get-VMHost | Export-Csv -Path “c:\hostreport.csv”

Cluster Report:

Get-Cluster | Export-Csv -Path “c:\clusterreport.csv”

Thanks for reading.

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