running netsh advfirewall set rule on multiple computers

Posted on 2016-11-17
Medium Priority
Last Modified: 2016-12-01
I wanted to ask you how can I run this command on multiple computers at once?
The best way would be to specify server list in servers.txt and then run this on multiple servers.

o      netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes

thank you very much!
Question by:creative555
  • 2
LVL 16

Accepted Solution

Dustin Saunders earned 2000 total points
ID: 41891873
Something like this would do the trick, with one computer name per line in the text file.  If you're not on a domain with permission, we'd need a different way though.
$textFile = "C:\Path\To\File.txt"
$computers = Get-Content $textFile

foreach ($computer in $computers)
    $cmd = 'netsh -r ' + $computer + ' advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes'   
    Invoke-Expression $cmd 

Open in new window


Author Comment

ID: 41894383
hm. It didn't work on the remote computer. I have no problem running enter-pssession directly. Running it in elevated prompt and with the domain admin account.

WARNING: Could not obtain host information from machine: [Server02.testtarget.local]. Some commands may not be available.
The RPC server is unavailable

Author Closing Comment

ID: 41909474
This worked!! Was my fault. I ran it on the other server and it worked!! thank you very much!

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Loops Section Overview

624 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