Quantcast
Channel: VMware Communities : Popular Discussions - vCloud Director PowerCLI
Viewing all 13334 articles
Browse latest View live

Issues with vCloud Cmdlets when connecting to a CIServer using SessionID

$
0
0

I'm working on a PowerCLI script that deploys vCloud vApps to multiple OvDCs. The script works great when it's serial, but I have been running into issues when trying to get the deployments to run in parallel. It seems that some of the vCloud cmdlets have issues when connection to a CIserver using the SessionID.

 

Connecting to a CI server using the SessionID, like so, works fine.

 

Connect-CIServer -Server $CIServer -SessionID $SessionID

 

But some cmdlets error out with the message "Object reference not set to an instance of an object.". For example:

 

PS>Get-OrgVdc
Get-OrgVdc : 10/21/2012 11:01:11 AM    Get-OrgVdc        Object reference not set to an instance of an object.
At line:1 char:11
+ Get-OrgVdc <<<<
    + CategoryInfo          : NotSpecified: (:) [Get-OrgVdc], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Cloud.Commands.Cmdlets.GetOrgVdc

I also get an odd error when trying to deploy the new vApp regarding not being able to get the results of the task.
PS>$Catalog | Get-CIVAppTemplate -Name $vAppTemplateName | New-CIVApp -Name $vAppName
New-CIVApp : 10/21/2012 11:17:46 AM    New-CIVApp        Could not obtain the result of task '/CIServer=username:orgname@ciserver.com:443/CITask=urn:vcloud:
task:8b2a5b94-7fb7-42f9-b99f-b93c9ad43ab3/'. Task name is 'vdcInstantiateVapp'. The following error occured: Object reference not set to an instance of an object.
At line:1 char:67
+ $Catalog | Get-CIVAppTemplate -Name $vAppTemplateName | New-CIVApp <<<<  -Name $vAppName
    + CategoryInfo          : NotSpecified: (:) [New-CIVApp], VimException
    + FullyQualifiedErrorId : CloudImpl_CITaskServiceProvider_ConvertTaskResult_Failed,VMware.VimAutomation.Cloud.Commands.Cmdlets.NewCIVApp

 

 

It all works correctly when connecting to the CIserver using the normal credential method (i.e. establishing a new session). For the sessionID I am grabbing it from an existing PowerCLI session ($SessionID = $global:DefaultCIServers[0].SessionID).

 

Any insight or thoughts would be great.

 

PowerCLI and vCloud Version  5.1

 

Thanks!

 

Joe


Sample script to modify vApp (Network, Firewall Rules, Start/Stop Order, GuestCustomization)

$
0
0

Hi all

I would like to share a script I developed the last few days.

 

What the script does:

- Add an internal network called "Internal" with NAT/Firewall to a vApp

- Add Firewall rules (f.e. RDP)

- Set the default stop action for every VM within this vApp to "Shutdown" instead of PowerOff

- Enable GuestCustomization for each VM (Enable and SID change, disable all other options like Admin Password)

- Upgrade HW Version to latest (HW9)

 

---------------------------------------------------------------------------------------------------------------------------------------------

 

# Add in the VI Toolkit

if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )

{

Add-PSsnapin VMware.VimAutomation.Core

}

if ( (Get-PSSnapin -Name VMware.VimAutomation.Cloud -ErrorAction SilentlyContinue) -eq $null )

{

Add-PSsnapin VMware.VimAutomation.Cloud

}

 

#Connect to vCloud Cell and vCenter

Connect-CIServer -Server vcloudcell1

Connect-VIServer -Server vcenter1

 

$myOrgInput = Read-Host "Please enter the Organization name:"

$myvAppInput = Read-Host "Please enter the vApp name:"

 

try {

    $myOrg = Get-Org -Name $myOrgInput

} catch {

    [System.Windows.Forms.MessageBox]::Show(“Organization ” + $myOrgInput + " does not exist.",”Org not found.”,0,[System.Windows.Forms.MessageBoxIcon]::Exclamation)

    Exit

}

try {

    $vApps = Get-CIVApp -Name $myvAppInput -Org $myOrg

} catch {

    [System.Windows.Forms.MessageBox]::Show(“vApp ” + $myvAppInput + " does not exist.",”vApp not found”,0,[System.Windows.Forms.MessageBoxIcon]::Exclamation)

    Exit

}

 

foreach ($vApp in $vApps) {

 

    #Get org network

    $NATOrgNetwork = Get-OrgNetwork "My External Org Network" -Org $myOrg

 

    #Add internal network

    New-CIVAppNetwork -ParentOrgNetwork $NATOrgNetwork -VApp $vApp -Routed -DnsSuffix "lab.local" -Gateway "172.20.20.1" -Name "Internal" -Netmask "255.255.255.0" -PrimaryDns "10.1.10.250" -StaticIPPool "172.20.20.100-172.20.20.199"

   

    #Create Firewall Rules

   

    $networkConfigSection = $vApp.ExtensionData.GetNetworkConfigSection()

    $vAppNetwork = $networkConfigSection.NetworkConfig | where {$_.networkName -eq "Internal"}

   

    $fwService = New-Object vmware.vimautomation.cloud.views.firewallservice

    $fwService.DefaultAction = "drop"

    $fwService.LogDefaultAction = $false

    $fwService.IsEnabled = $true

    $fwService.FirewallRule = New-Object vmware.vimautomation.cloud.views.firewallrule

    $fwService.FirewallRule += New-Object vmware.vimautomation.cloud.views.firewallrule

    $fwService.FirewallRule += New-Object vmware.vimautomation.cloud.views.firewallrule

    $fwService.FirewallRule += New-Object vmware.vimautomation.cloud.views.firewallrule

   

    #First Rule - Allow outgoing

    $fwService.FirewallRule[0].isenabled = $true

    $fwService.FirewallRule[0].description = "Outgoing Traffic"

    $fwService.FirewallRule[0].protocols = New-Object vmware.vimautomation.cloud.views.firewallRuleTypeProtocols

    $fwService.FirewallRule[0].protocols.ANY = $true

    $fwService.FirewallRule[0].policy = "allow"

    $fwService.FirewallRule[0].destinationIp = "external"

    $fwService.FirewallRule[0].sourceip = "internal"

   

    #Second Rule - RDP

    $fwService.FirewallRule[1].isenabled = $true

    $fwService.FirewallRule[1].description = "RDP"

    $fwService.FirewallRule[1].protocols = New-Object vmware.vimautomation.cloud.views.firewallRuleTypeProtocols

    $fwService.FirewallRule[1].protocols.Tcp = $true

    $fwService.FirewallRule[1].policy = "allow"

    $fwService.FirewallRule[1].port = "3389"

    $fwService.FirewallRule[1].destinationIp = "internal"

    $fwService.FirewallRule[1].sourceip = "external"

 

    #Third Rule - Ping ICMP

    $fwService.FirewallRule[2].isenabled = $true

    $fwService.FirewallRule[2].description = "PING"

    $fwService.FirewallRule[2].protocols = New-Object vmware.vimautomation.cloud.views.firewallRuleTypeProtocols

    $fwService.FirewallRule[2].protocols.Icmp = $true

    $fwService.FirewallRule[2].policy = "allow"

    $fwService.FirewallRule[2].destinationIp = "internal"

    $fwService.FirewallRule[2].sourceip = "external"

   

    $vAppNetwork.Configuration.Features = $vAppNetwork.Configuration.Features | where {!($_ -is [vmware.vimautomation.cloud.views.firewallservice])}

    $vAppNetwork.configuration.features += $fwService

    $networkConfigSection.UpdateServerData()

   

    #For each VM in the vApp

    $vms = Get-CIVM -VApp $vApp

    foreach ($vm in $vms) {

 

        #Enable guest customization

        $GuestCustomization = $vm.ExtensionData.GetGuestCustomizationSection()

        $GuestCustomization.Enabled = $true

        $GuestCustomization.ChangeSid = $true

        $GuestCustomization.ResetPasswordRequired = $false

        $GuestCustomization.AdminPasswordEnabled = $false

        $GuestCustomization.UpdateServerData()

       

        #Stop Rule -> set to Shutdown

        $myVM2StartRule = Get-CIVAppStartRule -VApp $vApp -VM $vm

        Set-CIVAppStartRule -StartRule $myVM2StartRule -StopAction ShutDown

       

        #Upgrade HW version to latest

        $vsphereVMView = Get-View –RelatedObject $vm.ExtensionData

        $vivm = Get-VIObjectByVIView $vsphereVMView

        $vmview = Get-View -id $vivm.Id

        $param = @($null)

        $vmview.gettype().GetMethod("UpgradeVM_Task").Invoke($vmview,$param)

        }

}

How to delete VMs from vCD via powerCli?

$
0
0

Hello

for test purposes, I frequently have to remove VMs from a vApp in vCloud Director. As I would like to do it 'properly', I do not want to delete the VMs by connecting to a vCenter and run remove-vm.

get-civm ... | remove-vm ... does not work. I get the following message: Cannot validate argument on parameter 'VM'. The argument is null or empty...

 

Any help is appreciated!

Thanks a lot

Uschi

Deleting CIVM from a CIvApp

$
0
0

Hi,

 

I would like to remove a specific CIVM from a CIvApp. The CIvApp is stopped and powered off. The following bit of code works but performance is inconsistent. Sometimes it takes a few seconds, sometimes it takes extremely long to do 1 VM (1min 15 seconds). Even with the PowerCLI XmlSerializers installed. It's more than like it's because I'm using Get-CIVM.

 

Works:

$civapp = "Test"
$civm = Get-CIVM -vApp $civapp -Name "VM1"
$civm.ExtensionData.Delete()

 

 

I've tried using Search-Cloud but it appears I can't do anything with the object once I found it:

No ExtensionData property:

$civm2 = Search-Cloud -QueryType AdminVM -Filter "ContainerName==Test;Name==VM2"

 

I also thought about using Get-CIView and then using RecomposeVApp but I'm not sure what to pass that to delete a VM:

 

$civapp = "Test"
$ciview = "get-ciview -ID $civApp.Id"
$ciview.RecomposeVApp("VM2" ,deleteItem) //Not sure what to do here.

 

 

Or does anyone know of another method to delete CIVM's from a CIvApp via the SDK perhaps? Or maybe those mystical cloud views?


Thanks!

PowerCLI error vCloud Director assigning Org vDC/vApp network to VM

$
0
0

Hello,

I'm working on a script that imports VMs from vCenter into vCloud Director by creating vApps within an Organization's vDC then assigning a network to the VM. The script reads in a lost of VMs, vApp names, Networks, etc. from a CSV file. The network I'm assigning to the VM inside the vApp already exists within the Org vDC's list of Networks. One part of the script adds the specified Org vDC network to the vApp - which works fine. However, when assigning that network to the VM itself, I get this error:

Set-CINetworkAdapter : 01-Aug-18 08:53:10       Set-CINetworkAdapter            The specified parameter 'VAppNetwork' expects a single

value, but your name criteria 'Network v2' corresponds to multiple values.

At C:\ps\scripts\testassignnetwork.ps1:10 char:99

+ ... rkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddres ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-CINetworkAdapter], VimExc

   eption

    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.Clo

   ud.Commands.Cmdlets.SetCINetworkAdapter

 

 

Set-CINetworkAdapter : 01-Aug-18 08:53:10       Set-CINetworkAdapter            CIVAppNetwork parameter: Could not find any of the

objects specified by name.

At C:\ps\scripts\testassignnetwork.ps1:10 char:99

+ ... rkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddres ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...ork VAppNetwork:RuntimePropertyInfo) [Set-CINetworkAd

   apter], ObnRecordProcessingFailedException

    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.Cloud.

   Commands.Cmdlets.SetCINetworkAdapter

 

Here's where I add the existing Org vDC network to the vApp:

Write-Host "`nImporting Org vDC network(s) in the new vApps"

Import-Csv $ImportPath | Foreach-Object {

New-CIVAppNetwork -ParentOrgVdcNetwork (Get-OrgVdc $_.NewOrgvDC | Get-OrgVdcNetwork $_.NewNetwork) -VApp (Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName) -Direct -RunAsync

}

Write-Host -ForegroundColor Green "Done"

Which works perfectly (the CSV file lists two VMs, both going to separate vApps):

Importing Org vDC network(s) in the new vApps

 

Name                           State      % Complete Start Time   Finish Time

----                           -----      ---------- ----------   -----------

vdcUpdateVappNetworkSection    Queued              0 08:52:05 AM

vdcUpdateVappNetworkSection    Queued              0 08:52:10 AM

Done

 

Now I try to assign the VM inside the vApp to the network I just added to the vApp:

Write-Host "`nAssigning vApp networks to the VMs"

Import-Csv $ImportPath | Foreach-Object {

#Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName | Get-CIVM $_.vAppName | Get-CINetworkAdapter | where{$_.MacAddress -eq $_.MAC} | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddressAllocationMode Pool -Connected $true

Get-OrgVdc $_.NewOrgvDC | Get-CIVApp $_.vAppName | Get-CIVM $_.vAppName | Get-CINetworkAdapter | Set-CINetworkAdapter -VAppNetwork $_.NewNetwork -IPaddressAllocationMode Pool -Connected $true

}

Write-Host -ForegroundColor Green "Done"

 

Which results in the error I pasted above (I get both errors twice since the CSV file has two entries). Any idea what's going on? I'd appreciate the help. Thanks.

How to delete external network via powercli?

$
0
0

Hi,

Does anybody know how to  delete an external network via powercli?

 

Thanks in advance,

Marco

External Networks

$
0
0

Does anyone know of a way to create external networks with PowerCLI?

Can I set CIVM name, CIVM computername or other parameters via PowerCLI

$
0
0

Hello!

The main question in topic. I tried this one example:

$VM = get-civm 'centos_template'

($VM.ExtensionData.Section | where {$_ -is [VMware.VimAutomation.Cloud.Views.guestCustomizationSection]}).computername = 'centos'

But it's not working...

I found some useful article how to set some parameters of VM here GeekAfterFive - Infrastructure as Code . Looks like that is possible, but you must know exact section and property. Where can I get this?

 

And the second quiestion.

The performance of requests through the powershell module is a bit sloooow. Is it by design or it depends on performance inside the Vcloud Provider I'm connecting to? In my org connection latency to cloud is ~7ms.

 

Thanks.


How to extract unallocated or free IP addresses in external network pool in vCloud director with powershell

$
0
0

Hi Guys,

 

I have PS command to extract allocated IP address but I need PS command to free IP addresses. We usually have requirement to find and assign one IP address to our clients and it is really cumbersome process to find one IP out of around 2000 IPs

 

I really need to find out free IP addresses.

Updating VMware tools & VMhardware version on VM's in vCloud (8.2) Organization

$
0
0

In our environment we only have access to vcloud organization to manage VM's & wanted to upgrade vmware tools & hardware versions in an automated way.

We don't have any visibility to hypervisor/vSphere/VCD(8.2) . I have tried to search on this but no getting enough information on this .

Please suggest the best way be it manual or via powercli script to do the upgrades.

Powershell to find and delete Stranded Items | vCloud Director 9.1

$
0
0

Hi All.



 

Is there any powershell script to automate the deletion of stranded items in vCloud Director 9.1?



 

Thanks in advance!



 

Alicia T

How can I get a list of vCloud Director active users using Power CLI?

$
0
0

Hi,

 

How can I get a list of vCloud Director active users using Power CLI? Is there a script/command that can get me this info?

 

I have seen a SQL command to get this data as explained here:

VMware Knowledge Base

Determining the list of users logged in to vCloud Director (2034809)

 

But I am looking to get the same/similar info using a script as I need to pipe the info to another tool.

 

Thanks.

 

Peter

How determine if VM in Vcenter (6.7) is Managed by Vcloud Director (9.5)

$
0
0

I used to have a script which connected to Viirtual Center and listed all VMs which are not managed by vcloud director. This worked well for Vcenter 6.5 and vcloudDirector 9.1 using the ManagedBy Attribute in the class VMware.Vim.VirtualMachineConfigInfo
After the Update to 6.7 and 9.5 this was unfortunately changed, and the managedby Attribute is now empty.... does anyone know how to determine between a VM managed by vcloud director and which is not? I cannot find any attribute which contains that part of information.

Export all vCloud Edge Gateway rules to CSV file

$
0
0

Hi,

 

For documenation purposes, I need to make a list of all vCloud firewall rules. Specifically, I am looking for Edge name, Rule ID, name, source, source port, destination, destination port, protocol, action, log, enabled/disabled

 

While I am terrible at any kind of scripting, I believe PowerCLI can accomplish this. Does anyone have a script or know where I can find one to obtain this info?

 

Thanks in advance!

Add a VM to a vApp using PowerShell

$
0
0

Hello,

 

I am trying to add a VM to a vApp using PowerShell.  I know that there is no explicit cmdlet to do it, and I need to recompose the vApp.

 

I've used the great Instantiation script from http://velemental.com/2012/03/27/deploying-a-vapp-in-vcd-from-a-catalog-using-powercli-part-two-the-lab-use-case/ to successfully create vApps, but I need to be able to add additional VMs to the vApp that is created, and don't want to have a huge catalog to accomodate all the various server configurations required for our different vApps.

 

Unfortunately - I am completely failing trying to create a powershell script to recompose a vApp.  I'm trying to start with the basics even, and just call recompose to rename a vApp, and it fails...

 

Does anyone have an example of a recompose script that they have created and can share?

 

If not, I'm juggling a few things and will post my broken script shortly for any assistance...

 

Thanks,

 

Jason


Deleting CIVM from a CIvApp

$
0
0

Hi,

 

I would like to remove a specific CIVM from a CIvApp. The CIvApp is stopped and powered off. The following bit of code works but performance is inconsistent. Sometimes it takes a few seconds, sometimes it takes extremely long to do 1 VM (1min 15 seconds). Even with the PowerCLI XmlSerializers installed. It's more than like it's because I'm using Get-CIVM.

 

Works:

$civapp = "Test"
$civm = Get-CIVM -vApp $civapp -Name "VM1"
$civm.ExtensionData.Delete()

 

 

I've tried using Search-Cloud but it appears I can't do anything with the object once I found it:

No ExtensionData property:

$civm2 = Search-Cloud -QueryType AdminVM -Filter "ContainerName==Test;Name==VM2"

 

I also thought about using Get-CIView and then using RecomposeVApp but I'm not sure what to pass that to delete a VM:

 

$civapp = "Test"
$ciview = "get-ciview -ID $civApp.Id"
$ciview.RecomposeVApp("VM2" ,deleteItem) //Not sure what to do here.

 

 

Or does anyone know of another method to delete CIVM's from a CIvApp via the SDK perhaps? Or maybe those mystical cloud views?


Thanks!

vCloud network allocated addresses

$
0
0

I am looking for some assistance. I am scripting the allocation of IP's for VM's deployed to a org network backed by a specific external network.

 

Currently I am running:

$extnet = get-externalnetwork "externalnetworkname"

 

I then want to get the list of IP's from this network that have been allocated to VM's already:

$AllocatedIps = $extnet.ExtensionData.GetallocatedAddresses().IpAddres.IPAddress

 

I thought this was working, until I started picking up duplicate IP allocations.

It turns out this only returns the first 128 allocated IP addresses. (Currently I have a possible 939 available IP addresses on this external network)

 

How can I return the full list of IP addresses that have already been allocated?

How to delete VMs from vCD via powerCli?

$
0
0

Hello

for test purposes, I frequently have to remove VMs from a vApp in vCloud Director. As I would like to do it 'properly', I do not want to delete the VMs by connecting to a vCenter and run remove-vm.

get-civm ... | remove-vm ... does not work. I get the following message: Cannot validate argument on parameter 'VM'. The argument is null or empty...

 

Any help is appreciated!

Thanks a lot

Uschi

Get-Task Error

$
0
0

Hi,

 

I get the following error running get-task. I seems to display the first 3000 odd tasks but then errors:

 

PS C:\> get-task

jobDelete                      Success           100 11:18:48 AM  11:18:48 AM

jobDisable                     Success           100 11:18:44 AM  11:18:44 AM

jobEnable                      Success           100 11:18:42 AM  11:18:42 AM

jobDisable                     Success           100 11:18:40 AM  11:18:40 AM

commonPurgeDeletedItem         Success           100 11:18:22 AM  11:18:22 AM

vdcDeleteVdc                   Success           100 11:18:22 AM  11:18:22 AM

jobDisable                     Success           100 11:18:17 AM  11:18:17 AM

vdcCreateVdc                   Error             100 11:02:57 AM  11:07:58 AM

jobVcStartConnection           Success           100 10:50:50 AM  10:50:50 AM

rclPrepareHost                 Success           100 10:48:42 AM  10:50:40 AM

jobCrosshostEnable             Success           100 10:50:26 AM  10:50:40 AM

jobInstall                     Success           100 10:48:42 AM  10:50:26 AM

jobVcStartConnection           Success           100 10:50:11 AM  10:50:11 AM

jobVcStartConnection           Success           100 10:50:09 AM  10:50:09 AM

rclPrepareHost                 Error             100 10:46:39 AM  10:48:14 AM

jobInstall                     Error             100 10:46:39 AM  10:48:14 AM

rclPrepareHost                 Error             100 10:44:03 AM  10:45:43 AM

jobInstall                     Error             100 10:44:03 AM  10:45:43 AM

rclPrepareHost                 Success           100 10:41:43 AM  10:43:33 AM

jobCrosshostEnable             Success           100 10:43:17 AM  10:43:33 AM

jobInstall                     Success           100 10:41:43 AM  10:43:17 AM

Get-Task : 5/24/2013 1:54:49 PM    Get-Task        There is an error in XML document (33, 769).

At line:1 char:9

+ get-task <<<<

    + CategoryInfo          : NotSpecified: (:) [Get-Task], VimException

    + FullyQualifiedErrorId : SdkUtil10_ErrorHandledStream_GetWrappedEnumerable,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetTask

 

Is there anyway to trim the amount of tasks in that list? Either via the database or from the vcloud cell. I've tried using Get-Task | select id -First 100 but it still evaluates all values. I must have a corrupt entry?

 

Any ideas?

 

Thanks!

Error when cloning a VM related to vCloud Director

$
0
0

Hey there!

I have the following cmdlet:

 

New-VM -Name ClonedVM -VM SourceVM -Datastore NewDS -VMHost ESXi -Location Folder -Confirm:$false

 

The problem is that I'm trying to clone a VM that is a part of a dead vCD system. Because the VM is registered as being managed by the dead vCD instance, I get the following error:

The operation for the entity ClonedVM failed with the following message: "A general system error occurred: The virtual machine requires the vcloud/system.service.vmware.vsla.vcloud service, which is not available on the host."

So.. is there a way for me to clone that VM using PowerCLI without un-registering and registering the VM in the VC?

Viewing all 13334 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>