Powershell

JCJohnson76
JCJohnson76 used Ask the Experts™
on
I will like to run a exe located in a particular directory.  After exe is performed I will like then to a restart a service.  

I will like to run this exe on all Domain Controllers in my environment.  Does anyone know how to performed this in Powershell.

The cmdlets I will like to use for the DC's are "Get-ADDomainControllers"

The user the foreach statement.

Example of directory: Path of the exe;  Filename of exe (watchdog.exe)


Can someone please provide the syntax for this
D:\Program files\Monitor\
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
FOXActive Directory/Exchange Engineer
Top Expert 2015

Commented:
Is the .exe sitting on each domain controller?

Author

Commented:
yes; same path
FOXActive Directory/Exchange Engineer
Top Expert 2015
Commented:
Try the below

$DC=Get-ADDomainController | ft samaccountname | foreach{start-process -filepath 'D:\Program files\Monitor\watchdog.exe' | Restart-Service theservicename
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
does not work;

Lets use another example

Lets say Systernal "pskill" is locate under the c:\tools\    This path is located on all DC's

And I have notepad running on all DC"s and I want to use pskill to kill this process.  How would I be able to do it using Get-ADDomaincontrollers
IT Infrastructure Architect
Commented:
pskill can be used to remotely kill the processes.

See the example below..
Import-Module Activedirectory
Get-ADDomainController -Filter * | %{
	& 'C:\Tools\pskill.exe' "\\$($_.name)" notepad
}

Open in new window

Pskill.exe should be there in the specified path where you run the script.

Author

Commented:
Subsun,

Thanks, it worked a like a charm

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial