I wrote the following in my powershell function app:
param($Timer)
$currentUTCtime = (Get-Date).ToUniversalTime()
if ($Timer.IsPastDue) {
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
$connectionString = "<connectionstring>"
$querystr = "select * from MyTable
Invoke-Sqlcmd -ConnectionString $connectionString -Query $querystr -OutputSqlErrors $true
The requirements.psd1 has the following:
@{
'Az' = '10.*'
}
It gives an error when i run it :
ERROR: The term 'Invoke-Sqlcmd' is not recognized as a name of a cmdlet, function, script file, or executable program.
System.Management.Automation.CommandNotFoundException
what do i need to include in the file to make this work ?
2
Answers
Invoke-Sqlcmd
Cmdlet is part ofSqlServer
module. Hence the finalrequirements.psd1
file should looks like this:To resolve the error, you need to install
SqlServer module
.Install the
Sqlserver module
with the commandInstall-Module sqlserver
:You can check if the
Invoke-sqlcmd
is available in the installedSqlServer module
with the commandGet-Command -Module SqlServer
.Import-Module sqlserver
:Then as @Abdul Niyas P M mentioned, add
'SqlServer' = '22.*'
in therequirements.psd1
.After following above steps, I ran the same code in my environment.
Response: