Install-ADDSForest ok by script but not in winform

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
thematterneo
Posts: 11
Joined: Thu Mar 06, 2014 2:22 pm

Install-ADDSForest ok by script but not in winform

Post by thematterneo » Wed Aug 08, 2018 7:46 am

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 :
  1. $DomainNameDNS = "example.local"
  2.  
  3. $DomainNameNetbios = "example"
  4.  
  5.  
  6.  
  7. $ForestConfiguration = @{
  8.  
  9. '-DatabasePath'= 'C:\Windows\NTDS';
  10.  
  11. '-DomainMode' = 'Default';
  12.  
  13. '-DomainName' = $DomainNameDNS;
  14.  
  15. '-DomainNetbiosName' = $DomainNameNetbios;
  16.  
  17. '-ForestMode' = 'Default';
  18.  
  19. '-InstallDns' = $true;
  20.  
  21. '-LogPath' = 'C:\Windows\NTDS';
  22.  
  23. '-NoRebootOnCompletion' = $false;
  24.  
  25. '-SysvolPath' = 'C:\Windows\SYSVOL';
  26.  
  27. '-Force' = $true;
  28.  
  29. '-CreateDnsDelegation' = $false }
  30.  
  31.  
  32.  
  33. Import-Module ADDSDeployment
  34.  
  35. Install-ADDSForest @ForestConfiguration

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Aug 08, 2018 7:55 am

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.

User avatar
thematterneo
Posts: 11
Joined: Thu Mar 06, 2014 2:22 pm

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

Post by thematterneo » Wed Aug 08, 2018 8:23 am

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 ?

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Aug 08, 2018 9:01 am

Run the commands in a job. I mentioned Azure because those modules have the same issue and running as a job fixes it.

User avatar
thematterneo
Posts: 11
Joined: Thu Mar 06, 2014 2:22 pm

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

Post by thematterneo » Wed Aug 08, 2018 9:33 am

essai.Export.ps1
(6.59 KiB) Downloaded 42 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 ?
Last edited by thematterneo on Wed Aug 08, 2018 10:54 am, edited 1 time in total.

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Aug 08, 2018 10:20 am

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.

User avatar
thematterneo
Posts: 11
Joined: Thu Mar 06, 2014 2:22 pm

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

Post by thematterneo » Wed Aug 08, 2018 10:55 am

Ok it's done for the attachment of the file and for the deletion of code in the post.

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Aug 08, 2018 11:47 am

Thank you. That is much easier to work with.

jvierra
Posts: 13891
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed Aug 08, 2018 11:50 am

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

User avatar
thematterneo
Posts: 11
Joined: Thu Mar 06, 2014 2:22 pm

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

Post by thematterneo » Wed Aug 08, 2018 12:47 pm

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 ?

Locked