Highlighted
Expert
Expert

JoinDomain_Task + cmdlet

Jump to solution

Is there also a cmdlet for the JoinDomain_Task?

So i can configure the Authentication Services

0 Kudos
1 Solution

Accepted Solutions
Highlighted
VMware Employee
VMware Employee

Hi Rob,

Executing JoinDomain_task in PowerCLI 4.1 is a little bit tricky since some of the new vSphere 4.1 host managers are missing in VMware.Vim assembly. However you can workaround the problem with this simple script:

function GetHostADAuthManagerMoRef($vmHost) {
	$filter = New-Object VMware.Vim.PropertyFilterSpec
	$filter.ObjectSet += New-Object VMware.Vim.ObjectSpec
	$filter.ObjectSet[0].Obj = $vmHost.ConfigManager.AuthenticationManager
	$filter.PropSet += New-Object VMware.Vim.PropertySpec
	$filter.PropSet[0].Type = "HostAuthenticationManager"
	$filter.PropSet[0].All = $true
	
	$collector = Get-View $vmHost.Client.ServiceContent.PropertyCollector 
	$content = $collector.RetrieveProperties($filter)
	$supportedStore = $content[0].PropSet | ? {$_.Name -eq "supportedStore"} 
	$result = $supportedStore.Val | ? {$_.Type -eq "HostActiveDirectoryAuthentication"}
	
	return [http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim41($result)
}

Connect-VIServer 'MyVC' -User 'Username' -Pass 'Password'
$vmHost = Get-View (Get-VMHost 'MyHost')
$authManagerMoRef = GetHostADAuthManagerMoRef($vmHost)

$taskMoRef = $vmHost.Client.VimService.JoinDomain_Task($authManagerMoRef, 'DomainToJoin', 'DomainUsername', 'Password')
$vmHost.WaitForTask([http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim($taskMoRef))

Regards,

Yasen Kalchev

PowerCLI Dev Team

Yasen Kalchev, vSM Dev Team

View solution in original post

0 Kudos
9 Replies
Highlighted
User Moderator
User Moderator

Afaik there is no cmdlet for the JoinDomain_Task. The JoinDomain_Task in HostActiveDirectoryAuthentication is new in PowerCLI 4.1. In the VMware vSphere PowerCLI Change Log there is no cmdlet mentioned for this task.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Highlighted
Expert
Expert

I am struggeling a little bit with the SDK on this subject.

How can you enable the JoinDomain_task on the host?

0 Kudos
Highlighted
User Moderator
User Moderator

Do you mean the call to JoinDomain_Task ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
Highlighted
Expert
Expert

That's the one. I need to configure the authentication services to active directory.

0 Kudos
Highlighted
VMware Employee
VMware Employee

Hi Rob,

Executing JoinDomain_task in PowerCLI 4.1 is a little bit tricky since some of the new vSphere 4.1 host managers are missing in VMware.Vim assembly. However you can workaround the problem with this simple script:

function GetHostADAuthManagerMoRef($vmHost) {
	$filter = New-Object VMware.Vim.PropertyFilterSpec
	$filter.ObjectSet += New-Object VMware.Vim.ObjectSpec
	$filter.ObjectSet[0].Obj = $vmHost.ConfigManager.AuthenticationManager
	$filter.PropSet += New-Object VMware.Vim.PropertySpec
	$filter.PropSet[0].Type = "HostAuthenticationManager"
	$filter.PropSet[0].All = $true
	
	$collector = Get-View $vmHost.Client.ServiceContent.PropertyCollector 
	$content = $collector.RetrieveProperties($filter)
	$supportedStore = $content[0].PropSet | ? {$_.Name -eq "supportedStore"} 
	$result = $supportedStore.Val | ? {$_.Type -eq "HostActiveDirectoryAuthentication"}
	
	return [http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim41($result)
}

Connect-VIServer 'MyVC' -User 'Username' -Pass 'Password'
$vmHost = Get-View (Get-VMHost 'MyHost')
$authManagerMoRef = GetHostADAuthManagerMoRef($vmHost)

$taskMoRef = $vmHost.Client.VimService.JoinDomain_Task($authManagerMoRef, 'DomainToJoin', 'DomainUsername', 'Password')
$vmHost.WaitForTask([http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim($taskMoRef))

Regards,

Yasen Kalchev

PowerCLI Dev Team

Yasen Kalchev, vSM Dev Team

View solution in original post

0 Kudos
Highlighted
Expert
Expert

Hi Yasen,

Thanks for your quick response. I will test it asap.

0 Kudos
Highlighted
Expert
Expert

It work perfectly. Thanks a lot!

0 Kudos
Highlighted
User Moderator
User Moderator

Fyi I created a function around this bypass and added a function to retrieve the authentication settings.

See my Script vSphere 4.1 AD Authentication post.

____________

Blog: LucD notes

Twitter: lucd22


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

Highlighted
Expert
Expert

Luc thanks for the great functions.

0 Kudos