Is there a way to call powershell in SSMS Sql query window? I know Command prompt can be invoked with xp_cmdshell
. Does similar method for powershell exist ? (Note, I know about powershell window , but want to pass a script string). want to call powershell script in our Post Deployment script publish profile.
Sql-server – Call Powershell command string from Sql Query Publish profile script
powershellsql serversql-server-2017ssms
Related Question
- Sql-server – Cannot run Sql Server Agent jobs with PowerShell script
- Sql-server – Invoke SQLCMD doesn’t work when used with xp_cmdshell
- Sql-server – Archive backups with a PowerShell script launched by SQL Server Agent
- Sql-server – SSIS package deployed to SQL Server hangs when running a Powershell script
- Sql-server – SQL Visual Studio Find and Replace in Publish Profile
- Sql-server – Drop and Recreate All Objects in Database Project
- Sql-server – Executing SQL Script through PowerShell gets inconsistent results vs in SSMS
Best Answer
If you turn on SQLCMD mode (from the SSMS Query menu), you can use SQLCMD commands within an SSMS query window. A line beginning with
!!
will execute the text that follows as an OS command on the client. For example:The command will similarly be executed when the script is run with the
SQLCMD
command-line utility with this technique.Note that the "script string" mentioned in your question will need to be hard-coded in the T-SQL script.