title: Powershell script to pass parameters using psexec in commandline
body: <p>Hi I am trying to run a powershell script remotely to create the webapplication pool for 2 servers: Below is the code in my Website_pararrel.ps1 which i run on 2nd server:</p>
  
  <pre><code> workflow pbatch{
  
   param ([string]$iisAppName,[string]$directoryPath,[string]$iisAppPoolName, 
   [string]$un,[string]$pw,[string]$path,[string]$servers)
  
   foreach -parallel ( $server in $servers)
   {             
       (InlineScript{
  
       Import-Module WebAdministration
  
       Set-Location "IIS:\AppPools"
  
      if (Test-Path $Using:iisAppPoolName -pathType container)
       {
          Remove-Item $Using:iisAppPoolName -recurse   
       }
  
          New-Item $Using:iisAppPoolName -Force           
          Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name managedRuntimeVersion -Value v4.0
          Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name processmodel.identityType -Value 3
          Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name ProcessModel.userName -Value $Using:un1
          Set-ItemProperty -Path IIS:\AppPools\WhereIsTest -Name processmodel.password -Value $Using:pw1
  
  
  
  
  
          })
  
  
     }
  
  }
  
  pbatch -servers $servers -iisAppPoolName $iisAppPoolName -un $un -pw $pw 
  </code></pre>
  
  <p>and i run using this command from 1st servers:</p>
  
  <pre><code>Psexec \\CPDEVWEB03.blfdev.lab /s cmd /c %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file D:\Website_Parallel.ps1 -servers "xyz" -iisAppPoolName "Test" -un "***\****" -pw "*******"
  </code></pre>
  
  <p>But i get this error: </p>
  
  <pre><code> Test-Path : Cannot bind argument to parameter 'Path' because it is an empty
   string.
   At pbatch:14 char:14
   +
   + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingVa
   lidationException
   + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
   lowed,Microsoft.PowerShell.Commands.TestPathCommand
   + PSComputerName        : [localhost]
  
    New-Item : Cannot bind argument to parameter 'Path' because it is an empty
   string.
    t pbatch:14 char:14
   +
   + CategoryInfo          : InvalidData: (:) [New-Item], ParameterBindingVal
   idationException
  + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
  lowed,Microsoft.PowerShell.Commands.NewItemCommand
  + PSComputerName        : [localhost]
  
    Set-ItemProperty : Cannot process argument because the value of argument 
    "obj"
    is null. Change the value of argument "obj" to a non-null value.
    At pbatch:14 char:14
    +
    + CategoryInfo          : InvalidArgument: (:) [Set-ItemProperty], PSArgum
    entNullException
    + FullyQualifiedErrorId : InvalidArgument,Microsoft.PowerShell.Commands.Se
    tItemPropertyCommand
  + PSComputerName        : [localhost]
  
   Set-ItemProperty : Cannot process argument because the value of argument 
   "obj"
    is null. Change the value of argument "obj" to a non-null value.
    cmd exited on CPDEVWEB03.blfdev.lab with error code 0.
  </code></pre>
  
  <p>Somehow the values of the variables from my commandline script is not getting passed to my powershell script. Any help would be greatly appreciated.</p>