Pass SQl Query parameter for Powershell Script

Hi,
I have following parameters being passed from SQL Stored procedure to Powershell.
----------PowerShell Start
 param
(
      [string] $server = "SQL2",
     [string] $database  = ("Utils"),
    [string] $query = "Select * from xPM_Extract",
    [string] $extractFile = "C:\temp\csv2  export.csv"
)
 
Write-Host $server
Write-Host $database
Write-Host $query
Write-Host $extractFile
----------PowerShell END
 
Problem is that parameters for $query & $extractFile are cutoff at first encounter of space. I call my SP as
Exec usp_MYPS_Export2CSV 'Utils','Select * From Customers','C:\temp\csv2 out.csv'
Translates to
EXEC xp_cmdshell 'PowerShell -Command "C:\Util\PSScripts\SQL_Export2CSV2.ps1 -Server SQL3 -database Test -query Select * From Customers -extractFile "C:\temp\csv2  out.csv"'
Output from Powersehll is Shown below after executing above statement from SSMS.
SQL3
Test
Select
C:\temp\csv2
------------output Ends here
 
I want to see output as below.
SQL3
Test

Select * from xPM_Extract

C:\temp\csv2  export.csv
----------------------
 Please notice that Query is trimmed at Select and Output file name is trimmed at csv2.
 How to pass parameters with space in them?
 

 

Thanks.
Parents
No Data
Reply Children
No Data