Reputation: 41
I see lots of examples on running SQLPS from SQL Server Agent, but how do you call a powershell script from TSQL on demand?
I'm replacing a C# CLR function with a PowerShell script. The script will simply get a path and date modified for files in a directory structure.
What's the command to call a PowerShell script from a T-SQL stored procedure?
Upvotes: 4
Views: 6968
Reputation: 60976
Something like this:
set @sql = 'powershell.exe -file "YourScript.ps1" -nologo'
EXEC xp_cmdshell @sql
Upvotes: 1