title: Powershell passing variables to remote script
body: <p>I have the following cmd file:-</p>
  
  <pre><code>PowerShell.exe -noexit E:\wwwroot\domains\processes\AddDirectory.ps1 -Param testdomain.co.uk
  </code></pre>
  
  <p>which goes through to:-</p>
  
  <pre><code>$Session = New-PSSession -ComputerName 192.168.0.25
  $script = {
  Param($Param1)
  set-executionpolicy unrestricted -force
  
  # Set Variables
  $domain = $Param1
  $sitepath = "e:\domains\" + $domain
  
  # Check for physical path
  if (-not (Test-Path -path $sitePath))
  {
  New-Item -Path $sitepath -type directory 
  New-Item -Path $sitepath\wwwroot -type directory 
  }
  set-executionpolicy restricted -force     
  }
  Invoke-Command -Session $Session -ScriptBlock $script
  </code></pre>
  
  <p>But it just runs but does nothing. </p>
  
  <p>If I declare the $domain variable as $domain = 'testdomain.co.uk' it works but it doesn't want to pass through the var from the cmd file. What am I doing wrong? I've tried to put it in the Invoke-Command as -ArgumentsList -$Param1 but that doesn't work either.....</p>
  
  <p>Any ideas greatfully received</p>
  
  <p>Thanks
  Paul</p>
  
  <p>Update - I've updated my code as per below but getting same issue:-</p>
  
  <pre><code>param($domainName)
  $script = {
      Param($Param1)
      set-executionpolicy unrestricted -force
      # Set Variables
      $domain = $Param1
      $sitepath = "e:\domains\" + $domain
      # Check for physical path
      if (-not (Test-Path -path $sitePath))
      {
          New-Item -Path $sitepath -type directory
          New-Item -Path $sitepath\wwwroot -type directory
          New-Item -Path $sitepath\db -type directory
          New-Item -Path $sitepath\stats -type directory
      }
      set-executionpolicy restricted -force
  }
  
  $Session = New-PSSession -ComputerName 192.168.0.25
  
  Invoke-Command -Session $Session -ScriptBlock $script -ArgumentList $domainName
  </code></pre>