To show an example for executing powershell commands inside a stored procedure, i am going to get the current data and time using Get-Date cmdlet.
EXEC sp_configure 'show advanced options', 1
GOEXEC sp_configure 'show advanced options', 1
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
--create stored procedure
CREATE PROCEDURE SP_EXEC_Powershell
AS
BEGIN
EXEC master..xp_cmdshell 'powershell.exe Get-Date'
END
EXEC SP_EXEC_Powershell
No comments:
Post a Comment