locked
Psexec in Powershell Question RRS feed

  • Question

  •  Hello All,

    If I wanted to run two netsh commands in the context below, what would the syntax for that be, if possible? I've tried a few different things, but I can't seem to get it to work. I'd rather not launch a 2nd process to enable another firewall rule, if I don't have to. Here is the line I'd like to to concatenate:

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


         #Computer name for PsExec
         $PsExecCname="\\$computer"       
         #Psexec the computer by running it through a local process and enable WMI on the firewall
         Write-Host "Enabling WMI firewall rules on $($computer.ToUpper())..." -ForegroundColor Cyan
         $command ='netsh advfirewall firewall set rule group="Windows Management Instrumentation (WMI)" new  enable=yes'
         Start-Process -FilePath 'C:\windows\System32\sysinternals\psexec.exe' -ArgumentList @($PsExecCname,$command)     -Wait -WindowStyle Hidden

    Wednesday, September 4, 2013 6:05 PM

Answers

  • I don't use NETSH myself, but the documentation seems to suggest that multiple command can be executed using the "-f" parameter:

    
    -f ScriptFile
    
     Specifies that all of the netsh commands in the ScriptFile file are run.
    

    reference: 

    http://technet.microsoft.com/en-us/library/cc785383(v=ws.10).aspx


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    • Proposed as answer by Yan Li_ Friday, September 6, 2013 2:39 PM
    • Marked as answer by Yan Li_ Tuesday, September 17, 2013 2:36 AM
    Thursday, September 5, 2013 2:48 PM

All replies

  • I've tried a little bit, but I can't seem to find a way to do two commands in one process.
    Thursday, September 5, 2013 2:38 PM
  • I don't use NETSH myself, but the documentation seems to suggest that multiple command can be executed using the "-f" parameter:

    
    -f ScriptFile
    
     Specifies that all of the netsh commands in the ScriptFile file are run.
    

    reference: 

    http://technet.microsoft.com/en-us/library/cc785383(v=ws.10).aspx


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    • Proposed as answer by Yan Li_ Friday, September 6, 2013 2:39 PM
    • Marked as answer by Yan Li_ Tuesday, September 17, 2013 2:36 AM
    Thursday, September 5, 2013 2:48 PM
  • Ah, yes, I will play around with this-- thanks Al!
    Thursday, September 5, 2013 3:55 PM