VMware Cloud Community
zenivox
Hot Shot
Hot Shot
Jump to solution

Double computer objects in AD when deploying VMs

Hello, I have a script that deploys VMs and works fine (script available here: https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/new-vm-the-operation-is-not-supported-... ). However I have a mandatory requirement to ensure that the newly created computer goes to a specific OU and not to the default OU for newly created devices. So I need to pre-create a computer object in desired OU, which the script does, but when the vmware oscustomization kicks in with the computer join to AD it creates another computer object with same name and in wrong OU. From few investigations I see that in contexts like this, there is a need to pre-create computer objects in a different way by using the WDSUTIL ( https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc... ). So I'm checking if anybody has already done this either using the WDSUTIL or other approaches and how they integrated within the PowerCLI script... or if someone can point me to resources I can read... as so far I haven't  found any

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The only way I know of doing that is by using the MachineObjectOU entry in the sysprep.txt file.

The option to use a sysprep.txt file as input to an OSCustomizationSpec is currently not available (see PowerCLI Idea #143).

But you can use the CustomizationSpecsManager to create one via the API method CreateCustomizationSpec.
With the 
CustomizationSysprepText property, you can pass your sysprep.txt.


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The only way I know of doing that is by using the MachineObjectOU entry in the sysprep.txt file.

The option to use a sysprep.txt file as input to an OSCustomizationSpec is currently not available (see PowerCLI Idea #143).

But you can use the CustomizationSpecsManager to create one via the API method CreateCustomizationSpec.
With the 
CustomizationSysprepText property, you can pass your sysprep.txt.


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

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

Many thanks Luc, I was afraid of that... I don't know how to handle APIs, I'll go through the material and see..

Cheers!

Reply
0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

just in case someone is or will be in my situation I'm temporarily solving with the lines listed below. However I will definitely dig into the API solution as THAT is definitely what I need.

Cheers!

 while(!(Get-ADComputer $Row.Name)){
        Write-Host "Computer not found in AD yet..." -ForegroundColor Yellow
        Start-Sleep -Seconds 5
    }
    if(Get-ADComputer $Row.Name) {
        Get-ADComputer $Row.Name | Move-ADObject -TargetPath $OU.DistinguishedName
        Start-Sleep -Seconds 30
    }
    $Session = New-PSSession $Row.Name"." +$global -Credential $Dcreds
    Invoke-Command -Session $Session -ScriptBlock {
        gpupdate.exe /force
    }
    Disconnect-PSSession -Session $Session 
Reply
0 Kudos