Solved

running netsh advfirewall set rule on multiple computers

Posted on 2016-11-17
3
60 Views
Last Modified: 2016-12-01
Hello,
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!
0
Comment
Question by:creative555
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 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

1
 

Author Comment

by:creative555
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.
Ok.


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

Author Closing Comment

by:creative555
ID: 41909474
This worked!! Was my fault. I ran it on the other server and it worked!! thank you very much!
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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

808 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