title: How to correctly run powershell script with here-strings?
body: <p>I am working with Sharepoint service. My python script runs powershell script and download file. I have following powershell script for downloading file from Sharepoint:</p>
  
  <pre><code>[CmdletBinding()]
  param(
  [Parameter(Mandatory=$True,Position=1)]
  [String]$UserName,
  [Parameter(Mandatory=$True,Position=2)]
  [String]$Password,
  [Parameter(Mandatory=$True, Position=3)]
  [String]$FileUrl,
  [Parameter(Mandatory=$True, Position=4)]
  [String]$DestinationFilePathName
  )
  
  try
  {
      # Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM.
      Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location)
      Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location)
  
      # Create a credential object using the username and password supplied.
      $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, (ConvertTo-SecureString $Password -AsPlainText -Force))
      $client = New-Object System.Net.WebClient 
      $client.Credentials = $Creds
      $client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
      Write-Host "Downloading file" $FileUrl "to" $DestinationFilePathName -ForegroundColor Green
      $client.DownloadFile($FileUrl, $DestinationFilePathName)
      $client.Dispose()
  }
  catch
  {
      # Error occurred.
      $_.Exception.Message
      $exitcode = -1
  }
  exit $exitcode
  </code></pre>
  
  <p>In python powershell script is called by the following code:</p>
  
  <pre><code>...
  shell_script = "powershell -ExecutionPolicy Unrestricted -Command \"&amp; %s %s %s %s %s\"" % (self.config['path_shell_download_script'], user_email, self.password, self.config['url_download_from_sp'], self.config['sp_extract_path'])
          if subprocess.call(shell_script, shell=True) != 0:
              raise Exception("Error while retrieving file: %s." % (self.config['url_download_from_sp']))
  ...
  </code></pre>
  
  <p>Everything ok, this script works with my credentials correctly. But when i try run script with admin credentials it does not work. Problems with password of admin, because password is something like - @'M@+12w-zT!3Lv)</p>
  
  <p>How i can correctly escape this symbols in my password?</p>