Scenario: After you add a runbook activity which runs a powershell script. The activity fails with error.
e.g connecting to Azure using an app id.
The term 'Connect-AzAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
If you open the runbook using runbook tester it may work fine.
But when you click run in the Designer it will fail.
This happens because the required modules are not installed in the runbook service context.
To do this add a new Run . Net script activity and add the lines to install those modules in the it.
You might also get the following error.
Install-NuGetClientBinaries -CallerPSCmdlet $PSCmdlet -Proxy $Proxy -ProxyCredential $ProxyCredential
Exception: Exception calling "ShouldContinue" with "2" argument(s): "A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files (x86)\PackageManagement\ProviderAssemblies' or 'C:\Windows\system32\config\systemprofile\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?"
Giving the lines here for the lazy ones.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -scope CurrentUser -Force
Install-module Az -scope CurrentUser -Force