Jester
Jester

Reputation: 41

How to call SQLPS from TSql in SQL Server 2008

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

Answers (1)

CB.
CB.

Reputation: 60976

Something like this:

set @sql = 'powershell.exe -file "YourScript.ps1" -nologo'

EXEC xp_cmdshell @sql  

Upvotes: 1

Related Questions