VMware Cloud Community
MrBean201110141
Contributor
Contributor

copy OSCustomizationSpec to another vcenter

Hi,

i'm trying to copy the existing Customization Specs from one vcenter to another.

Connect-VIServer -Server vc-old -Port 443 -Protocol https

Connect-VIServer -Server vc-new -Port 443 -Protocol https


$CUSTSPECS = Get-OSCustomizationSpec -Server vc-old


foreach ($CUSTSPEC in $CUSTSPECS) {
                              New-OSCustomizationSpec -OSCustomizationSpec $CUSTSPEC -Name $CUSTSPEC.Name -Server vc-new
                }

I get the following error:

New-OSCustomizationSpec : New-OSCustomizationSpec An OSCustomizationSpec with the same name already exists on the server.

New-OSCustomizationSpec ignores the "-Server" option and tries to create the spec on the vc-old vcenter. Can i solve this problem without exporting the specs?

Thanks for any feedback!

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership

Did you try closing vc-old explicitely (disconnect-VIServer) before doing the New-OSCustomizationSpec ?


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

Reply
0 Kudos
MrBean201110141
Contributor
Contributor

Hi LuCD,

i also tried to close the vc-old connection, but then the object is invalid.

Reply
0 Kudos
LucD
Leadership
Leadership

I think that is because the Server and ServerId properties of the OSCustomizationSpecImpl object contain references to the old-vc.

And both properties are read-only properties.

It looks indeed as if you discovered a flaw in the New-OSCustomizationSpec cmdlet for cloning.

As a bypass you could create the new OSCustomizationSpec without the cloning option, in other words without using the -OSCustomizationSpec parameter. It will mean unfortunately that you will have to explicitely specify all the other parameters.

Something like this

New-OSCustomizationSpec -Name $CUSTSPEC.Name -OSType $CUSTSPEC.OSType -AutoLogonCount $CUSTSPEC.AutoLogonCount ... -Server new-vc


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

MrBean201110141
Contributor
Contributor

That sounds good. I will try it and then report back.

Thanks for the hint!

Reply
0 Kudos
admin
Immortal
Immortal

Hi there,

You hit a bug in New-OSCustomizationSpec cmdlet. I will file a bug.

There is workaround which you can try. The steps are:

1. Connect to the old VC server

2. Copy all specification objects as non persistent objects

PS> $clientSpec = Get-OSCustomizationSpec | New-OSCustomizationSpec -Type NonPersistent

3. Disconnect the old VC server

4. Connect the new VC server

5. Copy the list of non persistnet objects to the second VC server

PS> $clientSpec | New-OSCustomizationSpec -Type Persistent

Regards,

Vitali

PowerCLI Team

MrBean201110141
Contributor
Contributor

Hi Vitali,

this does not work. "$clientSpec = Get-OSCustomizationSpec | New-OSCustomizationSpec -Type NonPersistent" tries to create a Spec on the source server. It fails because the object already exists. I can create a new object with a dummy name, but then i must delete it after the export. I don't want to do any changes on the source system, because normally this is the productive system.

Thanks for filing the bug!

regards,

Birk

Reply
0 Kudos
MrBean201110141
Contributor
Contributor

Hi LucD,

your hint does not work (out of the box). I must check every parameter for being not $null and then create the New-OSCustomizationSpec command. I have decided two export/import the Specs and wait for a bug fix.

Thanks again for your hint.

regards,

Birk

Reply
0 Kudos
admin
Immortal
Immortal

Hi Birk,

I tried those steps on PowerCLI 4.1.1 build 332441. Do you use the same version?

Vitali

Reply
0 Kudos
MrBean201110141
Contributor
Contributor

Hi Vitali,

i use the same version.

Get-PowerCLIVersion


PowerCLI Version
----------------
   VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
   VMWare vSphere PowerCLI 4.1 U1 build 332441
   VMware vCenter Update Manager PowerCLI 4.1 build 266648

Birk

Reply
0 Kudos
admin
Immortal
Immortal

Hi again Birk,

I just execute the steps again and it worked fine for me. Assure that the old VC is disconnected.

Vitali

Reply
0 Kudos
MrBean201110141
Contributor
Contributor

Hi Vitali,

i get the following error at step 2.

New-OSCustomizationSpec        There is already a customization spec with the same name.   

+ $clientSpec = Get-OSCustomizationSpec | New-OSCustomizationSpec <<<<  -Type NonPersistent

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

    + FullyQualifiedErrorId : Client20_VmHostServiceImpl_NewCustomizationSpec_DuplicateCustomizationSpecClient,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec 


1. Connect to the old VC server

2. Copy all specification objects as non persistent objects

PS> $clientSpec = Get-OSCustomizationSpec | New-OSCustomizationSpec -Type NonPersistent

3. Disconnect the old VC server

4. Connect the new VC server

5. Copy the list of non persistnet objects to the second VC server

PS> $clientSpec | New-OSCustomizationSpec -Type Persistent

New-OSCustomizationSpec tries to create the Specs on the source server instead of filling the $clientspec var...

Birk

Reply
0 Kudos
admin
Immortal
Immortal

Hi Birk,

I missed little detail... In the last step, specify explicitly the Server parameter, since this is the destination in this case:

$clientSpec | New-OSCustomizationSpec -Type Persistent -Server $connectionToNewVC

This should work.

Regards,

Vitali

Reply
0 Kudos