Share via


"Unable to find a default server with Active Directory Web Services running" when calling a script with Import-module AD

Question

Wednesday, November 6, 2013 7:56 PM

Hey guys,

Having some scripts that install some apps and provisions AD SQL and SharePoint and one main script that starts in background and calls my scripts. One of the scripts creates some AD accounts and have the import-module activedirectory. When I start the script itself it completes successfully. But when I call that script from the main script it fails with "Unable to find a default server with Active Directory Web Services running".

At first I though it could be because I run the Main script with the Local Service Account which is a member of the Local Admins but I made some debugging and if I log on to my machine and start the Main script with the Admin account it fails with the same error.

Any ideas what can it be and how to resolve it?

Thanks!

KR

Ognyan

All replies (16)

Tuesday, November 19, 2013 1:44 AM ✅Answered

Hi,

Sorry for the delay. With schedule task we have chose to choose different user to run the task. If you want to find a way to run powershell script with different credential, hope the below links be helpful:

Execute PowerShell Script using alternate credential with no prompts

http://gallery.technet.microsoft.com/scriptcenter/Execute-PowerShell-Script-38881dce

http://stackoverflow.com/questions/17569678/run-powershell-script-using-different-credentials

Regards,

Yan Li

TechNet Subscriber Support

If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.

Regards, Yan Li


Wednesday, November 6, 2013 11:38 PM | 1 vote

Hi,

On your DC's check and verify that the service is running.

You can do so by typing "sc query adws" in cmd

If the service is down start it by typing "net start adws"

Let me know how it went.

Regards,

G-P


Thursday, November 7, 2013 4:14 AM

I think to use ActiveDirectory PowerShell Module there should be at least one Server 2008 (or above) running Active Directory Web Services in your environment.........

If you don't have these then better way to go would be to use Quest Active Directory Snap-ins which don't require ADWS but simply use LDAP.

Knowledge is Power{Shell}.


Thursday, November 7, 2013 7:50 AM

PLEASE READ BEFORE REPLY!

If you read carefully you will see "When I start the script itself it completes successfully." It fails only when I call the script from another script!


Thursday, November 7, 2013 8:29 AM

Sorry ......I skipped that part.

If it works when running as standalone then...it should run when you call it from another Script....Strange.
Could you please share how you are calling this script from another script ?

Knowledge is Power{Shell}.


Thursday, November 7, 2013 10:36 AM

No probs,

