PowerCLI

 View Only
  • 1.  Join VM to Domain in specific OU

    Posted Oct 25, 2023 07:38 AM

    Good day.

    In powerCLI i want create new VM, and use  "New-OSCustomizationSpec -Type NonPersistent" with join to domain.

    Has OSCustomizationSpec a parameter indicating a specific OU? 

    It is necessary that when entering the domain, the server is created in the required OU

    Thank you.



  • 2.  RE: Join VM to Domain in specific OU

    Posted Oct 25, 2023 08:04 AM

    Afaik that is not possible.
    Use the Domain parameter on the OSCustomizationSpec, the VM will normally appear in the Computers OU.

    Then use the Move-ADObject cmdlet to move the computer to the desired OU.



  • 3.  RE: Join VM to Domain in specific OU

    Posted Oct 25, 2023 01:21 PM

    In vSphere 8U2 this got introduced but I'm not sure where in the API it's available PowerCLI-vise, but you can use REST API:

    Set Guest Customization | VM | vSphere vCenter REST APIs (vmware.com)

    "sysprep": { "domain": { "domain": "string", "domain_OU": "string", "domain_password": "string", "domain_username": "string", "type": "WORKGROUP", "workgroup": "string"

    More news here:
    https://core.vmware.com/resource/whats-new-vsphere-8-update-2#sec31672-sub7



  • 4.  RE: Join VM to Domain in specific OU
    Best Answer

    Posted Oct 25, 2023 02:32 PM

    Nice, I learned something new today 

    There are cmdlets available for these REST calls.
    See Initialize-VmGuestCustomizationSetSpec and Invoke-SetVmGuestCustomization
    See the Code Samples at 
    Set Guest Customization



  • 5.  RE: Join VM to Domain in specific OU

    Posted Apr 17, 2025 10:53 AM

    I know the thread is over a year old, but for the next person needing to set a custom OU path, here's a simple way without needing to dive down the API route.

    $osCustSpecName = 'OS Specification Name'
    $organizationalUnit = 'OU=PathToOU,DC=Domain,DC=COM'

    $osCustSpec
    = Get-View CustomizationSpecManager
    $specItem = $osCustSpec.GetCustomizationSpec($osCustSpecName)
    $specItem.Spec.Identity.Identification.DomainOU = $organizationalUnit
    $osCustSpec.OverwriteCustomizationSpec($specItem)



  • 6.  RE: Join VM to Domain in specific OU

    Posted Apr 22, 2025 11:49 AM

    Hi p0werShelldude,

    this is exactly what I was looking for. But it is not working in my environment, cause the $specItem.Spec.Identity.Identification does not contain a DomainOU Property.

    With which vCenter Version did you get this working? My is 8.0.3.




  • 7.  RE: Join VM to Domain in specific OU

    Posted Apr 22, 2025 11:53 AM
    Edited by p0werShelldude Apr 22, 2025 02:07 PM

    I'm using vCenter 8.0.3 Build: 24322831 with PowerCLI 13.3.0 Build 24145081. I was able to confirm that PowerCLI version 12.5.X it does not display the DomainOU property, but in version 13.3.X it does. Are you able to upgrade your PowerCLI and try again? 




  • 8.  RE: Join VM to Domain in specific OU

    Posted 10 days ago

    p0werShelldude -- The OU this explanation helped me as well, but the OU I'm dealing with has spaces in them (I know, spaces are bad), and although the code seems to function, the VMs don't join the OU. Have you seen this behavior, with regard to spaces?




  • 9.  RE: Join VM to Domain in specific OU

    Broadcom Employee
    Posted 8 days ago

    I just used the sample code to specify an OU with a space in it (two spaces in fact):

    OU=Space Test,OU=LAB Servers,DC=lab,DC=example,DC=com

    And the join completed to the requested OU.  If you look at the file C:\Windows\Panther\unattend.xml on the deployed machine, do you see the expected value in the Identification  MachineObjectOU definition of the unattend file?  I did my testing with Windows Server 2022, so if you don't see that unattend file, check the logs under C:\windows\temp\vmware-imc, thats what pointed me to the panther directory.