Home > Blogs > VMware PowerCLI Blog > Tag Archives: vCloud

Tag Archives: vCloud

Introduction to PowerCLI

Here at VMware we still get questions from people who are starting out with PowerCLI,

To make sure everyone is aware of the power that is available to system administrators in PowerCLI we wanted to create the below introduction which answers some of the frequent questions we receive when people start out on their journey to manage VMware platforms with the command line interface and provide automation to the Software Defined Data Center.

Retrieving vCloud Director VM Hard Disk size

I was asked recently if we were able to retrieve the disk space of a VM in vCloud Director through PowerCLI, on checking this I found that it is not currently part of the CIVM object and also there is currently no Get-HardDisk cmdlet equivalent like in the vSphere snapin.

After looking through the REST API Reference Documentation –> User Operations I found an entry for the VM VirtualHardwareSection  and specifically the disks which can be found as can be seen here: GET /vApp/{id}/virtualHardwareSection/disks

The virtualhardwaresection is easily accessed via PowerCLI using the extensiondata property which allows access to the back end API, I could then find my disk properties by filtering on the description of Hard Disk as in the example below:

(Get-VM MyCloudVM).ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}

Now I had the hard disk I noticed that part of the information was the capacity as highlighted below:image

With this information I could then find the capacity of the disk and add the information I needed into more of a friendly PowerShell property to the Hard Disk object.

So tying this all back together we could easily use the .ExtensionData reference to create our own Advanced PowerShell function to return the hard disk information for any CIVM.

Example

The following shows an example of how to use this new function and the output, this of course can also be used to export into CSV/HTML/Text or any other format PowerShell can be used with, it is also great for reporting on where the disk space in your cloud is being used!

image

The Code

Function Get-CIVMHardDisk {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
$CIVM
)
Process {
$AllHDD = $CIVM.ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}
$HDInfo = @()
Foreach ($HD in $AllHDD) {
$HD | Add-Member -MemberType NoteProperty -Name “Capacity” -Value $HD.HostResource[0].AnyAttr[0].”#text”
$HD | Add-Member -MemberType NoteProperty -Name “VMName” -Value $CIVM.Name
$HDInfo += $HD
}
$HDInfo
}

}

Back to Basics: Connecting to vCenter or a vSphere Host

Following my previous post which took you through the install of PowerCLI I thought it was time to add another back to basics (B2B) post and show how to take the first step in using PowerCLI… Connecting to your vCenter or vSphere host.

Yes, PowerCLI can be used to connect to both vCenter and also the vSphere host independently, of course not all the cmdlets will be relevant if you connect to just the host but still, this can be useful during the initial setup or automated deployments of the complete infrastructure.

How to connect

If you are connecting to either a vCenter server or a vSphere Host the cmdlet is the same, you can use the Connect-VIServer cmdlet to connect to both of these (even at the same time), lets take a look at an example:

C:\PS>Connect-VIServer -Server vcenter01 -User admin -Password pass

In the above example you can see we are connecting to our vCenter server called “vcenter01” with a username and password to gain access to the vCenter server, we did not specify a protocol or port, by default HTTPS and port 443 is assumed which is the same as the vSphere Client or Web Client, unless you specify a –port or –protocol parameter for the cmdlet.

Credentials

In the example above we used the –User and –Password parameters to pass through the credentials but this might not always be what you want to do, especially as PowerShell files are plain text!  There are multiple ways in which we can specify the credentials or store the credentials, its really up to you which you use and which is best suited for your situation.

Continue reading

PowerCLI 5.1 Release 2 Now Available

PowerCLI 5.1 Release 2 has now been released and can be downloaded here.  As always you will find some great new features, bug fixes and enhancements which make PowerCLI even better than before… I know its hard to believe but its true.

VDS Cmdlets

PowerCLI SnapinsWhenever I would ask the question at VMUG’s or VMWorld, “What would you like to see next from PowerCLI” I would always get the same answer “Support for Virtual Distributed Switches!”.

Previously there has been a fling available and also some work created by community member “Luc Dekens” to use VDS, this was a great start but in some cases was not a sustainable solution as it was either not supported or more complicated to maintain or use.

I am now pleased to tell you that PowerCLI has a new snapin, this snapin is called VMware.VimAutomation.VDS and is for managing Virtual Distributed Switches.

Introduced are 14 new cmdlets which will allow you to perform actions against your VDS configuration, we can use the Get-VdsCommand cmdlet to list the new cmdlets.

An overview of these are below:

Cmdlet Name Cmdlet description
Add-VDSwitchPhysicalNetworkAdapter This cmdlet adds host physical network adapters to a distributed switch.
Add-VDSwitchVMHost This cmdlet adds hosts to the specified distributed switch.
Export-VDPortGroup This cmdlet exports the configuration of a specified distributed port group to a specified .zip file.
Export-VDSwitch This cmdlet exports the configuration of a specified vSphere distributed switch to a .zip file.
Get-VDPortgroup This cmdlet retrieves distributed port groups.
Get-VDSwitch This cmdlet retrieves vSphere distributed switches.
New-VDPortgroup This cmdlet creates distributed port groups.
New-VDSwitch This cmdlet creates vSphere distributed switches.
Remove-VDPortGroup This cmdlet removes distributed port groups.
Remove-VDSwitch This cmdlet removes vSphere distributed switches.
Remove-VDSwitchPhysicalNetworkAdapter This cmdlet removes host physical network adapters from the distributed switches they are connected to.
Remove-VDSwitchVMHost This cmdlet removes hosts from the specified distributed switches.
Set-VDPortgroup This cmdlet modifies the configuration of distributed port groups.
Set-VDSwitch This cmdlet modifies the configuration of vSphere distributed switches.

Remember each of these cmdlets has help built in, to access the help including examples of how you might use these cmdlets use the following:

Get-Help cmdletname –full

PowerShell v3 Support

As well as the new cmdlets for working with Distributed switches and all the other great enhancements in PowerCLI 5.1 Release 2 we made sure we listened to our customers and with the release of PowerShell version 3 it seams that a lot of people are already making use or planning to install PowerShell v3.

You will be happy to know that PowerCLI now supports PowerShell v3, this not only gives you support from VMware but also we are now able to take advantage of some of the great enhancements which PowerShell v3 brings.

Some PowerShell v3 examples…

Simplified Syntax… Making PowerShell and therefore PowerCLI easier to read and quicker to type we can use simplified syntax to give us even more English like statements, before we would have needed to use the {} brackets to compare a property, now we are able to type it the same way we would think it…

SNAGHTML26e15701_thumb3

The above simple example shows all virtual machines which are powered on.

vCloud Director 5.1 Support

With PowerCLI 5.1 R2 we have also added support for vCloud Director 5.1, you can now automate the latest version of vCloud director using both PowerCLI and PowerCLI for tenants in a vCloud Director 5.1 environment.

image_thumb2

PowerCLI 5.1 now available

PowerCLI 5.1 is now generally available, as a reminder, in the previous post we gave you an update of what was new.  You can view that post here.

You can view the official PowerCLI release documentation here or the documentation for the Tenant snapin here.

From now on you will see two download links for PowerCLI, one for the updated version of PowerCLI and another for the Cloud Tenants, make sure you choose the correct one as they will not install together.

As you can see from the download page, the updated PowerCLI for vSphere and vCD Administrators is on the left hand side and the PowerCLI for Tenants of vCloud Director is on the right.

Stay tuned for more posts showing exactly what is possible with these new releases soon.Download PowerCLI

Download

Use the following link to be directed to the download page:  http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli?view=overview

PowerCLI 5.1 – What’s New ?

With the announcement of vSphere 5.1 from Steve Herrod at VMworld 2012 – San Francisco I wanted to highlight the new features which will be available as part of VMware vSphere PowerCLI 5.1 Release 1.

Background

image

As with previous releases there have been many enhancements to PowerCLI, as users of PowerCLI will know, as part of the default PowerCLI 5.0.1 install we already had 5 PowerShell Snapin’s available to use, these enabled you to manage the following products and features:

  • vCenter and vSphere (VMware.VimAutomation.Core Snapin)
  • vCenter and vSphere Licensing (VMware.VimAutomation.License Snapin)
  • Image Builder (VMware.ImageBuilder Snapin)
  • Auto Deploy (VMware.DeployAutomation Snapin)
  • vCloud Director (VMware.Vimautomation.Cloud Snapin)

As you will also know, most of the cmdlets for the Cloud snapin were “Get-“ cmdlets, these allowed us to focus on retrieving data from vCloud Director, access to more advanced functions were available via the Get-CIView cmdlet but this was for the advanced PowerCLI users.

What’s New for vSphere Users ?

The PowerCLI Core Snapin introduces a number of improvements and new features, you will of course find many bug fixes and speed enhancements as part of this release, as well as this the following enhancements have been included:

  • You can use Kerberos for pass-through authentication with vCenter Server, ESX/ESXi, and vCenter Virtual Appliance systems.
  • You can create linked clones with New-VM.
  • You can pass datastore clusters to the Datastoreparameters.
  • You can retrieve vSphere objects from vCloud Director objects with the RelatedObjectparameter.
  • You can manage resources more efficiently with Storage DRS (SDRS) support added to a number of cmdlets.
  • You can retrieve, create, modify, and remove VMHost, VM, and SDRS advanced settings with the the Get-AdvancedSetting, New-AdvancedSetting, Set-AdvancedSetting, and Remove-AdvancedSetting cmdlets.

vSphere PowerCLI 5.1 Release 1 also brings a set of improvements that enhance security and customization, these include:

  • You can set the scope of your settings with the Scope parameter of Set-PowerCLIConfiguration.
  • You can initialize custom vSphere PowerCLI scripts automatically by storing them in the Initialize-PowerCLIEnvironment_Custom.ps1 script configuration file.

What’s New for vCloud Admins ?

vCloud Director Admins can take advantage of over 60 cmdlets to manage vCloud Director, these have been enhanced from the “Get-“ cmdlets and now include cmdlets to help you modify and automate your vCloud Directory infrastructure, the following enhancements have been made:

  • You can create, modify, manage, and remove organizations.
  • You can create and manage permissions.
  • You can assign computing and networking resources.
  • You can create, modify, and remove organization networks.
  • You can create, modify, and remove vApp networks.
  • You can create, modify, manage, and remove vApps.
  • You can manage virtual machines and their guest operating systems within vApps.

What’s New for vCloud Tenants ?

With PowerCLI 5.1 Release 1 we now have a new snapin specifically for vCloud Tenants, in fact this is a completely separate installation with its own set of cmdlets which can not be installed on the same machine as vSphere PowerCLI 5.1 Release 1, this is called VMware vSphere PowerCLI Release 1 for Tenants and is designed to aid the vCloud Tenants in performing automated tasks in their hosted vCloud organization.

Why would we do this ?

We wanted to bring the power of automation and the ease of reporting that PowerCLI gives the current vSphere and vCloud Admins to the tenants of the cloud.  All this whilst giving them an easy to use simplified subset of cmdlets specific to the tasks they can do within their vCloud Organization.

What’s available to tenants ?

VMware vSphere PowerCLI 5.1 Release 1 for Tenants consists of two components:

  • vSphere PowerCLI common snapin for providing common PowerCLI configuration and usage based tasks, these cmdlets are part of the VMware.VimAutomation.Commonsnapin.
  • vCloud Director PowerCLI snapin for providing tenant-based reporting and automation, these cmdlets are part of the VMware.VimAutomation.Cloud snapin and can be used with vCloud Director 1.5.1 Tenant tasks.

These components will allow the vCloud Tenants to perform the following tasks:

  • You can list, modify, and manage organizations.
  • You can list, create, and manage permissions.
  • You can list and assign networking resources.
  • You can list organization networks.
  • You can list, create, modify, and remove vApp networks.
  • You can list, create, modify, manage, and remove vApps.
  • You can list and manage virtual machines and their guest operating systems within vApps.

