Install-ADDSForest ok by script but not in winform

Ask your 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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
thematterneo
Posts: 11
Last visit: Fri Oct 12, 2018 2:45 am

Install-ADDSForest ok by script but not in winform

Post 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 :
  1. $DomainNameDNS = "example.local"
  2. $DomainNameNetbios = "example"
  3.  
  4. $ForestConfiguration = @{
  5. '-DatabasePath'= 'C:\Windows\NTDS';
  6. '-DomainMode' = 'Default';
  7. '-DomainName' = $DomainNameDNS;
  8. '-DomainNetbiosName' = $DomainNameNetbios;
  9. '-ForestMode' = 'Default';
  10. '-InstallDns' = $true;
  11. '-LogPath' = 'C:\Windows\NTDS';
  12. '-NoRebootOnCompletion' = $false;
  13. '-SysvolPath' = 'C:\Windows\SYSVOL';
  14. '-Force' = $true;
  15. '-CreateDnsDelegation' = $false }
  16.  
  17. Import-Module ADDSDeployment
  18. Install-ADDSForest @ForestConfiguration
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
thematterneo
Posts: 11
Last visit: Fri Oct 12, 2018 2:45 am

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

Post 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 ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
thematterneo
Posts: 11
Last visit: Fri Oct 12, 2018 2:45 am

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

Post by thematterneo »

essai.Export.ps1
(6.59 KiB) Downloaded 136 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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.
User avatar
thematterneo
Posts: 11
Last visit: Fri Oct 12, 2018 2:45 am

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

Post by thematterneo »

Ok it's done for the attachment of the file and for the deletion of code in the post.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Thank you. That is much easier to work with.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post 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
User avatar
thematterneo
Posts: 11
Last visit: Fri Oct 12, 2018 2:45 am

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

Post 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 ?
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked