I am trying to create a SQL Server agent job that will run powershell commands in SQL Server 2008 R2. I keep getting errors. A lot of powershell commands it does not recognize (i.e. Import-module, Get-module, Invoke-cmd, etc). This is the error message I get “The term ‘get-module’ is not recognized as the name of a cmdlet, function, script file, or operable program.” It works fine in the powershell ISE console. Any ideas on my problem?
These are all base cmdlets in PoSH (Host / ISE / VSCode).
If you are not able to run them, then you are not in a PoSH environment.
See if the below gets you to where you need to be.
Run Windows PowerShell Steps in SQL Server Agent https://docs.microsoft.com/en-us/sql/powershell/run-windows-powershell-steps-in-sql-server-agent?view=sql-server-2017
Running PowerShell in a SQL Agent Job