VMware Cloud Community
GrantBrunton
Enthusiast
Enthusiast
Jump to solution

Need help updating script to work with new vSphere 6 environment

I have a very large powershell script I created some time ago to clone our production servers into a development environment and configure them for use in vShield isolated development networks.

We have recently updated our vSphere 5 environment to vSphere 6 and changed the architecture around.

Previously with vSphere 5 we had a single vCenter server that was managing our two datacenters by itself.

With the new vSphere 6 design we have a PSC and VCSA server at each datacenter working in a single SSO domain.

The first thing I have done with my cloning script is to update the vcenter reference to an array of both servers so I connect to both VCs at once.

This allows me to see and manage VM guests from both vCenters so get-vm works to see the source guest.

The problem though is that when I try to clone a VM from one datacenter to the other the command fails as it cannot find the VM to clone.

# Virtual Centre server or VM host to connect to

$aryVIServer = @("vc01.domain.com", "vc02.domain.com")

# Load VMware environment

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null

$VIServer = Connect-VIServer $aryVIServer

# Server cluster group to deploy to

$strVMCluster = "Bubbles"

# Define name of new server including environment prefix

$vmName = "$($envPrefix)-$($CloneServer)"

# Select Host with least memory consumption

$selectedHostObj = Get-VMHost -Location $strVMCluster | Sort-Object -Property MemoryUsageGB | Select-Object -First 1

# Select folder to place VM guest into

$folderObj = Get-Datacenter -Cluster $strVMCluster | Get-Folder $selectedBubble

# Select datastore with most available space

$selectedDatastoreObj = Get-DataStore -VMHost $selectedHostObj | Sort-Object -Property FreeSpaceGB -descending | Select-Object -First 1

# Clone new VM from running Server

$newVM = New-VM -Name $vmName -VM $CloneServer -VMHost $selectedHostObj -Datastore $selectedDatastoreObj -DiskStorageFormat "Thin" -Location $folderObj -Confirm:$false

This used to work fine when there was a single VC but of course is failing now with two.

The only difference so far is the change of VCs. We are still using the exact same hosts running ESXi 5.0 in the same location in separate datacenters.

Oh and I am now using powercli 6.3 R1 instead of 5.5 R1.

I expect this type of process should work fine and I will just need a different command for cloning the VMs now?

Tags (3)
1 Solution

Accepted Solutions
GrantBrunton
Enthusiast
Enthusiast
Jump to solution

Well, I solved the first problem as per here:

Re: Cannot deploy VM from template to different vCenter Server (in same SSO domain)

However, now I can't run Invoke-VMScript without getting an error that proxy authentication is required.

If I remove all my proxy settings in IE then it connects fine but this script needs to be run by a number of engineers without being dependent on their proxy settings being disabled.

I can programmatically change their proxy settings at the beginning of the script but there is nothing preventing them from changing those back if they use their browser and breaking the execution of the script midway.

Never had any problems with Proxy settings before and I haven't seen any other posts that look directly relevant.

Anyone know of a way to avoid this?

View solution in original post

8 Replies
LucD
Leadership
Leadership
Jump to solution

This looks the same issue/question as the one in Cannot deploy VM from template to different vCenter Server (in same SSO domain)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

GrantBrunton
Enthusiast
Enthusiast
Jump to solution

Yes I did just find that post after submitting this one and I used to do something similar to that when I first set the scripts up because the new-vm command didn't support some of the things I was doing then so I'll have a look back at my first scripts.

However, I was hoping that there may be a better way to do things with vSphere 6 and SSO domains but it appears that isn't the case.

eg. instead of Connect-VIServer you use another command to connect to a PSC in the SSO domain that gives you full control across the whole environment or something.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not afaik I'm afraid


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
GrantBrunton
Enthusiast
Enthusiast
Jump to solution

Well, I solved the first problem as per here:

Re: Cannot deploy VM from template to different vCenter Server (in same SSO domain)

However, now I can't run Invoke-VMScript without getting an error that proxy authentication is required.

If I remove all my proxy settings in IE then it connects fine but this script needs to be run by a number of engineers without being dependent on their proxy settings being disabled.

I can programmatically change their proxy settings at the beginning of the script but there is nothing preventing them from changing those back if they use their browser and breaking the execution of the script midway.

Never had any problems with Proxy settings before and I haven't seen any other posts that look directly relevant.

Anyone know of a way to avoid this?

LucD
Leadership
Leadership
Jump to solution

Where do you get the proxy authentication error ?

On the Invoke-VMScript call or on the script being executed via Invoke-VMScript ?

Perhaps add a screenshot of the error ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
GrantBrunton
Enthusiast
Enthusiast
Jump to solution

The error occurs when running the Invoke-VMScript command.

The below screenshot has proxy enabled in IE settings on the first execution and no proxy enabled on the second.

I assume it is the execution of that command causing it and not the running of the script because it is the proxy settings for the user running the command that affects the outcome.

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you do a Get-PowerCLIConfiguration  and check the ProxyPolicy ?

I suspect it might be set to UseSystemProxy, try changing that to NoProxy, with the Set-PowerCLIConfiguration cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

GrantBrunton
Enthusiast
Enthusiast
Jump to solution

Ah perfect, that was what I was after!!

Thanks a lot Smiley Happy

Reply
0 Kudos