I'm working on a script to mass deploy VM's from a CSV-file (thanks all who've helped in my previous post/s). I have entered data for 2 servers in the CSV-file. The script can deploy from either a template or blank (without OS) with only the data of the CSV-file. This script was working fine until I suddenly, without any changes to the script mind you, recieved this error:
PowerCLI C:\Temp\> .\NewVM-1.1.ps1
CleanUp-script removes the VM's created. At the moment this happens even if the VM's were created without error.
Even though I recieve the error the VM's are created/removed, but the rest of the script won't continue because of it (such as add extra hard drives and annotations). Also, it isn't every time that I get the error, sometimes both VM's are create, sometimes 1 of the two and sometimes none.
Some information that might help regarding our test environment that I run the script in:
Not running Power GUI (yes, i've read http://communities.vmware.com/message/1702069).
PowerCLI Version:
PowerCLI C:\Temp\> Get-PowerCLIVersion
VMware vSphere PowerCLI 5.1 Release 2 build 1012425
PowerShell Version:
PS C:\Users> get-host
Name : ConsoleHost
Version : 3.0
As stated in http://communities.vmware.com/message/2146831, previously there wasn't support for Powershell 3, but from what I understand of http://blogs.vmware.com/vipowershell/2013/02/powercli-5-1-release-2-now-available.html that shouldn't be a problem anymore.
My question is therefor: What reasons are there which might cause this error?
Just as a test (yes I know PS v3 is supported) can you try to start PowerShell in v2 mode by doing
C:\> powershell.exe -version 2
and then load the PowerCLI pssnapin and try to run your script ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That seems to work, but something I discovered as well is that it starts to work again if you restart or open a new powercli console window. However, first time I did this the issue returned after a while. So it could be possible that the issue hasn't appeared in powershell v2-mode just yet. Any idea why "reseting" the console fixes the issue only to reappear at a later point?
Also, resources shouldn't be an issue since this is run on a jumpserver (6GB memory) with no other task than to access the test environment, which basicly only is used by me.
6GB, does this mean you are the PowerCLI snapin in a 64-bit PowerShell engine ?
i had occasional issues with PS v3 as well.
Since restarting the session fixes the problem temporarily it could be a memory leak issue, but if that is due to PowerCLI or PS v3 itself is not clear to me.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Correct, it's actually a Win 2012 Server x64 I run the script from.
However, this doesn't explain why the cleanup script fails in one of the consoles 100% of the times and in the restarted/new console 0% of the times.
As you say this might be a memory leak issue, either with x64, powershell v3 or win 2012 server.
Also at a closer look I now noticed that there probably is some issue with my template.. I get the same error when trying to deploy from vCenter when I select another host than the host the template was created from/on.
I now rebooted the ESX host that were giving issues when deploying from template and it now works fine from the restarted/new console.
Anyone with any ideas what may have caused this?
i found the resolution to this was to close the PowerShell_ISE app and re-launch it, or re-open the powercli/powershell window. Thanks for posting this - you led me to this realization.
Thanks for sharing, if it happens again I will try this out!
I hit this error too, using a script that clones out VMs and destroys them using the same naming template.
testnli1, testnli2, testnli3.
After about 5-20 runs of the script (I'm still working out kinks), of destroying and creating VMs with the same name, I started to receive this exact error.
I had to close and re-open the PowerCLI session to continue working.
The odd thing was the New-VM operation said it failed in PowerCLI, but the clone VM operation actually took place, at first I thought it was defining the RunAsync as $true somehow... but then I realized it was erroring out on New-VM. Indicating the name of the new VM as the failure point. (Even though one doesn't exist yet).
This might just be a thing with re-running the same script in one session.
I had this issue too. After some re-runs of
New-VM -Name $clonename -ResourcePool $respool -VM $sourceVM -Location $folder -Datastore $datastore -DiskStorageFormat Thin -RunAsync:$false
This is my environment:
Powercli 6.0 Release 3 (32 bits)
It is solved by re-opening a new session in Powercli.
It seems this issue has gone on long enough that VMWare would take the time to get it worked out. I am having the same issue with any of the NetworkAdapter commands like Set or New-NetworkAdapter.
I wanted to put an updated timeline on this post and problem.
PS C:\> New-NetworkAdapter -VM $vmObj -Portgroup $portObj -StartConnected:$true -Confirm:$false -Server $viServer
WARNING: Parameter 'VM' is obsolete. Passing multiple values to this parameter is obsolete.
New-NetworkAdapter : 7/6/2016 6:54:08 AM New-NetworkAdapter Operation is not valid due to the current state of the object.
At line:1 char:1
+ New-NetworkAdapter -VM $vmObj -Portgroup $portObj -StartConnected:$tr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewNetworkAdapter
Name Value
---- -----
PSVersion 5.0.10586.122
VMware vSphere PowerCLI 6.3 Release 1 build 3737840
Yes, restarting the session seemed to work.
Do you have a valid Support contract?
In that case I would suggest you open a SR for the issue you encounter. That would at least make it more official.
This is a "user" forum after all.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference