Solved

running netsh advfirewall set rule on multiple computers

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SBS 20011 to Office 365 7 57
Folder Permission Powershell 4 35
Powershell - check csv format 4 32
Disk Ram Peak 1 19
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
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 …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now