Hi Konstantin,
can you post the content of the script so that we can check it out and comment?
Thanks and Regards,
Stoyan
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have two SQL boxes one SQL 2014 Developer edition and a second SQL 21019 standard on two different Windows boxes.
My PowerShell script working in SQL 2014 Developer but not in SQL 21019. It generates error
The term 'C:\Path_to_File\ExportToExcel.ps1'
is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
I tested this script from the command line and it working perfectly.
The sql code simple exec xp_cmdshell 'PowerShell.exe "C:\Path_to_File\ExportToExcel.ps1"'
Run command xp_cmdshell 'PowerShell.exe' doesn't generate any errors any errors
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
NULL
PS C:\Windows\system32>
Any ideas?
Thank you
Konstantin
Hi Konstantin,
can you post the content of the script so that we can check it out and comment?
Thanks and Regards,
Stoyan
Hi Stoyan this is a script example
Remove-Item "*.csv"
$sqlData = Invoke-Sqlcmd -Query "Select * From User" -Database "USER" -Server "SERVER1"
$sqlData | Export-Csv -NoTypeInformation -Path "C:\Path_to_File\User.csv" –Delimiter “|”
This code working if I run it from the command line.
Thank you
An example isn't the code that fails! I expect if you take a look at the script you'll find a missing (or extra) quote somewhere.
I'd start by removing the quotes that surround *.csv, USER, SERVER and C:\Path_to_File\User.csv
this code I run
exec xp_cmdshell 'PowerShell.exe "C:\Path_to_File\ExportToExcel.ps1"'