title: Pass argument from Powershell to Batch script
body: <p>I need to pass a password with special characters from powershell script <code>automation.ps1</code> to batch script <code>batch_script.bat</code> which pipes it to <code>main.py</code>. Piping from <code>batch_script.bat</code> to <code>main.py</code> works fine, that is authentication succeeds. However, when I run the entire procedure described above, authentication fails, but <code>echo</code>ing the password shows the correct password string.</p>
  
  <p>My guess is that there are issues with special characters. What is a safe way to pass these strings?</p>
  
  <p><strong>Background</strong></p>
  
  <p>I want to automate the daily download from some external source via a Python script <code>main.py</code>. This process requires a password. So I wrote a <code>batch_script.bat</code> which pipes the password to the Python script when prompted for it. However, I don't want to store the password as plain text in the batch script, so I encrypted the password and wrote another layer <code>automation.ps1</code> which decrypts the password and passes it as plain text to <code>batch_script.bat</code>.</p>
  
  <p><strong>automation.ps1</strong></p>
  
  <pre><code># get password
  $securePassword = Get-Content "&lt;file_path&gt;" | ConvertTo-SecureString
  $credentials = New-Object System.Management.Automation.PsCredential("&lt;user_name&gt;",$securePassword)
  $unsecurePassword = ($credentials).GetNetworkCredential().Password
  
  # call script
  $script = "&lt;path&gt;\batch_script.bat"
  $args = @("`"&lt;user name&gt;`"","`"$unsecurePassword`"")
  start-process $script $args
  </code></pre>
  
  <p><strong>batch_script.bat</strong></p>
  
  <p>(I am aware that in this example I discard the passed username, just wanted to preserve the fact that I pass multiple arguments in case there is any relevance to it)</p>
  
  <pre><code>@echo off
  SET username=%~1
  SET password=%~2
  echo(%password%|python main.py
  </code></pre>