Page 1 of 2

Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 7:46 am
by thematterneo
Hello,

In Powershell, no problem for the installation of new forest, but when I create just one button in new form on PowerShell Studio 2018 it doesn't work (message : WARNING: The plug-in for "Active Directory Domain Services" is taking more time to load than expected). Maybe someone can help me for this problem ?
The script :

Code: Select all

$DomainNameDNS = "example.local"
$DomainNameNetbios = "example"

$ForestConfiguration = @{
'-DatabasePath'= 'C:\Windows\NTDS';
'-DomainMode' = 'Default';
'-DomainName' = $DomainNameDNS;
'-DomainNetbiosName' = $DomainNameNetbios;
'-ForestMode' = 'Default';
'-InstallDns' = $true;
'-LogPath' = 'C:\Windows\NTDS';
'-NoRebootOnCompletion' = $false;
'-SysvolPath' = 'C:\Windows\SYSVOL';
'-Force' = $true;
'-CreateDnsDelegation' = $false }

Import-Module ADDSDeployment
Install-ADDSForest @ForestConfiguration

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 7:55 am
by jvierra
Some modules may require STA/MTA threading and some may need to be loaded before the form is launched. MAny newer modules such as Azure modules will not run in a form and can be used if run as a job.

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 8:23 am
by thematterneo
Thank you.
But it's not azure, but just install new forest in Windows 2012 R2.
I create GUI to install new forest, gpo, OUs, Groups and Users AD Accounts but the only problem it's to use button to run the installation of new forest, maybe there is a solution to resolve this kind of problem ?

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 9:01 am
by jvierra
Run the commands in a job. I mentioned Azure because those modules have the same issue and running as a job fixes it.

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 9:33 am
by thematterneo
essai.Export.ps1
(6.59 KiB) Downloaded 39 times
Ok thank you. So I need to put for the command "Add-WindowsFeature -Name $Feature -IncludeManagementTools" :

$test={"Add-WindowsFeature -Name $Feature -IncludeManagementTools"} start-job -ScriptBlock $test
What do you think ? Do you think if it's ok like this ?

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 10:20 am
by jvierra
Please do not post large scripts. Please include as an a file attachment.

Just edit your post and delete the code block then attach the PSF file.

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 10:55 am
by thematterneo
Ok it's done for the attachment of the file and for the deletion of code in the post.

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 11:47 am
by jvierra
Thank you. That is much easier to work with.

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 11:50 am
by jvierra
All of the following has to be run in a job. Test it at a command prompt until the job works then use it in the form.

You can also just place all of the button event into a job. Use the JobTracker control.

Code: Select all

	$DomainNameDNS = $DNSName
	$DomainNameNetbios = "$NameNetbiosDxx"
	
	$ForestConfiguration = @{
		'-SafeModeAdministratorPassword'    = (ConvertTo-SecureString 'P@ssw0rd' -AsPlainText -Force);
		'-DatabasePath'					    = 'C:\Windows\NTDS';
		'-DomainMode'					    = 'Default';
		'-DomainName'					    = $DomainNameDNS;
		'-DomainNetbiosName'			    = $DomainNameNetbios;
		'-ForestMode'					    = 'Default';
		'-InstallDns'					    = $true;
		'-LogPath'						    = 'C:\Windows\NTDS';
		'-NoRebootOnCompletion'			    = $false;
		'-SysvolPath'					    = 'C:\Windows\SYSVOL';
		'-Force'						    = $true;
		'-CreateDnsDelegation'			    = $false
	}
	
	Import-Module ADDSDeployment
	Install-ADDSForest @ForestConfiguration

Re: Install-ADDSForest ok by script but not in winform

Posted: Wed Aug 08, 2018 12:47 pm
by thematterneo
Sorry but I'm french and my english is very bad, I don't understand that you said; could you show me please ? Maybe with an example ?