0

I am trying to write a script that can add/edit/delete firewall rules remotely through PSSessions in an automated fashion, meaning it initializes the parameters (ip, rule name, etc) in the beginning to be used for the rule creation.

$remoteName = "clientName"
$ruleName = "testRuleName"
$tgtIp = "192.168.1.1"
$workstation = New-PSSession -Authentication Kerberos -Credential "" -ComputerName $remoteName

From it request user credentials and I enter them and successfully establish the remote machine connection and proceed to the following:

Enter-PSSession $workstation
netsh advfirewall firewall add rule name = $ruleName  dir = in localip = $tgtIp action = allow

I use this method outside of the PSSession with success. However, when I enter it in the session I receive the following error.

"One or more essential parameters were not entered. Verify the required parameters, and reenter them."

I'm rather new to PSSession so any insight on what I'm doing wrong would be appreciated.

Bryan
  • 11
  • 2
  • Do you set `$ruleName` and `$tgtIp` variables in the remote session? – user4003407 Nov 07 '16 at 17:15
  • Is the error message in response to the Enter-PSSession command or the netsh command? – lit Nov 07 '16 at 17:17
  • 1
    You put a variable in your workstation's memory, then you ask the server to retrieve it from the server's memory. Like putting milk in your office fridge then calling up someone in a customer's office and asking them to open their fridge and wondering why they can't see your milk. If your script is going to be automating it, then you won't be using the interactive `Enter-PSSession` to run things, but rather `Invoke-Command` against the session. And in that case... http://stackoverflow.com/questions/40247384/passing-string-variable-to-invoke-command-scriptblock-parameter-name – TessellatingHeckler Nov 07 '16 at 17:58

0 Answers0