VMware Solutions Discussions

VSC Automation

mbeattie
6,944 Views

Hi All,

VSC can be automated using PowerShell to invoke API SOAP requests via web services.

I'm currently writting a function library for VSC4.X to replicate the functionality the previously existed with the Kamino PowerShell Module for VSC2.X.

See example code below, hope this helps to accelerate your development!

<#'-----------------------------------------------------------------------------

'Script Name : vsc.ps1

'Author      : Matthew Beattie

'Email       : mbeattie@netapp.com

'Created     : 04/08/13

'Description : Example of VSC automation using web services API.

'-------------------------------------------------------------------------------

'Functions Section

'-----------------------------------------------------------------------------#>

Function Connect-VSC{

   <#

   .SYNOPSIS

   Connect-VSC Connects to the NetApp (VSC) Virtual Storage Console using web services

   .DESCRIPTION

   Connects to the Virtual Storage Console and returns a connection.

   .PARAMETER

   IPAddress accepts a string containing the VSC IPAddress

   .PARAMETER

   PortNumber Accepts an Integer containing the Port Number the VSC is listening on.

   .EXAMPLE

   Connect-VSC -IPAddress 192.168.0.100 -PortNumber 8143 -Credentials $credentials

   .NOTES

   The Function returns a connection object to the VSC using the Web Services API.

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$IPAddress,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [Int]$PortNumber,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials

   )

   $connection = ""

   #'---------------------------------------------------------------------------

   #'Bypass SSL certificate confirmation

   #'---------------------------------------------------------------------------

   [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}

   #'---------------------------------------------------------------------------

   #'Get the web service proxy object of the SOAP API for the VSC

   #'---------------------------------------------------------------------------

   [String]$uri = "https://$ipAddress`:$portNumber/kamino/public/api?wsdl"

   Try{

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `

      New-WebServiceProxy -uri $uri -Credential $credentials -ErrorAction Stop

   }Catch{

      Write-Host ("Error """ + $Error[0] + """ Connecting to ""$uri""")

      Break;

   }

   Return $connection;

}#End Function

#'------------------------------------------------------------------------------

Function Get-VSCvCenterVersion{

   <#

   .SYNOPSIS

   Get-VCenterVersion enumerates the Virtual Center Version

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      $Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$IPAddress,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials    

   )

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$vcVersion = ""

   [String]$domain    = $credentials.GetNetworkCredential().domain

   [String]$user      = $credentials.GetNetworkCredential().username

   [String]$password  = $credentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Get the object of the namespace

   #'---------------------------------------------------------------------------

   $namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a request  spec from the NameSpace

   #'---------------------------------------------------------------------------

   $requestSpecType = ($namespace + '.requestSpec')

   $requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $ipAddress + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   $vcVersion              = $connection.getVCenterVersion($requestSpec)

   Return $vcVersion;

}#End Function

#'------------------------------------------------------------------------------

Function Get-VSCManagedObjectRef{

   <#

   .SYNOPSIS

   Get-VCenterVersion enumerates the Virtual Center Version

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$IPAddress,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Name,

      [Parameter(Position=3,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Type,

      [Parameter(Position=4,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials    

   )  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$moref     = ""

   [String]$domain    = $credentials.GetNetworkCredential().domain

   [String]$user      = $credentials.GetNetworkCredential().username

   [String]$password  = $credentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $ipAddress + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference based on the object type.

   #'---------------------------------------------------------------------------

   Switch($Type){

   Switch($Type){

      "ClusterComputeResource"{

         [String]$moref = $connection.getMoref($Name, "ClusterComputeResource", $requestSpec)

      }

      "Datacenter"{

         [String]$moref = $connection.getMoref($Name, "Datacenter", $requestSpec)

      }

      "Datastore"{

         [String]$moref = $connection.getMoref($Name, "Datastore", $requestSpec)

      }

      "Folder"{

         [String]$moref = $connection.getMoref($Name, "Folder", $requestSpec)

      }

      "HostSystem"{

         [String]$moref = $connection.getMoref($Name, "HostSystem", $requestSpec)

      }

      "ResourcePool"{

         [String]$moref = $connection.getMoref($Name, "ResourcePool", $requestSpec)

      }

      "VirtualMachine"{

         [String]$moref = $connection.getMoref($Name, "VirtualMachine", $requestSpec)

      }

   }

   Return $moref;

}#End Function

#'------------------------------------------------------------------------------

#'Initialization Section  

#'------------------------------------------------------------------------------

[String]$scriptPath     = Split-Path($MyInvocation.MyCommand.Path)

[String]$scriptSpec     = $MyInvocation.MyCommand.Definition

[String]$scriptBaseName = (Get-Item $scriptSpec).BaseName

#'------------------------------------------------------------------------------

[String]$ipAddress      = "192.168.100.19"

[Int]$portNumber        = 8143

[String]$datacenter     = "Testlab"

[String]$datastore      = "Datastore1"

[String]$username       = "testlab\administrator"

$password               = Read-Host "Please enter the password for user ""$userName""" -AsSecureString

$credentials            = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $password

#'------------------------------------------------------------------------------

#'Connect to the VSC using the web service API.

#'------------------------------------------------------------------------------

Try{

   $connection = Connect-VSC -IPAddress $ipAddress -PortNumber $portNumber -Credentials $credentials -ErrorAction Stop

   Write-Host "Connected to VSC on IPAddress ""$ipAddress"" on Port ""$portNumber"""

}Catch{

   Write-Host "Failed connecting to ""$ipAddress"" on PortNumber ""$portNumber"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the Virtual Center Version.

#'------------------------------------------------------------------------------

Try{

   $vcVersion = Get-VSCvCenterVersion -Connection $connection -IPAddress $ipAddress -Credentials $credentials -ErrorAction Stop

   Write-Host "Enumerated Virtual Center Version as ""$vcVersion"""

}Catch{

   Write-Host "Failed Enumerating Virtual Center Version"

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the Managed Object Reference for the DataCenter object.

#'------------------------------------------------------------------------------

Try{

   [String]$dataCenterMoref = Get-VSCManagedObjectRef -Connection $connection -IPAddress $ipAddress -Name $datacenter -Type "Datacenter" -Credentials $credentials -ErrorAction Stop

   Write-Host "Enumerated Managed Object Reference for ""$datacenter"" as ""$dataCenterMoref"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$datacenter"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the Managed Object Reference for the DataCenter object.

#'------------------------------------------------------------------------------

Try{

   [String]$dataStoreMoref = Get-VSCManagedObjectRef -Connection $connection -IPAddress $ipAddress -Name $datastore -Type "Datastore" -Credentials $credentials

   Write-Host "Enumerated Managed Object Reference for ""$datastore"" as ""$dataStoreMoref"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$datastore"""

   Break;

}

Example output:

Connected to VSC on IPAddress "192.168.100.19" on Port "8143"

Enumerated Virtual Center Version as "5.1.0"

Enumerated Managed Object Reference for "Testlab" as "Datacenter:datacenter-2"

Enumerated Managed Object Reference for "Datastore1" as "Datastore:datastore-16"

Watch this space, i'll be adding to the library of functions. Hope this helps

Cheers Matt

Here is another example of how to invoke methods using the web services API. The following example will resize an NFS datastore

Example output:

Connected to VSC "testvc01" on Port "8143"

Enumerated Managed Object Reference for "datastore1" as "Datastore:datastore-16"

Enumerated Managed Object Reference for "Testlab" as "Datacenter:datacenter-2"

Resizing datastore "Datastore1" to "200GB"

Initiated Resize for datastore "Datastore1". VCenter TaskID "Task:task-262"

#'------------------------------------------------------------------------------

Function Connect-VSC{

   <#

   .SYNOPSIS

   Connect-VSC Connects to the NetApp (VSC) Virtual Storage Console using web services

   .DESCRIPTION

   Connects to the Virtual Storage Console and returns a connection.

   .PARAMETER

   VSCHostName accepts a string containing the NetBIOS Hostname of the VSC server.

   .PARAMETER

   PortNumber Accepts an Integer containing the Port Number the VSC is listening on.

   .EXAMPLE

   Connect-VSC -VSCHostName TESTVC01 -PortNumber 8143 -Credentials $credentials

   .NOTES

   The Function returns a connection object to the VSC using the Web Services API.

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [Int]$PortNumber,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials

   )

   $connection = ""

   #'---------------------------------------------------------------------------

   #'Bypass SSL certificate confirmation

   #'---------------------------------------------------------------------------

   [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}

   #'---------------------------------------------------------------------------

   #'Get the web service proxy object of the SOAP API for the VSC

   #'---------------------------------------------------------------------------

   [String]$uri = "https://$vscIpAddress`:$portNumber/kamino/public/api?wsdl"

   Try{

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `

      New-WebServiceProxy -uri $uri -Credential $credentials -ErrorAction Stop

   }Catch{

      Write-Host ("Error """ + $Error[0] + """ Connecting to ""$uri""")

      Break;

   }

   Return $connection;

}#End Function

#'------------------------------------------------------------------------------

Function Get-VSCManagedObjectRef{

   <#

   .SYNOPSIS

   Get-VCenterVersion enumerates the Virtual Center Version

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Name,

      [Parameter(Position=3,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Type,

      [Parameter(Position=4,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials    

   )  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$moref     = ""

   [String]$domain    = $credentials.GetNetworkCredential().domain

   [String]$user      = $credentials.GetNetworkCredential().username

   [String]$password  = $credentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference based on the object type.

   #'---------------------------------------------------------------------------

   Switch($Type){

   Switch($Type){

      "ClusterComputeResource"{

         [String]$moref = $connection.getMoref($Name, "ClusterComputeResource", $requestSpec)

      }

      "Datacenter"{

         [String]$moref = $connection.getMoref($Name, "Datacenter", $requestSpec)

      }

      "Datastore"{

         [String]$moref = $connection.getMoref($Name, "Datastore", $requestSpec)

      }

      "Folder"{

         [String]$moref = $connection.getMoref($Name, "Folder", $requestSpec)

      }

      "HostSystem"{

         [String]$moref = $connection.getMoref($Name, "HostSystem", $requestSpec)

      }

      "ResourcePool"{

         [String]$moref = $connection.getMoref($Name, "ResourcePool", $requestSpec)

      }

      "VirtualMachine"{

         [String]$moref = $connection.getMoref($Name, "VirtualMachine", $requestSpec)

      }

   }

   Return $moref;

}#End Function

#'------------------------------------------------------------------------------

Function Update-VSCDataStoreSize{

   <#

   .SYNOPSIS

   Resize-VSCDataStore resizes a datastore

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$ControllerHostName,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=3,

         Mandatory=$False,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VFilerHostName,

      [Parameter(Position=4,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Protocol,

      [Parameter(Position=5,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [Bool]$ThinProvision,

      [Parameter(Position=5,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$DataStoreName,

      [Parameter(Position=6,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$DataCenterName,

      [Parameter(Position=7,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [Int]$dataStoreSizeGB,

      [Parameter(Position=8,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$ControllerCredentials,

      [Parameter(Position=9,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$VSCCredentials   

   )

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$domain    = $ControllerCredentials.GetNetworkCredential().domain

   [String]$user      = $ControllerCredentials.GetNetworkCredential().username

   [String]$password  = $ControllerCredentials.GetNetworkCredential().password

   #'---------------------------------------------------------------------------

   #'Set the username for the domain or local user.

   #'---------------------------------------------------------------------------  

   If($domain -ne ""){

      [String]$username  = "$domain\$user"

   }Else{

      [String]$username = $user.Split("\")[0]

   }

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a controllerSpec Object from the NameSpace object and set properties.

   #'---------------------------------------------------------------------------

   [System.Object]$controllerType           = ($namespace + '.controllerspec')

   [System.Object]$controllerSpec           = New-Object ($controllerType)

   [System.Object]$controllerSpec.username  = $username

   [System.Object]$controllerSpec.password  = $password

   [System.Object]$controllerSpec.ipAddress = $ControllerHostName

   [System.Object]$controllerSpec.ssl       = $True

   #[System.Object]$controllerSpec.port     = 443

   #'---------------------------------------------------------------------------

   #'Set the vFiler context if the parameter was parsed to the function

   #'---------------------------------------------------------------------------

   If($VFilerIPAddress -ne $Null){

      [System.Object]$controllerSpec.passthroughContext = $VFilerHostName

   }

   $controllerSpec  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$domain    = $vscCredentials.GetNetworkCredential().domain

   [String]$user      = $vscCredentials.GetNetworkCredential().username

   [String]$password  = $vscCredentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference for the Datastore object.

   #'---------------------------------------------------------------------------

   Try{

      [String]$objectType     = "Datastore"

      [String]$dataStoreMoref = Get-VSCManagedObjectRef -Connection   $connection     `

                                                        -VSCHostName  $vscHostName    `

                                                        -Name         $dataStore      `

                                                        -Type         $objectType     `

                                                        -Credentials  $vscCredentials `

                                                        -ErrorAction  Stop

      Write-Host "Enumerated Managed Object Reference for ""$datastore"" as ""$dataStoreMoref"""

   }Catch{

      Write-Host "Failed Enumerating Managed Object Reference for ""$datastore"""

      Break;

   }

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference for the DataCenter object.

   #'---------------------------------------------------------------------------  

   Try{  

      [String]$objectType      = "Datacenter"

      [String]$dataCenterMoref = Get-VSCManagedObjectRef -Connection   $connection     `

                                                         -VSCHostName  $vscHostName    `

                                                         -Name         $dataCenter     `

                                                         -Type         $objectType     `

                                                         -Credentials  $vscCredentials `

                                                         -ErrorAction  Stop

      Write-Host "Enumerated Managed Object Reference for ""$dataCenter"" as ""$dataCenterMoref"""

   }Catch{

      Write-Host "Failed Enumerating Managed Object Reference for ""$dataCenter"""

      Break;

   }

   #>

   #'---------------------------------------------------------------------------

   #'Create a dataStoreSpec Object from the NameSpace object and set properties.

   #'---------------------------------------------------------------------------  

   [System.Object]$dataStoreType                   = ($namespace + '.datastorespec')

   [System.Object]$dataStoreSpec                   = New-Object ($dataStoreType)

   [System.Object]$dataStoreSpec.controller        = $controllerSpec

   [System.Object]$dataStoreSpec.thinProvision     = $thinProvision

   [System.Object]$dataStoreSpec.Protocol          = $protocol.ToUpper();

   [System.Object]$dataStoreSpec.protocolSpecified = $True

   [System.Object]$dataStoreSpec.numDatastores     = 1

   [System.Object]$dataStoreSpec.sizeInMB          = ($dataStoreSizeGB * 1024)

   [System.Object]$dataStoreSpec.sizeInMBSpecified = $True

   [System.Object]$dataStoreSpec.datastoreNames    = $dataStoreName

   [System.Object]$dataStoreSpec.mor               = $dataStoreMoref

   [System.Object]$dataStoreSpec.targetMor         = $dataCenterMoref

   [System.Object]$dataStoreSpec.wrapperVol        = $True

   #'---------------------------------------------------------------------------

   #'Invoke the ResizeDataStore Method.

   #'---------------------------------------------------------------------------

   [String]$taskID = ""

   Trap [System.Management.Automation.MethodInvocationException]{

      Write-Host ("Error " + $_ + " Resizing datastore ""$dataStoreName""") Stop

   }

   Write-Host "Resizing datastore ""$dataStoreName"" to ""$dataStoreSizeGB`GB"""

   [String]$task   = $connection.ResizeDatastore($dataStoreSpec, $requestSpec)

   [String]$taskID = $task.SubString($task.LastIndexOf(" ") + 1)

   Return $taskID;

}#End Function

#'------------------------------------------------------------------------------

#'Initialization Section  

#'------------------------------------------------------------------------------

[String]$scriptPath     = Split-Path($MyInvocation.MyCommand.Path)

[String]$scriptSpec     = $MyInvocation.MyCommand.Definition

[String]$scriptBaseName = (Get-Item $scriptSpec).BaseName

#'------------------------------------------------------------------------------

#'Prompt for storage credentials.

#'------------------------------------------------------------------------------

[String]$username = "root"

[System.Security.SecureString]$password = `

Read-Host "Please enter the password for user ""$username""" -AsSecureString

[System.Management.Automation.PSCredential]$controllerCredentials = `

New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password

#'------------------------------------------------------------------------------

#'Prompt for VSC credentials.

#'------------------------------------------------------------------------------

[String]$username = "testlab\administrator"

[System.Security.SecureString]$password = `

Read-Host "Please enter the password for user ""$username""" -AsSecureString

[System.Management.Automation.PSCredential]$vscCredentials = `

New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password

#'------------------------------------------------------------------------------

#'Set variables.

#'------------------------------------------------------------------------------

[String]$controllerHostName  = "testns01"

[String]$vFilerHostName      = "testnv01"

[String]$vscHostName         = "testvc01"

[Int]$portNumber             = 8143

[String]$protocol            = "nfs"

[Int]$dataStoreSizeGB        = 200

[String]$dataCenterName      = "Testlab"

[String]$dataStoreName       = "Datastore1"

#'------------------------------------------------------------------------------

#'Connect to the VSC using the web services API.

#'------------------------------------------------------------------------------

Try{

   [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `

   Connect-VSC -VSCHostName  $vscHostName    `

               -PortNumber   $portNumber     `

               -Credentials  $vscCredentials `

               -ErrorAction  Stop

   Write-Host "Connected to VSC ""$vscHostName"" on Port ""$portNumber"""

}Catch{

   Write-Host "Failed connecting to ""$vscHostName"" on PortNumber ""$portNumber"""

   Break;

}

#'------------------------------------------------------------------------------

#'Resize the datastore.

#'------------------------------------------------------------------------------

Try{

   [String]$taskID = Update-VSCDataStoreSize -Connection            $connection            `

                                             -ControllerHostName    $controllerHostName    `

                                             -VSCHostName           $vscHostName           `

                                             -VFilerHostName        $vFilerHostName        `

                                             -Protocol              $protocol              `

                                             -ThinProvision         $True                  `

                                             -DataStoreName         $dataStoreName         `

                                             -DataCenterName        $dataCenterName        `

                                             -DataStoreSizeGB       $dataStoreSizeGB       `

                                             -ControllerCredentials $controllerCredentials `

                                             -VSCCredentials        $vscCredentials

   [String]$taskID = $taskID.SubString($taskID.LastIndexOf(" ") + 1)

   Write-Host "Datastore ""$dataStoreName"" resized. VCenter TaskID ""$taskID"""

}Catch{

   Write-Host "Failed Resizing datastore ""$dataStoreName"""

   Break;

}

#'------------------------------------------------------------------------------

Here is another example that demonstrates how to create rapid clones using the "CreateClones" method of Kamino web services API

Example output:

Connected to VSC "testvc01" on Port "8143"
Enumerated Managed Object Reference for "Datastore1" as "Datastore:datastore-16"
Enumerated Managed Object Reference for "testxp01" as "VirtualMachine:vm-17"
Enumerated Managed Object Reference for "Testlab" as "Datacenter:datacenter-2"
Enumerated Virtual Machine Files for template "testxp01"
Initiating Rapid Clones
Initiated Rapid clones. VCenter TaskID "Task:task-308"

See code below. Hope this helps

<#'-----------------------------------------------------------------------------

'Script Name : CreateClones.ps1  

'Author      : Matthew Beattie

'Email       : mbeattie@netapp.com

'Created     : 07/08/13

'Description : This script provides and example of creating rapid clones by

'            : invoking the "CreateClones" method of the kamino API

'            : using web services.

'-------------------------------------------------------------------------------

'Functions Section  

'-----------------------------------------------------------------------------#>

Function Connect-VSC{

   <#

   .SYNOPSIS

   Connect-VSC Connects to the NetApp (VSC) Virtual Storage Console using web services

   .DESCRIPTION

   Connects to the Virtual Storage Console and returns a connection.

   .PARAMETER

   VSCHostName accepts a string containing the NetBIOS Hostname of the VSC server.

   .PARAMETER

   PortNumber Accepts an Integer containing the Port Number the VSC is listening on.

   .EXAMPLE

   Connect-VSC -VSCHostName TESTVC01 -PortNumber 8143 -Credentials $credentials

   .NOTES

   The Function returns a connection object to the VSC using the Web Services API.

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [Int]$PortNumber,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials

   )

   $connection = ""

   #'---------------------------------------------------------------------------

   #'Bypass SSL certificate confirmation

   #'---------------------------------------------------------------------------

   [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}

   #'---------------------------------------------------------------------------

   #'Get the web service proxy object of the SOAP API for the VSC

   #'---------------------------------------------------------------------------

   [String]$uri = "https://$vscHostName`:$portNumber/kamino/public/api?wsdl"

   Try{

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `

      New-WebServiceProxy -uri $uri -Credential $credentials -ErrorAction Stop

   }Catch{

      Write-Host ("Error """ + $Error[0] + """ Connecting to ""$uri""")

      Break;

   }

   Return $connection;

}#End Function

#'------------------------------------------------------------------------------

Function Get-VSCManagedObjectRef{

   <#

   .SYNOPSIS

   Get-VCenterVersion enumerates the Virtual Center Version

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Name,

      [Parameter(Position=3,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$Type,

      [Parameter(Position=4,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials    

   )  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$moref     = ""

   [String]$domain    = $credentials.GetNetworkCredential().domain

   [String]$user      = $credentials.GetNetworkCredential().username

   [String]$password  = $credentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference based on the object type.

   #'---------------------------------------------------------------------------

   Switch($Type){

      "ClusterComputeResource"{

         [String]$moref = $connection.getMoref($Name, "ClusterComputeResource", $requestSpec)

      }

      "Datacenter"{

         [String]$moref = $connection.getMoref($Name, "Datacenter", $requestSpec)

      }

      "Datastore"{

         [String]$moref = $connection.getMoref($Name, "Datastore", $requestSpec)

      }

      "Folder"{

         [String]$moref = $connection.getMoref($Name, "Folder", $requestSpec)

      }

      "HostSystem"{

         [String]$moref = $connection.getMoref($Name, "HostSystem", $requestSpec)

      }

      "ResourcePool"{

         [String]$moref = $connection.getMoref($Name, "ResourcePool", $requestSpec)

      }

      "VirtualMachine"{

         [String]$moref = $connection.getMoref($Name, "VirtualMachine", $requestSpec)

      }

   }

   Return $moref;

}#End Function

#'------------------------------------------------------------------------------

Function Get-VSCVMFiles{

   <#

   .SYNOPSIS

   Get-VCenterVersion enumerates the Virtual Center Version

   #>

   Param(

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VirtualMachineName,

      [Parameter(Position=3,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials    

   )  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$domain    = $credentials.GetNetworkCredential().domain

   [String]$user      = $credentials.GetNetworkCredential().username

   [String]$password  = $credentials.GetNetworkCredential().password

   [String]$username  = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   #'---------------------------------------------------------------------------

   #'Enumerate the Managed Object Reference based on the object type.

   #'---------------------------------------------------------------------------

   $files = ""

   $files = $connection.getVMFiles($VirtualMachineName, $requestSpec)

   Return $files;

}#End Function

#'------------------------------------------------------------------------------

Function Start-VSCClones{

   <#

   .SYNOPSIS

   Start-VSCClone Invokes the CreateClones Method of the Web Services API.

   .DESCRIPTION

   Creates Rapid Clones using the VSC web services API.

   .PARAMETER

   Connection Accepts a web services object containing a connection the VSC web services API.

   .PARAMETER

   VSCHostName Accepts a String containing the NetBIOS hostname of the VSC Server.

   .PARAMETER

   CloneSpec Accepts a web services object containing the clone configuration to invoke.

   .EXAMPLE

   Start-VSCClones -Connection $connection -VSCHostName "testvc01" -CloneSpec $cloneSpec -Credentials $credentials

   #>

   Param(

  

      [Parameter(Position=0,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Web.Services.Protocols.SoapHttpClientProtocol]$Connection,

     

      [Parameter(Position=1,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [String]$VSCHostName,

     

      [Parameter(Position=2,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Object]$CloneSpec,

     

      [Parameter(Position=3,

         Mandatory=$True,

         ValueFromPipeLine=$True,

         ValueFromPipeLineByPropertyName=$True)]

      [System.Management.Automation.PSCredential]$Credentials      

   )  

   #'---------------------------------------------------------------------------

   #'Enumerate the username and password from the credential object.

   #'---------------------------------------------------------------------------

   [String]$domain   = $credentials.GetNetworkCredential().domain

   [String]$user     = $credentials.GetNetworkCredential().username

   [String]$password = $credentials.GetNetworkCredential().password

   [String]$username = "$domain\$user"

   #'---------------------------------------------------------------------------

   #'Create a namespace object from the connection object

   #'---------------------------------------------------------------------------

   [System.Object]$namespace = $connection.GetType().Namespace

   #'---------------------------------------------------------------------------

   #'Create a requestspec Object from the NameSpace object

   #'---------------------------------------------------------------------------

   [System.Object]$requestSpecType = ($namespace + '.requestSpec')

   [System.Object]$requestSpec     = New-Object ($requestSpecType)

   #'---------------------------------------------------------------------------

   #'Set the properties of the RequestSpec object.

   #'---------------------------------------------------------------------------

   $requestSpec.serviceUrl = "https://" + $vscHostName + "/sdk"

   $requestSpec.vcUser     = $username

   $requestSpec.vcPassword = $password

   $requestSpec.CloneSpec  = $cloneSpec

   #'---------------------------------------------------------------------------

   #'Invoke the CreateClones Method.

   #'---------------------------------------------------------------------------

   [String]$taskID = ""

   Trap [System.Management.Automation.MethodInvocationException]{

      Write-Host ("Error " + $_ + " Initiating Rapid Clones") Stop

   }

   Write-Host "Initiating Rapid Clones"

   [String]$task   = $connection.CreateClones($requestSpec)

   [String]$taskID = $task.SubString($task.LastIndexOf(" ") + 1)

   Return $taskID;

   Return $taskId;

}#End Function

#'------------------------------------------------------------------------------

#'Initialization Section  

#'------------------------------------------------------------------------------

[String]$scriptPath     = Split-Path($MyInvocation.MyCommand.Path)

[String]$scriptSpec     = $MyInvocation.MyCommand.Definition

[String]$scriptBaseName = (Get-Item $scriptSpec).BaseName

#'------------------------------------------------------------------------------

#'Prompt for storage credentials.

#'------------------------------------------------------------------------------

[String]$username = "root"

[System.Security.SecureString]$password = `

Read-Host "Please enter the password for user ""$username""" -AsSecureString

[System.Management.Automation.PSCredential]$controllerCredentials = `

New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password

#'------------------------------------------------------------------------------

#'Prompt for VSC credentials.

#'------------------------------------------------------------------------------

[String]$username = "testlab\administrator"

[System.Security.SecureString]$password = `

Read-Host "Please enter the password for user ""$username""" -AsSecureString

[System.Management.Automation.PSCredential]$vscCredentials = `

New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password

#'------------------------------------------------------------------------------

#'Set variables.

#'------------------------------------------------------------------------------

[String]$controllerHostName  = "testns01"

[String]$vFilerHostName      = "testnv01"

[String]$vscHostName         = "testvc01"

[String]$esxHostName         = "testesx1.testlab.local"

[Int]$portNumber             = 8143

[String]$dataCenterName      = "Testlab"

[String]$dataStoreName       = "Datastore1"

[String]$templateName        = "testxp01"

[String]$folderName          = "netapp_rapid_clones"

[String]$customizationName   = "test1"

[Array]$cloneNames           = @("testxp10","testxp11","testxp13","testxp14","testxp15")

[Bool]$powerOn               = $False

#'------------------------------------------------------------------------------

#'Connect to the VSC using the web services API.

#'------------------------------------------------------------------------------

Try{

   [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `

   Connect-VSC -VSCHostName  $vscHostName    `

               -PortNumber   $portNumber     `

               -Credentials  $vscCredentials `

               -ErrorAction  Stop

   Write-Host "Connected to VSC ""$vscHostName"" on Port ""$portNumber"""

}Catch{

   Write-Host "Failed connecting to ""$vscHostName"" on PortNumber ""$portNumber"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the managed object reference for the template to clone.

#'------------------------------------------------------------------------------

Try{  

   [String]$objectType     = "Datastore"

   [String]$dataStoreMoref = Get-VSCManagedObjectRef -Connection   $connection     `

                                                     -VSCHostName  $vscHostName    `

                                                     -Name         $dataStoreName  `

                                                     -Type         $objectType     `

                                                     -Credentials  $vscCredentials `

                                                     -ErrorAction  Stop

   Write-Host "Enumerated Managed Object Reference for ""$dataStoreName"" as ""$dataStoreMoref"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$dataStoreMoref"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the managed object reference for the template to clone.

#'------------------------------------------------------------------------------

Try{  

   [String]$objectType    = "VirtualMachine"

   [String]$templateMoref = Get-VSCManagedObjectRef -Connection   $connection     `

                                                    -VSCHostName  $vscHostName    `

                                                    -Name         $templateName   `

                                                    -Type         $objectType     `

                                                    -Credentials  $vscCredentials `

                                                    -ErrorAction  Stop

   Write-Host "Enumerated Managed Object Reference for ""$templateName"" as ""$templateMoref"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$templateName"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the managed object reference for the clone destination folder.

#'------------------------------------------------------------------------------

Try{

   [String]$objectType  = "Datacenter"

   [String]$targetMoref = Get-VSCManagedObjectRef -Connection   $connection     `

                                                  -VSCHostName  $vscHostName    `

                                                  -Name         $dataCenterName `

                                                  -Type         $objectType     `

                                                  -Credentials  $vscCredentials `

                                                  -ErrorAction  Stop

   Write-Host "Enumerated Managed Object Reference for ""$esxHostName"" as ""$targetMoref"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$esxHostName"""

   Break;

}

#'------------------------------------------------------------------------------

#'Enumerate the files for the source virtual machine template

#'------------------------------------------------------------------------------

Try{

   $files = Get-VSCVMFiles -Connection         $connection       `

                           -VSCHostName        $vscHostName      `

                           -VirtualMachineName $templateMoref `

                           -Credentials        $vscCredentials   `

                           -ErrorAction Stop

   Write-Host "Enumerated Virtual Machine Files for template ""$templateName"""

}Catch{

   Write-Host "Failed Enumerating Managed Object Reference for ""$templateName"""

   Break;

}

#'---------------------------------------------------------------------------

#'Create a requestspec Object from the NameSpace object

#'---------------------------------------------------------------------------

[System.Object]$namespace          = $connection.GetType().Namespace

#'---------------------------------------------------------------------------

#'Enumerate the username and password from the controller credential object.

#'---------------------------------------------------------------------------

[String]$domain    = $ControllerCredentials.GetNetworkCredential().domain

[String]$user      = $ControllerCredentials.GetNetworkCredential().username

[String]$password  = $ControllerCredentials.GetNetworkCredential().password

#'---------------------------------------------------------------------------

#'Ensure the username is correct if a local user was specified.

#'---------------------------------------------------------------------------  

If($domain -ne ""){

   [String]$username  = "$domain\$user"

}Else{

   [String]$username = $user.Split("\")[0]

}

#'---------------------------------------------------------------------------

#'Create a controllerSpec Object from the NameSpace object and set properties.

#'---------------------------------------------------------------------------

[System.Object]$controllerType                    = ($namespace + '.controllerspec')

[System.Object]$controllerSpec                    = New-Object ($controllerType)

[System.Object]$controllerSpec.username           = $username

[System.Object]$controllerSpec.password           = $password

#'------------------------------------------------------------------------------

#'Set controller IP address (cloning only works via IP even with DNS A & PTR)

#'------------------------------------------------------------------------------

[System.Object]$controllerSpec.ipAddress          = "192.168.100.22" #$controllerHostName

[System.Object]$controllerSpec.passthroughContext = $vFilerHostName

[System.Object]$controllerSpec.ssl                = $True

#[System.Object]$controllerSpec.port              = 443

#'------------------------------------------------------------------------------

#'Set the destination controller and datastore for the files.

#'------------------------------------------------------------------------------

ForEach($file In $files){

   $file.destDatastoreSpec.controller = $controllerSpec;

}

#'------------------------------------------------------------------------------

#'Create a cloneSpec Object from the NameSpace object and set properties.

#'------------------------------------------------------------------------------

[System.Object]$cloneSpecType            = ($namespace + '.cloneSpec')

[System.Object]$cloneSpec                = New-Object ($cloneSpecType)

[System.Object]$cloneSpec.templateMoref  = $templateMoref;

[System.Object]$cloneSpec.containerMoref = $targetMoref;

#'------------------------------------------------------------------------------

#'Create objects for each clone and set their properties.

#'------------------------------------------------------------------------------

[Array]$clones = @()

For($i = 0; $i -le ($cloneNames.Count -1); $i++){

   #'---------------------------------------------------------------------------

   #'Create a vmSpec Object from the NameSpace object and set properties.

   #'---------------------------------------------------------------------------

   [System.Object]$vmSpecType         = ($namespace + '.vmSpec')

   [System.Object]$vmSpec             = New-Object ($vmSpecType)

   #'---------------------------------------------------------------------------

   #'Create a cloneSpecEntry Object from the NameSpace object and set properties.

   #'---------------------------------------------------------------------------

   [System.Object]$cloneSpecEntryType = ($namespace + '.cloneSpecEntry')

   [System.Object]$cloneSpecEntry     = New-Object ($cloneSpecEntryType)

   #'---------------------------------------------------------------------------

   #'Create a guestCustomizationSpecType Object from the NameSpace object and set properties.

   #'See the following VMWare KB before you apply a customization!

   #'http://kb.vmware.com/kb/1005593 (Sysprep files must be the correct version in correct location!)

   #'---------------------------------------------------------------------------

   [System.Object]$guestCustomizationSpecType  = ($namespace + '.guestCustomizationSpec')

   [System.Object]$guestCustomizationSpec      = New-Object ($guestCustomizationSpecType)

   [System.Object]$guestCustomizationSpec.Name = $customizationName

   [System.Object]$vmSpec.powerOn              = $powerOn

   [System.Object]$vmSpec.custSpec             = $guestCustomizationSpec

   [System.Object]$cloneSpecEntry.key          = $cloneNames[$i]

   [System.Object]$cloneSpecEntry.Value        = $vmSpec

   [Array]$clones                             += $cloneSpecEntry

   #'---------------------------------------------------------------------------

   #'Set the destination controller and datastore for the files.

   #'------------------------------------------------------------------------------

   ForEach($file In $files){

      $file.destDatastoreSpec.controller = $controllerSpec;

      $file.destDatastoreSpec.mor        = $dataStoreMoref;

   }  

}

#'------------------------------------------------------------------------------

#'Set the properties of the cloneSpec Object.

#'------------------------------------------------------------------------------

[System.Object]$cloneSpec.files  = $files

[System.Object]$cloneSpec.clones = $clones

#'------------------------------------------------------------------------------

#'Initiate the Rapid clone task for the Even Numbered Clones.

#'------------------------------------------------------------------------------

Try{

   [String]$taskId = Start-VSCClones -Connection $connection      `

                                     -VSCHostName $vscHostName    `

                                     -CloneSpec $cloneSpec        `

                                     -Credentials $vscCredentials `

                                     -ErrorAction Stop

   [String]$taskId = $taskId.SubString($taskId.LastIndexOf(" ") + 1)

   Write-Host "Initiated Rapid clones. VCenter TaskID ""$taskId"""

}Catch{

   Write-Host "Failed Initiating rapid clones"

   Break;

}

#'------------------------------------------------------------------------------

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
5 REPLIES 5

SCOTTS2012
6,810 Views

Hi,

Can the above script be modified to perform a Redeploy instead of Create Clones? Have tried to modify this but cannot get it to work. If you could provide an example script on how this can be achieved I would be very grateful.

Thank you,

Scott S.

mbeattie
6,810 Views

Hi Scott,

I understand what you're trying to do based on your post here:

https://communities.netapp.com/message/121856

In theory this should be possible as the VSC supports a "RedeployVMs" API method. EG:

#'------------------------------------------------------------------------------
[String]$ipAddress      = "192.168.100.19" #also works with FQDN EG: “testvc01.testlab.local”
[Int]$portNumber        = 8143
[String]$username       = "testlab\administrator"
$password               = Read-Host "Please enter the password for user ""$userName""" -AsSecureString
$credentials            = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $password
#'------------------------------------------------------------------------------
#'Connect to the VSC using the web service API.
#'------------------------------------------------------------------------------
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}
[String]$uri = "https://$ipAddress`:$portNumber/kamino/public/api?wsdl"
Try{
   [System.Web.Services.Protocols.SoapHttpClientProtocol]$connection = `
   New-WebServiceProxy -uri $uri -Credential $credentials -ErrorAction Stop
   Write-Host "Connected to VSC on IPAddress ""$ipAddress"" on Port ""$portNumber"""
}Catch{
   Write-Host ("Error """ + $Error[0] + """ Connecting to ""$uri""")
   Break;
}

PS C:\> $connection.redeployVMs

MemberType          : Method
OverloadDefinitions : {string redeployVMs(Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServic
                      eProxy119_8143_kamino_public_api_wsdl.requestSpec arg0, Microsoft.PowerShell.Commands.NewWebservi
                      ceProxy.AutogeneratedTypes.WebServiceProxy119_8143_kamino_public_api_wsdl.controllerSpec[] arg1)}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : string redeployVMs(Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebService
                      Proxy119_8143_kamino_public_api_wsdl.requestSpec arg0, Microsoft.PowerShell.Commands.NewWebservic
                      eProxy.AutogeneratedTypes.WebServiceProxy119_8143_kamino_public_api_wsdl.controllerSpec[] arg1)
Name                : redeployVMs
IsInstance          : True

Having issues getting it working in my lab, might take me some time to figure out.

Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mbeattie
6,810 Views

Hi Scott,

Posted the solution in your origonal thread here:

https://communities.netapp.com/message/121856

Cheers Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

CHANDLERBING02
6,810 Views

Hi, I have a list of non contiguous computer names in a text file.  They all use the same VM Template.  How can i use powershell to take the text file as an argument and use VSC to rapidly provision the machines in the list? 

mbeattie
6,810 Views

Hi,

Use the get-content cmdlet to read the list of hostnames from the text file instead of hardcoding the hostnames in the array. The example below assumes you will save the hostnames.txt file in the same directory as the script.

Cheers Matt

#'------------------------------------------------------------------------------

#'Initialization Section

#'------------------------------------------------------------------------------

[String]$scriptPath     = Split-Path($MyInvocation.MyCommand.Path)

[String]$scriptSpec     = $MyInvocation.MyCommand.Definition

[String]$scriptBaseName = (Get-Item $scriptSpec).BaseName 

#'------------------------------------------------------------------------------

#'Read the hostnames from the text file instead of hardcoding them into an array

#'------------------------------------------------------------------------------

[String]$fileSpec   = "$scriptPath\hostnames.txt"

#[Array]$cloneNames = @("testxp10","testxp11","testxp13","testxp14","testxp15")

[Array]$cloneNames  = Get-Content -Path $fileSpec

#'------------------------------------------------------------------------------

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public