snippetsqlMinor
How can I run SQL Server Vulnerability Assessment from a SQL Job?
Viewed 0 times
canvulnerabilitysqlassessmenthowserverfromjobrun
Problem
I want to run SQL Server Vulnerability Assessment from a SQL Server Agent Job. Currently, I am attempting a job with a PowerShell script and am running a command like the one below.
I have confirmed that Invoke-SqlVulnerabilityAssessmentScan is available on the SQL Server (I can run it from the PowerShell command prompt there), but when I run my job, I receive an error stating that
The term 'Invoke-SqlVulnerabilityAssessmentScan' is not recognized as the name of a cmdlet
After looking at this Microsoft article, I am wondering if SQL Agent only has a subset of PowerShell cmdlets that it can access.
How can I run the vulnerability assessment scan from a SQL Job?
Invoke-SqlVulnerabilityAssessmentScan -ServerInstance $(ESCAPE_DQUOTE(SRVR)) -Database AdventureWorksI have confirmed that Invoke-SqlVulnerabilityAssessmentScan is available on the SQL Server (I can run it from the PowerShell command prompt there), but when I run my job, I receive an error stating that
The term 'Invoke-SqlVulnerabilityAssessmentScan' is not recognized as the name of a cmdlet
After looking at this Microsoft article, I am wondering if SQL Agent only has a subset of PowerShell cmdlets that it can access.
How can I run the vulnerability assessment scan from a SQL Job?
Solution
You are getting that error because the module is not imported.
You have to use
see : Running PowerShell in a SQL Agent Job
You have to use
import-module -name sqlserver # or path to the modulesee : Running PowerShell in a SQL Agent Job
Code Snippets
import-module -name sqlserver # or path to the moduleContext
StackExchange Database Administrators Q#245781, answer score: 5
Revisions (0)
No revisions yet.