Im using the following command in SQL Powershell to generate csv of data returned by SQL.
Invoke-Sqlcmd -Query "myp" -ServerInstance "." | Export-Csv -Path "d:\data\MyDatabaseSizes.csv" -NoTypeInformation
The above command works perfectly fine in SQL Power Shell. but when I tried to run in from SQL using the following code
DECLARE @cmd varchar(1000)
SET @cmd = 'Invoke-Sqlcmd -Query "myp" -ServerInstance "." | Export-Csv -Path "d:\data\MyDatabaseSizes.csv" -NoTypeInformation'
EXEC xp_cmdshell @cmd
it give error that
'Invoke-Sqlcmd' is not recognized as an internal or external command,
Anyone please help me in running the command from SQL.
Thanks