Solved

Powershell

Posted on 2016-08-30
6
77 Views
Last Modified: 2016-09-09
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\
0
Comment
Question by:JCJohnson76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:FOX
ID: 41776663
Is the .exe sitting on each domain controller?
0
 

Author Comment

by:JCJohnson76
ID: 41776683
yes; same path
0
 
LVL 16

Assisted Solution

by:FOX
FOX earned 50 total points
ID: 41776700
Try the below

$DC=Get-ADDomainController | ft samaccountname | foreach{start-process -filepath 'D:\Program files\Monitor\watchdog.exe' | Restart-Service theservicename
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

Author Comment

by:JCJohnson76
ID: 41776940
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
0
 
LVL 40

Accepted Solution

by:
Subsun earned 450 total points
ID: 41779934
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.
0
 

Author Closing Comment

by:JCJohnson76
ID: 41791296
Subsun,

Thanks, it worked a like a charm
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question