Summary

So where are we now ? What can we actually do with PowerCLI and the different VMware installations of snapins ?

image

As you can see, we have a number of different snapins which enable us to add the products and areas we are interested in using with Windows PowerShell, we have the ability to not only enable our admin users but also our private and public cloud users, with the VMware snapins all users of the VMware products can achieve the level of automation, integration and reporting that PowerShell and PowerCLI gives.

More Information

Keep tuned for more blog posts and information or if you are visiting VMworld Europe in 2012 make sure you add  INF-VSP1252 – What’s New with vSphere 5.1 – ESXCLI & PowerCLI to your session list.

Automating creation of vCD Organizations, Users and Org vDCs

AlanFeb2012_thumb_thumb1_thumb_thumb
Posted by
Alan Renouf
Technical Marketing

In Part 1 of this blog series I wrote about how I presented together with a colleague of mine Vladimir Goranov at Partner Exchange 2012.  I already showed you the reporting script and demonstration on how to create graphs straight from PowerCLI which detail the resources and statistics in your Cloud Infrastructure (CI).

Following the reporting side of the vCloud Director snap-in we explained that although in PowerCLI 5.0.1 the cmdlets were mainly “GET” cmdlets which retrieved data from the Cloud there was also a cmdlet called Get-CIView and a property on the returned objects called .ExtensionData.

The Get-CIView cmdlet and ExtensionData property exposes the entire vCloud Director API and allows us to make changes to the CI, this opens up multiple possibilities and moves us away from just retrieving data and allows us to create and alter our CI.

In our presentation we showed how the current cmdlets could be used to create some advanced functions which would look just like PowerShell cmdlets and could be used to create new Organizations, Users and Organizational vDC's.

We then used the scenario of a service provider having to add multiple new Organizations into their CI, would they add these one by one using the GUI ? Maybe they already have their own product which integrates into the vCloud Director APIs and they didn’t need to do this but for those looking for a free and easy way to create multiple Orgs we showed how easy it was to create 50 new orgs in less than 2 minutes.

Creating 50 new Organizations in less than 2 minutes

The below video was used in the presentation we gave at Partner Exchange, follow through to see the creation of a single Org, User and Org vDC and then how we can create 50 orgs in less than 2 minutes from an Excel spreadsheet:

The Scripts

Below are the scripts and examples we used in the presentation, please note these are not fully formed cmdlets and are shown as examples of how you can use the Get-CIView cmdlet and ExtensionData to create these CI objects, you may need to adjust these functions to perform extra tasks or to work in your CI.

Function New-Org {
    Param (
        $Name,
        $FullName,
        $Description,
        [Switch]$Enabled,
        [Switch]$PublishCatalogs
    )
    Process {
        $vcloud = $DefaultCIServers[0].ExtensionData
       
        $AdminOrg = New-Object VMware.VimAutomation.Cloud.Views.AdminOrg
        $adminOrg.Name = $name
        $adminOrg.FullName = $FullName
        $adminOrg.Description = $description
        $adminOrg.IsEnabled = $Enabled

        $orgSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgSettings
        $orgGeneralSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgGeneralSettings
        $orgGeneralSettings.CanPublishCatalogs = $PublishCatalogs
        $orgSettings.OrgGeneralSettings = $orgGeneralSettings

        $adminOrg.Settings = $orgSettings

        $org = $vcloud.CreateOrg($adminOrg)
        Get-Org -Name $name
    }
}

Function New-CIUser {
    Param (
        $Name,
        $Pasword,
        $FullName,
        [Switch]$Enabled,
        $Org,
        $Role
    )
    Process {
        $OrgED = (Get-Org $Org).ExtensionData
        $orgAdminUser = New-Object VMware.VimAutomation.Cloud.Views.User
        $orgAdminUser.Name = $Name
        $orgAdminUser.FullName = $FullName
        $orgAdminUser.Password = $Pasword
        $orgAdminUser.IsEnabled = $Enabled

        $vcloud = $DefaultCIServers[0].ExtensionData
       
        $orgAdminRole = $vcloud.RoleReferences.RoleReference | where {$_.Name -eq $Role}
        $orgAdminUser.Role = $orgAdminRole
       
        $user = $orgED.CreateUser($orgAdminUser)
        Get-CIUser -Org $Org -Name $Name
    }
}   

Function New-OrgVDC {
    Param (
        $Name,
        [Switch]$Enabled,
        $Org,
        $ProviderVDC,
        $AllocationModel,
        $CPULimit,
        $CPUAllocated,
        $MEMAllocated,
        $MEMLimit,
        $StoraqeLimit
    )
    Process {
        $adminVdc = New-Object VMware.VimAutomation.Cloud.Views.AdminVdc
        $adminVdc.Name = $name
        $adminVdc.IsEnabled = $Enabled
        $providerVdc = Get-ProviderVdc $ProviderVDC
        $providerVdcRef = New-Object VMware.VimAutomation.Cloud.Views.Reference
        $providerVdcRef.Href = $providerVdc.Href
        $adminVdc.ProviderVdcReference =$providerVdcRef
        $adminVdc.AllocationModel = $AllocationModel
        $adminVdc.ComputeCapacity = New-Object VMware.VimAutomation.Cloud.Views.ComputeCapacity
        $adminVdc.ComputeCapacity.Cpu = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
        $adminVdc.ComputeCapacity.Cpu.Units = "MHz"
        $adminVdc.ComputeCapacity.Cpu.Limit = $CPULimit
        $adminVdc.ComputeCapacity.Cpu.Allocated = $CPUAllocated
        $adminVdc.ComputeCapacity.Memory = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
        $adminVdc.ComputeCapacity.Memory.Units = "MB"
        $adminVdc.ComputeCapacity.Memory.Limit = $MEMLimit
        $adminVdc.ComputeCapacity.Memory.Allocated = $MEMAllocated
        $adminVdc.StorageCapacity = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
        $adminVdc.StorageCapacity.Units = "MB"
        $adminVdc.StorageCapacity.Limit = $StorageLimit
       
        $OrgED = (Get-Org $Org).ExtensionData
        $orgVdc = $orgED.CreateVdc($adminVdc)
        Get-OrgVdc $name
    }
}

# Connect to our Cloud Infrastructure
Connect-CIServer vCloud

# Create a new Org
New-Org -Name "PowerCLIRocks" -FullName "PowerCLI Rocks hard!" -description "PowerCLI really rocks hard." -Enabled

# Create a new Administrator for that Org
New-CIUser -Enabled -Name "PowerCLIRocksAdmin" -FullName "PowerCLI Rocks Administrator" `
    -Pasword "Pa$$w0rd" -Org "PowerCLIRocks" -Role "Organization Administrator"

# Create a new Org VDC for that Org
New-OrgVDC -Name "PowerCLIRocksVDC" -Org "PowerCLIRocks"-AllocationModel "AllocationPool" -Enabled `
    -CPUAllocated 500 -CPULimit 1000 -MEMAllocated 1000 -MEMLimit 2000 -ProviderVDC "Bronze" -StorageLimit 1024

# Create all the Urgent Orgs
Import-Csv c:\UrgentWork\UrgentOrgs.csv | Foreach {
    New-Org -Name $_.OrgName -FullName $_.OrgFullName -description $_.OrgDesc -Enabled
}

Get notification of new blog postings and more by following VMware PowerCLI on Twitter: @PowerCLI

PowerCLI at VMworld 2011 (Las Vegas) UPDATE

VSP2296 What everybody ought to know about reporting vSphere and vCloud environment with PowerCLI session has a repetition!

If you haven’t managed to subscribe for it in the first time slot due to the high interest level from the audience, now you have the opportunity to attend the second one on Tuesday 4:30 PM.

All PowerCLI Presentations