views:

1721

answers:

3

I have two servers Server A and Server B i want to Stop server A from Server B remotely using powershell script Can anybody help me on this its urgent. Thank you in advance

+2  A: 

One of the simplest ways to do this is really with just a command line execution using PsExec. And send over to the machines

IISReset /STOP or /START or /RESTART

So you'd do something like this

PsExec \\Server2 -u Administrator -p somePassword IISReset /STOP

Just be careful with password management if you go this route or any route that involves some type of admin level account impersonation so that no one can get a plain text copy of the admin password.

Chris Marisic
+4  A: 

Because you asked for Powershell:

(Get-WmiObject Win32_Service -ComputerName ServerA -Filter"Name='iisadmin'").InvokeMethod("StopService",$null)

Agreed this question should be moved to ServerFault.

fenster
A: 

Hi,

I tested the following code "PsExec \Server2 -u Administrator -p somePassword IISReset /STOP" and it works fine. However, it does not if called from within Asp.net app.

I want to start and stop IIS on remote server using asp.net website.

When i try to stop IIS on remote PC, it raises error. I am using the following syntax "PsExec \Server2 -u Administrator -p somePassword IISReset /STOP". This works fine when called within VS IDE or from another C# code. However does not work when called from within asp.net app. I am using "Administrator" as user which has Admin access to both of machines.

Can anyone help me on this?

Regards,

Chandan

Chandan