Did you check that on the datastore there is no folder present with the name of the new VM?
It could be that you have an orphaned VM on that datastore due to previous runs of the script.
the VM names are unique, but I did check that.
Like I said when I run the commands manually (i.e. copy & paste) it works fine
Which PowerCLI version are you using?
From where do you run the script and the commands?
From an IDE, from the PowerShell prompt, from the PowerCLI prompt...?
VMware PowerCLI 6.5 Release 1 build 4624819
VMware Cis Core PowerCLI Component 6.5 build 4624453
VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
VMware vSphere Update Manager PowerCLI 6.5 build 4540462
Name : ConsoleHost
Version : 5.1.17134.165
InstanceId : 2cd21ede-ccda-4660-adf2-dc7a8d6bbafd
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-GB
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
I am running the script & commands from my workstation - connected to vcenter server via connect-viserver command
Ok, so you are running this from the PowerShell prompt it seems.
Did you already stop/start that PowerShell session?
That is a rather old PowerCLI version, I would suggest you upgrade.
5.1 is the latest version of PS for Win 10
I was referring to the PowerCLI version, not the PowerShell version.
And did you try the stop/start of the PowerShell session?