Here`s a link with the main script http://sdrv.ms/17e3i9r

First function is working fine but the configure accounts fails with this error. When I start the script itself it works fine.

May be this is not the best solution to make but as I am not a developer this is the best logic I could think of :)

Any other ideas are appreciated :)

KR,

Ognyan

P.S. Link with the script that configure the accounts http://sdrv.ms/HByhRq


Thursday, November 7, 2013 11:44 AM

one way of calling powershell script from other file is

.\Filename.PS1 - Just give a try and let us know

Regards Chen V [MCTS SharePoint 2010]


Thursday, November 7, 2013 11:48 AM

I saved two files in desktop

Service.PS1

Get-Service
.\process.PS1 

Process.PS1

Get-Process

C:\Users\Profile\Desktop>Service.PS1

Did the trick

Regards Chen V [MCTS SharePoint 2010]


Thursday, November 7, 2013 12:33 PM

Hi,

The warning is generated if you have several domain controllers, and not all of them have the Active Directory Management Gateway Service installed. Depending on which domain controller authenticated the workstation, the warning appears. The solution is to install the Active Directory Management Gateway Service on all of the non-Windows Server 2008 R2 domain controllers. The other solution is to ignore the warning and specify the server parameter each time when using one of the cmdlets (but that will mean the PSDrive will be unavailable).

Please also refer to the below link:

How to fix AD PowerShell error “Unable to find a default server with Active Directory Web Services running.”

Hope this helps.

Regards,

Yan Li

TechNet Subscriber Support

If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.

Regards, Yan Li


Thursday, November 7, 2013 1:19 PM | 1 vote

Guys do you even red my question and the details?!???

I HAVE SEVERAL SCRIPTS AND MAIN SCRIPTS THAT CALL THEM!

SOME OF THEM PASSES SUCCESSFULLY! ONE IS FAILING WITH THE ERROR!

THE ONE FAILING IS RUNNING OK WHEN IT IS STARTED BY ITSELF (NOT FROM THE MAIN SCRIPT)

ERROR OCCUR ONLY WHEN CALLED FROM OTHER SCRIPT!

CALLING OTHER SCRIPTS WORKS FINE!

NO PROBLEM WITH THE AD SERVICES!

Do I have to translate this to Chinese?

Read the details, think and then answer with more relevant replies! Next stupid answer will be marked as abuse!


Thursday, November 7, 2013 1:33 PM | 5 votes

Read the details, think and then answer with more relevant replies! Next stupid answer will be marked as abuse!

This is a professional forum. Your response shows that no one else should bother answering your question.

Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,300+ strong and growing)


Wednesday, November 13, 2013 12:45 PM

I think I found the issue.. whatever I do the script runs with local service credentials.... 

Used these script to debug that:

1st script having 

$ADWS = Get-Service |?{$_.Name -eq "ADWS"}

$user = whoami

$adwsStat = $adws.Status

$message = "Active Directory Web Service Status = $adwsStat

User running the script $user"

$message | Out-File "C:\Install\AdwsStat.txt"

 

2nd script calling the 1st script

$variables = Import-Clixml "c:\install\variables.xml"

$upn = $variables.netbiosName + "\Administrator"

$secpass = ConvertTo-secureString $variables.svcSpAccountsPass -asPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential ($upn,$secpass)

$script = C:\Install\AdwsStat.ps1

start-process powershell -Credential $cred -ArgumentList "-noprofile -command &{Start-Process $script -verb runas}" -Wait

and a script that registers scheduled task 

*    $A = New-ScheduledTaskAction –Execute "powershell.exe" -argument "C:\install\StartServiceCheck.ps1"*

*    $T = New-ScheduledTaskTrigger -AtStartup*

*    $u = "nt authority\localservice"*

*    $S = New-ScheduledTaskSettingsSet*

*    Register-ScheduledTask "ServiceCheck" -Action $A -user $U -Trigger $T -Settings $S*

 Result:

Active Directory Web Service Status = Running

User running the script nt authority\local service

 

So I have to find the right way calling a script with different user credentials... oooor may be giving permissions to the local service on the service?


Friday, November 22, 2013 2:43 PM

Hey Yan,

Thanks for the information! I already find a way to do that. Because my script promote ad I cannot schedule the script to run with future domain admin. So at the beginning of the script I create a schedule task with local service and after the promotion the script delete this task and create a new one that will run with the domain admin. Now everything is working perfect.

Will make a blog post about this because during the development of the script I ran in several issues and had to find some workarounds.

I have never seen this before in production so I think it will be very interesting to companies doing SharePoint dev.

It is about automated deployment of SharePoint dev environment with just a few clicks. After that the scripts install everything, Pomoting AD, Creating AD Accounts, Installing SQL, configuring SQL, Installing SP Prereqs and SP Binaries, configuring SP and installing Visual Studio.

If anyone is having interest about this and need some help and know how is very pleased to contact me :)!

KR,

Ognyan Guglev


Tuesday, December 31, 2013 7:51 PM

I am interested in this script.  Have you created a blog yet?


Tuesday, December 31, 2013 8:28 PM

You can query a Server 2003 only domain using the AD module on a client computer, however, you will have to include the -Server parameter. You will, of course, need to do some installs on your servers first, such as the ADWS and other requirements.


Thursday, January 10, 2019 6:19 PM

I am interested. Please let me know how to contact you