How to Run Powershell script in SQL Server

Hello, I need to run some PS scripts on a Windows 2022 server than has SQL 2022 installed. Which PS components must be installed on the server and how do I obtain them?

Thanks.

I think I solved it on my own by doing these steps:

Open Powershell ISE as an Admin user
Run Set-ExecutionPolicy Unrestricted answer Y Yes to prompts
Run Install-module dbatools
It downloaded some files and showed “installing package dbatools”

2 Likes

Glad you found a solution!

As far as I know, as an alternative you can use xp_cmdshell or SQL Server Agent Jobs.

1 Like