Solved

running netsh advfirewall set rule on multiple computers

Posted on 2016-11-17
3
46 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

770 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