1

We have a multi server system that we need to install at a client site. I would like to put together a script that can:

  1. Turn off services on remote machines
  2. Uninstall software on several remote machines
  3. Install .msi files several remote machines

I've struggled with psexec and wmic to do points #2 and #3.

It seems like there has to be an easier way without having to resort to PowerShell.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
bpeikes
  • 3,495
  • 9
  • 42
  • 80
  • I suppose most sites have a deployment software such as [SCCM](http://en.wikipedia.org/wiki/System_Center_Configuration_Manager) (formerly SMS), [IBM's Tivoli](http://en.wikipedia.org/wiki/Tivoli_Management_Framework), [CA Unicenter](http://en.wikipedia.org/wiki/CA_Unicenter) or similar. Perhaps this is even available there? – Stein Åsmul Nov 12 '14 at 11:01
  • If these deployment tools are available, I would not recommend messing with scripts of any kind. If not, please see my other answer below. – Stein Åsmul Nov 12 '14 at 11:22

1 Answers1

1

First, see this thread for WSH Remoting: Remote Install on Windows Server 2012 R2.

Then, you can perhaps you can try to use a VBScript library such as that available in VbsEdit (I don't like to make software recommendations, but I assume it is allowed since I am not affiliated and want to suggest it to solve the problem):

Here is a script to install software remotely:

' Install Software on a Remote Computer
Const wbemImpersonationLevelDelegate = 4

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
    ("WebServer", "root\cimv2", "fabrikam\administrator", _
         "password", , "kerberos:WebServer")
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate

Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\atl-dc-02\scripts\1561_lab.msi",,True)

Here is a script to stop services:

' Stop Services Running Under a Specific Account
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where StartName = '.\netsvc'")

For Each objService in colServices 
    errReturnCode = objService.StopService()
Next

Here is a screen shot from VbsEdit's script library:

VbsEdit Search Samples

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164