Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Wait-Task - The operation has timed out

$
0
0

if i use the command sequence:

 

$objTask = New-VM -Name $hostname -ResourcePool $objCluster -ContentLibraryItem $objContentLibrary -Location $objFolder -Datastore $objDatastoreCluster -RunAsync

write-host "Deploy OVF Template: Starting Job..."

Wait-Task $objTask

After some time the error is returned:

 

Wait-Task : 19/06/2017 14:05:49    Wait-Task        19/06/2017 13:54:45    Wait-Task The operation has timed out

At line:1 char:1

+ Wait-Task $objTask

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

    + CategoryInfo          : NotSpecified: (:) [Wait-Task], ViError

    + FullyQualifiedErrorId : VICore_VMServiceImpl_DeployFromLibraryItem_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask

Even giving this error I realized that in vcenter there are still two tasks: Deploy OVF package from Content Library to Resource Pool and then the Deploy OVF template

This two tasks are executed with sucess and vm was created even with the timeout error.

Note: The template has 25GB

 

TaskStart TimeFinal TimeTime ElapsedStatus
Wait-task14:29:4614:49:4600:20:00Error
Fetch Content of a Library Item14:29:4614:30:0000:00:14Sucess
Deploy OVF package from Content Library to Resource Pool14:29:4615:01:2000:31:34Sucess
Deploy OVF Template14:30:1315:01:1900:31:06Sucess

Wait-Task - The operation has timed out

$
0
0

if i use the command sequence:

 

$objTask = New-VM -Name $hostname -ResourcePool $objCluster -ContentLibraryItem $objContentLibrary -Location $objFolder -Datastore $objDatastoreCluster -RunAsync

write-host "Deploy OVF Template: Starting Job..."

Wait-Task $objTask

After some time the error is returned:

 

Wait-Task : 19/06/2017 14:05:49    Wait-Task        19/06/2017 13:54:45    Wait-Task        The operation has timed out       

At line:1 char:1

+ Wait-Task $objTask

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

    + CategoryInfo          : NotSpecified: (:) [Wait-Task], ViError

    + FullyQualifiedErrorId : VICore_VMServiceImpl_DeployFromLibraryItem_Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask

Even giving this error I realized that in vcenter there are still two tasks: Deploy OVF package from Content Library and then the Deploy OVF template

This two tasks are executed with sucess and vm was created even with the timeout error.

Note: The template has 25GB

PowerCLI script for migrating VMs from one ESX cluster using VSS to another using VDS.

$
0
0

Hi guys,

 

I'm hoping you guys can help me out on this one. We are looking to migrate a fair amount of virtual machines from one ESX cluster using a different SAN to another ESX cluster using a new SAN. Both of these clusters are managed by the same vCenter instance.  Cluster A is using a VDS and cluster B is using VSS and we would like to go from Cluster A to Cluster B.

 

I can easily perform this task by using the web client and performing a compute and storage migration. Using the web client also allows me to change the mapping of the source network (VSS) to the new destination network (DVS) without any errors or downtime. All preliminary compatibility checks pass with no errors.

 

Obviously I would like to automate this process but I am running into an error when using my script.  I manually connect to my vCenter instance hence no connection string is present. All virtual machines to be moved are stored inside the vms.txt file which is being read.

 

Here's the script:

 

$vms = Get-Content D:\Scripts\vms.txt

 

foreach ($vm in $vms)

{

#Move-VM -VM $vms -Destination 'oldesx' -Datastore 'newVMFS' -PortGroup 'newPG(VDS)'

}

 

Here's the error I am getting when I execute my script:

 

Move-VM : Cannot bind parameter 'PortGroup'. Cannot convert the "myvdsportgroup" value of type "System.String" to type

"VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroupBase".

At D:\Scripts\Global\vMotion\bulkmove.ps1:6 char:114

+ ... e 'newVMFS' -PortGroup ''myvdsportgroup"

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

    + CategoryInfo          : InvalidArgument: (:) [Move-VM], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

 

What do I need to include into my script to honor the portgroup change as part of the migration effort.

 

Thanks!

get vmhosts connected to datastores

$
0
0

I need to get a list of all vmhost connected to specific datastores

 

 

is there a quick way to do this?

 

get-datastore | ?{$_.name -match "EMC"} | get-vmhost ??

Get-HardDisk - Thin provisioning

$
0
0

Hi

 

I did a quick look in PowerCLI (including extensiondata, excluding Onyx) and in the community but couldn't find this.

 

If I wanted to find out the virtual HDs of the VM, specifically if it's thick or thin (that's easy) but more specifically what sub-type - thick/lazy, thick/eager, etc.

 

I don't need a full script just an example of one VM - I can put in the fillers around it.

 

Thank you

POWER CLI - Create new users in vsphere.local

$
0
0

How can i create new users in vSphere.local using powercli?

how to change "display name" via PowerCLI command?

$
0
0

Hi, guys,

I have a question:

Vcenter----->home---->inventory--->host and Clusters, I select an ESX host and ------->configuration----->storage adapter, we can see many LUNs from storage.

1.jpg

We usually right click the "Name" to change the name to match with what we see in stroage side.

file:///E:/1.jpg

 

now we present 90 LUNs to this ESX cluster.

 

I am wondering if there is any command we can change the device name?

 

I tried get-ScsiLun.....and I can get the HLU, but there is no "Name" in the outpur.........

 

would you help please point the right command?

 

many thanks in advance!

Script to shutdown all VMs and hosts in a cluster on Saturday evening, and start it up on Mon Morning

$
0
0

Hi,

I am a newbie and just wondering if such a script exists?

 

My vcenter is a windows based VM on one of the 3 hosts.

 

much thanks!


get-view -viewtype

$
0
0

can i use get-view -viewtype to filter on multiple items?

 

ex

 

I want to get esxi version of esxi hosts on cluster1

 

get-view -viewtype computeresource -filter @{"Name"="cluster1"}

 

but how do I get the esxi hosts as well?

 

get-view -viewtype hostsystem -filter

vms deploy from template

$
0
0

Hello

 

I had requirement to deploy vms from a template where vms details are pulled from template as the node count is given in csv based on the node count in a row that many vms should create in series.

as i am new I can able to deploy single vm at once but i am faling to deploy multiple vms at once.

Can someone please write a script for my requirement

the csv file contains like this

 

For example if the node count is 2 it show create vms with names SERVM1,SERVM2 (the number count will increase if i increase the node count  in the csv like SERVM1,SERVM2,SERVM3,SERVM4)

 

Same for all the vms

       

NodesVmnamesTemplate nameDatastoreNumberOfCoresMemoryInMBOSStorageESXI
2SERVM1,SERVM2RHEL_6_New_TemplateSER_56_LUN_2013584RHEL 6.820Host1
1SERVM6RHEL_6_New_TemplateSER_56_LUN_2127168RHEL 6.820Host2
3SEZVM1,SEZVM2,SEZVM3Win2k12_STD_TemplateSEZ_45_LUN_4414336Win 12150Host3
4SEMVM46,SEMVM47,SEMVM48,SEMVM48Win2k12_ENT_TemplateSEM_55_LUN_10828672Win 121000

Host4

Does Get-Tag work on vcsa 6.5?

$
0
0

I'm having some issues using Get-Tag or Get-TagAssignment on two different 6.5 vcsas.  PowerCLI is 6.5 R1.  Whenever I attempt to execute either command I get the following error.  Anyone else seeing this behavior?

get-tag-err.png

PowerCLI+LogInsight API Filtering

$
0
0

So I have this issue with ESXi hosts where they randomly seem to stop sending SysLog to Loginsight in such a way that no alerts trigger anywhere, I just end up with no data until syslog service on the host is restarted.  In the past when I was leveraging vCenter syslog, since it dropped everything into a folder on the Windows server I could just check last modified timestamp on the folder contents, then based on a certain delta indicating its been too long since any activity was written I could reach out via PowerCLI and restart the host syslog service.  With LogInsight I don't have any folders to check, yet I do have the API so I thought it would be fairly simple to get a list of hosts and latest event time stamp.  It turns out it's harder than I thought since I don't really understand how to leverage the API effectively.  Does anyone have any URI examples of how I might get a list of 'source' with a latest event timestamp?  I would even settle for just getting a list of unique 'source' names and ID's that I could then run through an array.

Need Help on "New-VM -VMFilePath " When Using $Variable Instead of Path String

$
0
0

Hi everyone!

 

I'm quite new to this forum, to PowerShell, and to PowerCLI in general. So I may need your understanding and generous help on this...

 

I've created a simple script that should remove/unregister a VM (based on a text file), and register them to a new cluster based on the vmx file location extracted through a function called "Get-VMXPath" (get it here: Script Get the VMX Path for VMware VMs)

 

$filename = "ztest.txt"
$location = "C:\Scripts\_Migration\ztest"
$vmList = Get-Content "$location\$filename.txt"
foreach ($vm in $vmList)
{    $vmxpath = Get-VMXPath $vm | select VMXPath    Remove-VM -VM $vm -DeleteFromDisk:$false -Confirm:$false -RunAsync    New-VM -VMFilePath $vmxpath -ResourcePool (Get-Cluster Cluster_Name | Get-ResourcePool ResourcePool_Name)
 }

 

I'm having issues with Line 8, particularly, the variable $vmxpath. When I use this variable, I get this error:

 

New-VM : 8/14/2017 4:01:22 PM    New-VM        '@{VMXPath=[datastore01] vmfolder/vm.vmx}' is not valid datastore path.   

At line:1 char:1

+ New-VM -VMFilePath $vmxpath -ResourcePool (Get-Cluster Cluster_Name ...

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

    + CategoryInfo          : InvalidArgument: (:) [New-VM], InvalidArgument

    + FullyQualifiedErrorId : Common_DatastorePathHelper_ValidateDatastorePath_InvalidPath,VMware.VimAutomation.ViCore.Cmdlets.Command

   s.NewVM

 

But when I don't use the $vmxpath variable, and use the actual value of "[datastore01] vmfolder/vm.vmx" instead, it works.

 

As I've said, I'm new to PowerCLI and PowerShell in general, so I might be missing out on how to insert a variable to property or to the PowerCLI new-vm switch -VMFilePath.

 

Also, just a side note, we're migrating ~100+ vms from one cluster to another, but we're unable to vMotion due to some errors (which is still getting fixed). So I was hoping to use this script to perform the migration.

 

Hoping for your kind assistance on this, thanks!

PowerCLI - Deploy VM-templates from CSV

$
0
0

Having issues with a script.  I feel I'm close but I'm still missing something...  I'm not sure if the issue lies within PowerCLI or my lacking PowerShell knowledge. 

 

My PowerCLI 6 script seems to work but only at a low level.  It creates the VMs but doesn't seem to assign the IP or hostname to the newly created VM.  So, when it's time to apply the Customization Specification, it either times out or just doesn't fully apply; I'm not sure which as no errors get spit back at me.  It creates the VM with the correct name & changes the port-group on which the NIC will sit but that seems to be about it.  I've manually tested the Customization Specification and template that are being used in this script and it looks fine after a manual walk-through.  For some reason, some the info from the CSV is not being used correctly or at all.

 

The script I have is pretty long and I didn't want to muck up the page with it so I dumped it on PasteBin; hope that's ok...

 

Script: http://pastebin.com/XwFHLHER

 

CSV: http://pastebin.com/u59TwBu4

Trimming variable names

$
0
0

I have been working on a script for creating a couple of Standard vSwitches. The goal is to move VMs back to the Standard from a VDS in preparation for a move of the entire datacenter from one vCenter to another. I have everything worked out but one stupid simple question. I am logging in and grabbing the cluster, then enumerating port groups like so:

 

$VMHosts = Get-Cluster -Name "MyCluster" |    Get-VMHost


$sourceDVS = $VMHosts |
    Get-VDSwitch |        Get-VDPortGroup |            Where {$_.IsUplink -ne "True"} |                Where {$_.Name -ne "dvPortGroup"}  |                        Select Name,VlanConfiguration |                            Out-GridView

 

Works just fine. The VlanConfiguration shows up as "VLAN 28", "VLAN37", etc.

 

When going to create the New-VirtualPortGroup, however, I want to trim this down to just the number for the -VLANID parameter. I tried using trim(), but get an error:

Method invocation failed because [VMware.VimAutomation.Vds.Impl.V1.SingleVlanConfigurationImpl] does not contain a method named 'trim'

I would have thought that it would simply use PS, but I guess I was mistaken. I can do a -split on the output, like so:

foreach ($vm in $sourceDVS) {   $sTrim = ($vm.VlanConfiguration -split "VLAN ")   Write-Host $sTrim
}

 

but this leaves a leading space that I again cannot trim out. It must be something simple stupid, but what is the best way to perform string operations on these variables?


script to fetch datastore details -- vsphere replication

$
0
0

Hi All,

 

Can anyone help me with a script to get following information

 

We have multiple virtual machines configured under vsphere replication. We need the datastore information of all the vmdk on both primary and replicated site (vmdk's datastore of the replicated VM at the DR site)

 

Please help.

 

LucD

Clone VM Between vCenters using New-VM

$
0
0

Not sure why this should be so difficult - cloning a VM between two vcenters in enhanced linked mode / same SSO domain using new-vm.

 

$mastervm = ‘vmtoclone’
$sourcevcenter = ‘sourcevcenter’
$destvcenter = ‘destinationvcenter’
$destdatastore = ‘destinationdatastore’
$destcluster = ‘destinationcluster’
$destfolder = ‘destinationfolder’

connect-viserver $sourcevcenter -Credential $cred
connect-viserver $destvcenter -Credential $cred

New-VM -server $destvcenter -name clonedvm -vm (get-vm -Name $mastervm -Server $sourcevcenter) `
 -datastore (get-datastore -Server $destvcenter -Name $destdatastore) `
 -location (get-folder $destfolder -Type vm -server $destvcenter) `
 -DiskStorageFormat Thin -ResourcePool (get-cluster -Name $destcluster -server $destvcenter)


 

New-VM  -  The object <vim.ClusterComputeResource> has already been deleted or has not been completely created

 

I'm connected to both vcenters, and I'm able to create a new VM on the desired destination cluster, folder and datastore without cloning, but whenever I try to clone (by specifying the -vm parameter) it fails with the above error.

 

Any ideas?

Script needed to count the number of Windows VM's per Cluster and the number of CPU cores

$
0
0

I've used the following one liner which gives me the numver of vm's per cluster but I need to narrow that down to just the number of Windows servers per cluster.

 

get-cluster | select @{n="cluster";e={$_.name}}, @{n="hosts";e={($_ | get-vmhost).count}}, @{n="vms";e={($_ | get-vm).count}} | sort cluster | ft -auto

 

I tried adding the following expression to select only Windows servers but it returns 0 for all vm's then.

 

get-cluster | select @{n="cluster";e={$_.name}}, @{n="hosts";e={($_ | get-vmhost).count}}, @{n="vms";e={($_ | get-vm | Where-Object {$_.OSFullName -like "*Windows Server*"}).count}} | sort cluster | ft -auto

 

Does anyone know what I'm doing wrong? I would also like to know the number of CPU cores used per cluster for the windows VM's.

 

Many thanks

Script to extract multiple IP Address corresponding to VNIC

$
0
0

Hi,

 

We are trying to bring some data related to VM. Output needs to be one line per vm in a csv format

Lets say VM1 has 2 VNIC and 3 IP Address, output should come in this format

 

VM1; UUID1; VNIC1; IP1,IP2; MAC1;PG1

VM1;UUID1;VNIC2;IP3;MAC2;PG2

VM2;UUID2; VNIC2;IP4; MAC3;PG3

 

Can someone help to fix below script by running on PowerCli 6.5.1 ?

 

$reportedvms=New-Object System.Collections.ArrayList

$vms=get-view -viewtype virtualmachine  |Sort-Object -Property {  $_.Config.Hardware.Device |  where {$_ -is [VMware.Vim.VirtualEthernetCard]} |  Measure-Object | select -ExpandProperty Count} -Descending

 

foreach($vm in $vms){

  $reportedvm = New-Object PSObject

  Add-Member -Inputobject $reportedvm -MemberType noteProperty -name Guest -value $vm.Name

  Add-Member -InputObject $reportedvm -MemberType noteProperty -name UUID -value $($vm.Config.Uuid)

$networkcards=$vm.guest.net | ?{$_.DeviceConfigId -ne -1}

$i=0

foreach($ntwkcard in $networkcards){

Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.Network" -Value $ntwkcard.Network

Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.MacAddress" -Value $ntwkcard.Macaddress 

$IP = $(($ntwkcard.IpAddress|?{$_ -like "*.*"}) -join ',')

Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.IpAddress" -Value $IP

$i++

}

$reportedvms.add($reportedvm)|Out-Null

}

$reportedvms| export-csv -delimiter "`t" -path E:\SCRIPTS\CRAMER\OUTPUT\HCS_multipleIP-$(get-date -f dd-MM-yyyy-hh-mm).csv –notypeinformation

What is the best option to run scripts to automate a task on ESXi 5.5 host

$
0
0

The main reason why I want to write a script and automate a task is because my host server is running ESXi 5.5 and its stored on 5 hard drives configured for RAID 5. As we know, hard drives fail and I would like to know when a hard drive takes a dump so I can fix the problem immediately. I would like to receive an alert via email when a hard drive fails on my storage RAID 5.

 

I've successfully installed hp-esxi5.5uX-bundle-2.4-16.zip and I was able to run a command to display RAID status, perfect! its what I want. Now I would like to write a script, but I know ESXi host sbin file has very limited Linux shell scripting commands.

 

I wrote a basic script and the output was what I was looking for. With that said, to simply my scripting situation regarding sending an email when a single hard drive fails, would it be better if I install PowerCLI or stick to my plan using BusyBox shell thats provided with ESXi 5.5?

Viewing all 14549 articles
Browse latest View live


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