Add VM inventory with PowerCLI

Can someone tell me how I can just add 1 VM inventory in vCenter?

I found a bunch of big scripts, but they seem excessive.

Thank you

Scott

Do you mean create a new virtual machine?

This can be done with the New-VM cmdlet.

Or do you mean saving a VM from the .vmx file?

My post of Raiders of the lost VMX has a script for this.

Tags: VMware

Similar Questions

  • How can I get the version of VMware to virtual machines with powercli officer?

    How can I get the version of VMware View Agent running on a virtual machine with powercli or view Powercli?

    As much as I know there is no cmdlet PowerCLI for this, but you can use the Invoke-VMScript cmdlet and interrogate the Win32_Product class.

    By running the following. You can add a Where clause to return only the Agent of the view

    Get-WmiObject-class Win32_Product | Select the name, Version

  • Unable to connect to vCD with PowerCLI

    Hi, can you help me with troubleshooting problem with connecting in vCD using PowerCLI.

    When I log in using my system administrator account

    Connect-CIServer vcdCell01 - User "username-password"pass"

    I get:

    Connect-CIServer: 11/30/2015 connect 12:19:21 AM-CIServer the

    Server returned "Unauthorized" with the status of the authorized 401 - no code.

    On line: 1 char: 1

    + Connect CIServer vcdCell01 - User "username-password 'pass' '.

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

    + CategoryInfo: NotSpecified: (:)) [connect-CIServer], CIException)

    + FullyQualifiedErrorId: Cloud_ConnectivityServiceImpl_ConnectCloudServer

    _ConnectError, VMware.VimAutomation.Cloud.Commands.cmdlets.ConnectCIServer

    I can connect to the Web user interface using the same system administrator account.

    The only way I can connect with PowerCLI is when I create the local account in one of the organizations and Add - Org to order

    Connect-CIServer vcdCell01-user "localuser" - password 'localpass' - 'org' Org

    Help, please.

    I used a few tricks of Python to connect to vCD. To connect as a system administrator, I had to use "Administrator@System" as the user.

    Maybe it will work for you if you use '-Org system?

  • in bulk license with PowerCLI 6.0 Release 2 broken?

    Hello

    I upgraded successfully to PowerCLI 6.0 Release 1 to PowerCLI 6.0 Release 2.

    After that, I wanted to add a new license to the license in bulk newly deployed ESXi Hosts with Auto deploy but encountered the following error:

    $licenseData = new-Object VMware.VimAutomation.License.Types.LicenseData

    New-Object: cannot find type [VMware.VimAutomation.License.Types.LicenseData]: check that the assembly containing this type is loaded.

    On line: 1 char: 16

    + $licenseData = new-Object VMware.VimAutomation.License.Types.LicenseData

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

    + CategoryInfo: InvalidType: (:)) [New-Object], PSArgumentException)

    + FullyQualifiedErrorId: TypeNotFound, Microsoft.PowerShell.Commands.NewObjectCommand

    I'm sure that it worked with PowerCLI 6.0 Release 1.

    Did someone else run into it as well? Perhaps no work around?

    I appreciate your help.

    see you soon,

    Ronny

    Hello

    It is a backward compatibility problem that was introduced in PowerCLI 6.0R2. It will be addressed in a version of the next patch very soon, but until then, you can work around

    replacement of

    'VMware.VimAutomation.License.Types.LicenseData '.

    with

    'VMware.VimAutomation.License.Types.V1.LicenseData '.

    Keep in mind that if you do the above to make your script works and later upgrade your PowerCLI to a version more recent that you should check back this change in scripts.

    -Dimitar Milov

  • Average throughput of the network to a virtual machine with PowerCLI

    I would get average network throughput for a virtual machine with PowerCLI including all e-cards, the virtual machine has for the last week (not including NFS or storage of traffic-related).

    How best should add this report:

    Get - vm myvm | Select name, numcpu

    Thank you!

    Try like this

    Get-VM | Select Name, @{N="Avg Network Throughput MBPs";E={    [math]::Round((Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Stat "net.throughput.usage.average" |    where {$_.Instance -eq ""} |    Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1KB,2)}}
    

    The script takes the aggregate value for all NICs for (the one where the Instance is an empty string).

    Then we take the average and converts the Kbps, Mbps.

  • Parameter of LVM. EnableResignature problem with PowerCLI vpshere 5.1 and 5.1 U2 Powercli

    Use us SRM and you want to make sure that when done with test that the LVM. EnableResignature is set to return 0 since move us hosts often. I tried 2 different ways to do it and they both fail with "a specified parameter was not correct", all examples I see online are for esx 4.x and below, I didn't know someone check this in 5.x.  We are 5.1U1 and latest powercli.

    Any help would be greatly appreciated.

    Method 1:

    $vh contains the name of the host to be reset:

    If ((Get-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature). Values - not 0) {}

    Game-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature-value 0 - confirm: $false

    }

    Method 2:

    Borrow the code for the functions I've seen online:

    If ((Get-VMHostAdvancedConfiguration - vmhost $vh - name of LVM. EnableResignature). Values - not 0) {}

    $esx = get-View (Get-VMHost $vh) USER.USER
    $optmgrMoRef = $esx.configManager.advancedOption
    $optmgr = get-views $optmgrMoRef

    $optarray = $optmgr. QueryOptions ("LVM. EnableResignature")
    $optarray [0]. Value = 0
    $optmgr. UpdateOptions ($optarray)

    }

    It seems as if the function of 9 Re: LVM/EnableResignature value = 1 with PowerCLI on ESX 4.1  

    work on 5.1 as well

    Function Set-VMHostResignature {}

    [CmdletBinding()]

    (Param

    [(Setting)

    Mandatory = $True,.

    ValueFromPipeline = $True

    )]

    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl []] $VMHost,.

    [(Setting)

    Mandatory = $True,.

    Position = 0

    )]

    [ValidateSet (0, 1)]

    [long] $Value

    )

    Begin {}

    $Option = new-Object Vmware.Vim .optionvalue - property @ {}

    Key = "LVM. EnableResignature ".

    Value = $Value

    }

    $OptionArray = $Option

    }

    {In process

    $VMHost | {ForEach-Object

    $ESX = get-view $_.ID

    $OptMgr = get - see $ESX. ConfigManager.AdvancedOption

    $OptMgr.UpdateOptions ($OptionArray)

    }

    }

    }

    Get-VMHost | Game-VMHostResignature-value 1

  • Complete the VI Client with PowerCLI Script idle Sessions

    Hello gurus PowerCLI

    I searched the net for a script PowerCLI that would end all the VI client sessions that have been inactive for x period of time.  I found a post on the forums of VMware (http://communities.vmware.com/message/914858?z=zI0r8n) but had no luck with it.  I also found a script created by A.Mikkelsen, to http://www.amikkelsen.com/?p=384 , but that one does not work either.

    Here's the actual script by A.Mikkelsen that is based on code by LucD in the forum mentioned previously.

    BEGINNING

    ##################################################################################
    # The script terminates all sessions if idle idle user for more than xx #.
    #                             #
    # Created by: Anders Mikkelsen, 2010 #.
    ##################################################################################
    Claire
    # Add - PSSnapin VMware.VimAutomation.Core

    # $server = "vcenter server.
    # $user = "vcenter username.
    # $pwd = "password of vcenter.

    # Add 1 extra hour when, due to the difference of timestamp between MSSQL and Windows.
    # slow down time 5 hours = 360
    # 10 hours slowed = 660
    $intOlderThan = 60

    # Connect-VIServer $server - user $user-password $pwd
    # Connect-VIServer $server

    $svcRef = new-object VMware.Vim.ManagedObjectReference
    $svcRef.Type = 'ServiceInstance.
    $svcRef.Value = 'ServiceInstance.
    $serviceInstance = get-views $svcRef

    $sessMgr = get-view $serviceInstance.Content.sessionManager
    $oldSessions = @)
    {foreach ($sess in $sessMgr.SessionList)}
    If (($sess.)) (LastActiveTime) .addminutes ($intOlderThan) - lt (Get-Date)) {}
    $oldSessions += $sess. Key
    #write "$($sess.)". User name)'
    }
    }

    # Session terminal that are inactive for more than approved ($intOlderThan)
    $sessMgr.TerminateSession ($oldSessions)

    Disconnect-VIServer *-confirm: $false

    END

    The error message I get is:

    BEGINNING

    Exception calling 'TerminateSession' with '1' or the arguments: "it was not correct to specified parameters.

    "

    D:\Scripts\vc_terminate_idle_sessions.ps1:36 char: 26

    + $sessMgr.TerminateSession < < < < ($oldSessions)

    + CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)

    + FullyQualifiedErrorId: DotNetMethodException

    END

    I should mention that my knowledge of PowerCLI is almost nothing, so any help in tweaking this script to make it work with PowerCLI 5.1 Release 2 and VC 5 U2 would be much appreciated.

    The error is caused by the fact that you are trying to kill your own session (if it was started long time ago).

    Apparently in vSphere 5. they included a security mechanism integrated to avoid this.

    You can take this by adding a simple test.

    ## max number of idle minutes for sessions to keep$intOlderThan = 60$serviceInstance = Get-View 'ServiceInstance'## get the session manager object$sessMgr = Get-View $serviceInstance.Content.sessionManager## array to hold info about stale sessions$oldSessions = @()foreach ($sess in $sessMgr.SessionList){    if (($sess.LastActiveTime).addminutes($intOlderThan) -lt (Get-Date) -and          $sess.Key -ne $sessMgr.CurrentSession.Key){        $oldSessions += $sess.Key    } ## end if} ## end foreach
    
    ## if there are any old sessions, terminate them; else, just write message to the Warning streamif (($oldSessions | Measure-Object).Count -gt 0) {    ## Terminate sessions than are idle for longer than approved ($intOlderThan)    $sessMgr.TerminateSession($oldSessions)} ## end ifelse {Write-Warning "No sessions that have been idle for more than '$intOlderThan' minutes; no action taken"}
    
  • Adding a paralytic to the catalog in vCD with PowerCLI

    I would add a paralytic to a catalog via PowerCLI. I see not all the methods under the the VAPP extensiondata that allow this.

    Then I thought that maybe I need to look at the catalog and couldn't find CatalogItems in the GetCIView() of the org and don't know how to edit:

    $ciorg. ExtensionData.Catalogs.CatalogReference [0]. GetCIView(). CatalogItems

    Then I tried to script on the creation of a new catalog... It works but I still don't know to go to add vApps.

    $ciorg = get - org "Org name"

    $cat = New-Object vmware.vimautomation.cloud.views.AdminCatalog
    $cat. Owner = New-Object VMware.VimAutomation.Cloud.Views.Owner
    $cat. Owner.User = New-Object VMware.VimAutomation.Cloud.Views.Reference
    $cat. Owner.User = (get - org). ExtensionData.Users.UserReference [0]
    $cat. CatalogItems = New-Object VMware.VimAutomation.Cloud.Views.CatalogItems
    $cat. IsPublished = $True
    $cat. Name = "catalog name.
    $cat. Description = "created with PowerCLI.
    $ciorg. ExtensionData.CreateCatalog ($cat)

    * Entries in bold must refine. Didn't know how to find a specific user so I used the first input that is mine in the user table.

    So currently, I'm puzzled. Alan, LucD or Jake... Ideas?

    Thank you!

    The ExtensionData and Get-CIView expose the vCloud API REST. The documentation is available here: https://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/index.html. What PowerCLI exposes them, however, are slightly different. We will publish a separate documentation to another point that would be more accurate.

    Note the PowerCLI interface exposes to .net is not the same as the c# SDK for vCloud.

    To access the documentation for the 2 operations, you should define the scope of research on all operations and the search for InstantiateVAppTemplate or ComposeVApp, follow the link of type Input to InstantiateVAppTemplateParams/ComposeVAppParams.

    Creating a vApp on a vApp model is done with InstantiateVAppTemplate. ComposeVApp is for the creation of a paralytic from scratch.

    Just an aside: take a look at the CIVApp import and import-CIVAppTemplate, those who are able to "register" a virtual machine of vSphere in vCloud. Maybe it's a quicker way of migration of machines virtual vSphere to vCloud VAPP model that they can do the conversion without facing the virtual machine.

  • Override the port NIC teaming with powercli group?

    Hi all

    Any chance you could lend a hand?

    I have a powercli script that goes out to all of my ESX 4.0 host and add a new port group to vswitch1 with a new VLAN ID. That works well, but I also need to override the NIC teaming on this port group, to set an active NIC and the other to be the backup. (we put NIC failover port groups not the vswitches).

    I see ways to change NIC vswitches grouping settings, but am yet to find a way to change the settings of the NIC collection for groups of ports themselves with powercli?

    Can someone shine a light?

    Thank you

    Try something like:

    Get-VirtualPortGroup-name '' | Get-NicTeamingPolicy | Game-NicTeamingPolicy - MakeNicActive "vmnic1" - MakeNicStandby "vmnic0".

    I hope this helps!

  • Handling of keys with powerCLI

    I need to add and remove keys vCetner with powerCLI.  My hope was to add new keys to a txt or csv type file and run a small powerCLI script to remove old keys and add the new keys in the file.  I'm sure I can find a way extract the file, but I do not know what commands PowerCLI to use to control the vCenter.

    Does anyone know how to do this?

    Or at least point me in the right direction (perhaps with a few power CLI commands, I can't find any dealing with adding or deleting key.)?

    Have you already checked my post to license of vCenter ?

    Currently, there are no cmdlets for managing licenses, but it's pretty easy to call the PowerCLI SDK API.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Add bookmark adds the bookmark with incorrect URL

    When I press the star to bookmark add, or click the 'Bookmark this page' it adds a bookmark with the correct favicon, but the URL is to some site randomly in my story and sometimes some website I don't know at all.

    Problems with bookmarks and history does not properly can be caused by a corrupted database places.sqlite file.

    You can check for problems with the database places.sqlite file in the Firefox profile folder.

  • count the number of targets, devices and paths by hba for each host with powercli 5.5

    Hi all

    I'm writing this Question again in the community, was not able to found the answer I was looking for in the nets:

    https://communities.VMware.com/thread/516226?start=0 & tstart = 0

    https://communities.VMware.com/thread/293531

    I went through the scripts provided in the community, but seems that t not work on powercli 5.5.

    ///

    # The target account, devices and paths for each host

    Get-Cluster $cluster | Get-VMHost | Sort-Object-property name. {ForEach-Object

    $VMHost = $_

    $VMHost | Get-VMHostHba-type FibreChannel | Sort-Object-property device | {ForEach-Object

    $VMHostHba = $_

    $ScsiLun = $VMHostHba | Get-ScsiLun

    If {($ScsiLun)

    $ScsiLunPath = $ScsiLun | Get-ScsiLunPath | `

    Where-Object {$_.} Name - like "$($VMHostHba.Device) *"} ".

    $Targets = ($ScsiLunPath |) »

    Group-object - property SanID | Measure - Object). County

    $Devices = ($ScsiLun |) Measure - Object). County

    $Paths = ($ScsiLunPath |) Measure - Object). County

    }

    Else {}

    $Targets = 0

    $Devices = 0

    $Paths = 0

    }

    $Report = "" | Select-Object - property VMHost, HBA, target devices, paths

    $Report.VMHost = $VMHost.Name

    $Report.HBA = $VMHostHba.Device

    $Report.Targets = $Targets

    $Report.Devices = $Devices

    $Report.Paths = $Paths

    $Report

    }

    }

    ///

    I went through the script LucD posted below: but it's not exactly what I'm looking for.

    LucD : can you please change the same for me please.   to count the number of paths per hba for each host with powercli 5.5, devices and targets.

    //

    $esx = get-VMHost < host name >

    foreach ($hba to (VMHostHba Get - VMHost $esx - type "FibreChannel")) {}

    $target = ((get - see $hba. VMhost). Config.StorageDevice.ScsiTopology.Adapter | where {$_.} Adapter - eq $hba. Key}). Goal

    $luns = get-ScsiLun - Hba $hba - LunType 'disk '.

    $nrPaths = ($target | % {$_.}) Lun.Count} | Measure - Object - sum). Sum

    Write-Host $hba. Device ' target: ' $target. County "devices:" $luns. County ' path: ' $nrPaths

    }

    //

    I'll be grateful for any help.

    Tarun Gupta

    Try something like this

    {foreach ($esx in Get-VMHost)

    foreach ($hba to (VMHostHba Get - VMHost $esx - type "FibreChannel")) {}

    $target = ((get - see $hba. VMhost). Config.StorageDevice.ScsiTopology.Adapter | where {$_.} Adapter - eq $hba. Key}). Goal

    $luns = get-ScsiLun - Hba $hba - LunType "disk" - ErrorAction SilentlyContinue

    $nrPaths = ($target | % {$_.}) Lun.Count} | Measure - Object - sum). Sum

    $props [ordered] = @ {}

    VMHost = $esx.name

    HBA = $hba. Name

    Target = $target. County

    Device = $luns. County

    Path = $nrPaths

    }

    New-object PSObject-property $props

    }

    }

  • Download the virtual machine in a store of data with powercli

    Hello

    How to list the files of virtual machine on a store of data with PowerCLI

    I have a virtual machine and I want to see all the files in a data store (such as hard,.-flst.vmdk, .log, .nvram) using powercli. Is this possible?

    TKS.

    Try the following, it uses a function of my position of friendly units .

    Function Get-FriendlyUnit {}

    <>

    . Numbers converted small binary multiples SYNOPSIS

    . DESCRIPTION the function accepts a value and him will convert

    in the largest available binary unit.

    . Author NOTES: Luc relaxing

    . Value of the PARAMETER

    The value to convert.

    This number must be positive.

    . IEC PARAMETER

    A switch to indicate whether the function should return the CIS

    Unit, or the names of the units most commonly used names.

    The default is to use the commonly used unit names.

    . EXAMPLE OF

    PS > Get-FriendlyUnit-value 123456

    . EXAMPLE OF

    PS > 123456 | Get-FriendlyUnit - CIS

    . EXAMPLE OF

    PS > Get-FriendlyUnit-value 123456,789123, 45678

    #>

    (param

    [CmdletBinding()]

    [parameter (mandatory = $true, ValueFromPipeline = $true)]

    [double []] $Value,.

    [switch] $IEC

    )

    Begin {}

    $OldUnits = "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB".

    $IecUnits = 'B', 'KiB', 'MiB', "GiB", "TiB", "PIF", "BANK", "ZiB", "YiB".

    If ($IEC) {$units = $IecUnits} else {$units = $OldUnits}

    }

    {in process

    $Value | %{

    If ($_ - lt 0) {}

    Write-Error "Numbers must be positive."

    breaking

    }

    If ($value - gt 0) {}

    $modifier = [math]: Floor([Math]::Log($_,1KB)))

    }

    else {}

    $modifier = 0

    }

    New-object PSObject-property @ {}

    Value = $_ / [math]: Pow(1KB,$modifier)

    Unit = & {if ($modifier - lt $units. {Count) {$units [$modifier]} else {'1KO E {0}' f $modifier}}

    }

    }

    }

    }

    foreach ($vm in (Get-View - ViewType VirtualMachine - property Name, 'LayoutEx.File')) {}

    $vm. LayoutEx.File |

    Select @{N = "VM"; E = {$vm. Name}},

    @{N = 'Name'; E={$_. Name.Split(' ') [1]. "Split('/') [1]}},"

    @{N = "Path"; E={$_. Name}},

    @{N = 'FileType'; E={$_. Type}},

    @{N = "Datastore"; E={$_. Name.Split(']') [0]. TrimStart('[')}},

    @{N = "size"; E = {}

    $val = get-FriendlyUnit-value of $_. Size

    "{0:n2} {1}" f $val. Value, $val. Unit

    }}

    }

  • To connect to vCenter using the same Session with PowerCLI

    Hi all

    Is it possible that we can establish multiple connections to vCenter using the same session with Powercli.

    As connect-viserver-Server "vcenter1" - domain\domainacnt of the username-password "Password".

    is to establish several connections and we want to limit, because we are in the process of report generation based on the web developing using Powercli with IIS.

    Please suggest.

    You can use the Session parameter on the cmdlet Connect-VIServer .

    I use this for the PowerShell Workflows, see workflow of PowerShell and PowerCLI

  • I need a way to change the Login with PowerCLI 5.5 banner

    So I'm having a lot of problems with the fixing of the banner of connecting through Host Profiles.  It does not change the formatting at all, and it always shows not permitted even after the application.  Someone has found a way to define it with PowerCLI?  I saw ways to connect directly to the host ssh but I want to with a session PowerCLI, vCenter and does not direct connection to the host.  I would like to know if anyone has found anything!

    Thank you.

    We had a similar thread before, see script logon banner , but without using SSH, as I know there is no way to do it.

Maybe you are looking for