r/PowerShell • • Feb 18 '22

Question How do I remotely issue a command for executing the ".exe" file to all the windows domain computers at once?

I want all windows computers connected to the same Domain to want to get the ".exe" file and run it without physically visiting each machine. So I need a central way of distributing the .exe file and sending a command to run it.

How should i do this?

6 Upvotes

23 comments sorted by

25

u/bringtheremedy Feb 18 '22

Hi, I think you're better off using a deployment tool like SCCM or PDQ Deploy if available.

If it has to be PowerShell, you could use Copy-Item to copy the exe and then Invoke-Command to start it on each computer.

3

u/orwiad10 Feb 18 '22

Also an admin path has to be available and you need proper credentials obviously.

11

u/slatts7 Feb 18 '22

The Finglonger should do the trick.

3

u/anynonus Feb 18 '22

what-if we actually had a finglonger

3

u/Greasy_Exc Feb 18 '22

This thing isn’t worth the gold it’s made of

26

u/[deleted] Feb 18 '22

if you’re an IT worker who is responsible for software at your company, then take no offense to this but you need to do some more research and immerse yourself in learning about industry solutions to common requests like this.

while you CAN do what you’re asking in powershell with a one liner already answered in this thread, you should just google “managing software in a domain environment” or “configuration management” or “mdm.”

you need some fundamentals.

0

u/[deleted] Feb 18 '22

[deleted]

2

u/[deleted] Feb 18 '22

laptops is mobile devices. a lot of mdms dont just do mdm. they’re config mabagers too.

1

u/[deleted] Feb 18 '22

Honestly I used Microsoft’s Intune MDM to install ever app I need, Change every registry edit I need and run powershell scripts on my whole network, i like it

0

u/[deleted] Feb 18 '22

[deleted]

1

u/[deleted] Feb 19 '22

I have a series of update rings configured in intune, perhaps that is WU for business i just dont know it by that name, but basicly i have 2 sites update 1st then after some testing everyone else gets updates.

2

u/admin_username Feb 21 '22

Guys, in the future can we NOT help ransomware script kiddies?

3

u/[deleted] Feb 18 '22

Psexec? Not sure what your exe does

3

u/[deleted] Feb 18 '22

+1 for psexec or group policy.

3

u/z386 Feb 18 '22

This would work in principal:

$Session = New-PSSession -ComputerName "computer1"
Copy-Item -Path "c:\my.exe" -Destination "c:\my.exe" -ToSession $Session
Invoke-Command -Session $Session { c:\my.exe }

3

u/weedsman Feb 18 '22

This is going to trigger so many alerts… lol

1

u/[deleted] Feb 18 '22

I’m not gonna write the whole script out for you but hope this helps

Make fileshare Put exe on it

Invoke-command { to run on remote machine Ps-drive to mount file share Copy-item to copy the exe to your remote machine from the ps drive Start-process to start the exe Delete the ps drive at the end }

1

u/thesterv Feb 19 '22

Big fan of PDQ myself. Heard they recently bought Smart Deploy so they likely support imaging now. Hoping to introduce it at my new job—currently using Kace, not a fan of the bloat and unintuitive interface.

1

u/syntek_ Feb 20 '22

This is exactly what group policy is for. Otherwise, how do you handle unreachable computers? Laptops that are not on-site or on-VPN? Desktops that are shutdown? Group policy can handle this multiple ways.. You can add a startup script to run your exe, or create a run-once scheduled task. Place the file in a share or even somewhere in \youdomain.local\NETLOGON and reference it there.