PowerShell script and libeay32.dll with Azure Function App - powershell

I'm trying to use a PowerShell script that works on my machine in an Azure Function App.
In short, the script uses a Service Principal profile json to login to Azure and then does some magic to renew my Let's Encrypt SSL certificate.
The script itself is in a file called Register-LetsEncryptCertificateSP.ps1 and I can run it successfully in local PowerShell ISE by calling it like this:
PS C:\tmp\test> .\Register-LetsEncryptCertificateSP.ps1 -Domain dev.mysite.com -RegistrationEmail my#email.com -ResourceGroup my-resourcegroup-name -WebApp my-webapp-name -ServicePrincipalProfilePath "c:\tmp\letsencryptSP.json".
I added Service Principal support to Lee Holmes's script which prompts for Azure account credentials by default: https://www.powershellgallery.com/packages/Register-LetsEncryptCertificate/1.0/DisplayScript
I'm trying to put this script inside a TimerTriggerPowerShell Function App. The script requires following modules: #requires -Modules AcmeSharp, Azure, AzureRM.Websites
Azure and AzureRM.Websites are available by default and I have uploaded ACMESharp to modules/ -directory` but when I run the script in Azure I get the following log:
2017-04-03T09:46:23.499 Function started (Id=015f9081-8bc2-4801-b392-76e53da027f7)
2017-04-03T09:46:23.983 Loaded modules:
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.psd1
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp-AWS/ACMESharp-AWS.psd1
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp-IIS/ACMESharp-IIS.psd1
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.PKI.Providers.OpenSslLib32.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.PKI.Providers.OpenSslLib64.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.POSH-test.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.POSH.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.Providers.AWS.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.Providers.IIS.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp.Vault.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/AWSSDK.Core.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/AWSSDK.Route53.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/AWSSDK.S3.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ManagedOpenSsl.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/Microsoft.Web.Administration.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/Newtonsoft.Json.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/x86/libeay32.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/x86/ssleay32.dll
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp-AWS/ACMESharp-AWS.psm1
/TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp-IIS/ACMESharp-IIS.psm1
2017-04-03T09:46:24.186 Import-Module : The specified module 'AWSPowerShell' was not loaded because no valid module file was found in any module directory.
at <ScriptBlock>, /TimerTriggerPowerShell1/modules/ACMESharp/0.8.1/ACMESharp-AWS/ACMESharp-AWS.psm1: line 17
+ Import-Module
+ _____________
+ CategoryInfo : ResourceUnavailable: (AWSPowerShell:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
2017-04-03T09:46:24.280 Function completed (Failure, Id=015f9081-8bc2-4801-b392-76e53da027f7)
2017-04-03T09:46:24.343 Exception while executing function: Functions.TimerTriggerPowerShell1. System.Management.Automation: Could not load file or assembly 'file:///D:\home\site\wwwroot\TimerTriggerPowerShell1\modules\ACMESharp\0.8.1\x86\libeay32.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
The app service is running on 32bit. Any ideas how to solve this error?

Related

Error while deploying locally - Azure IOT remote monitoring suite

Team,
We are trying out this IOT remote monitoring suite from github. We are trying to first deploy that locally instead of Azure and hence we have followed the document mentioned here https://github.com/Azure/azure-iot-remote-monitoring/blob/master/Docs/local-deployment.md
Also, we have followed the pre-requisites over here https://github.com/Azure/azure-iot-remote-monitoring/blob/master/Docs/dev-setup.md
We then come over to my developer command prompt (running as admin) but we end up having error:
Get-AzureEnvironment : The 'Get-AzureEnvironment' command was found in
the module 'Azure', but the module could not be loaded. For more
information, r 'Import-Module Azure'. At
C:\Users\swagh\Downloads\azure-iot-remote-monitoring-master\azure-iot-re
-monitoring-master\Common\Deployment\PrepareIoTSample.ps1:14 char:14
+ if ((Get-AzureEnvironment AzureCloud) -eq $null)
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzureEnvironment:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
Get-AzureRMEnvironment : The 'Get-AzureRMEnvironment' command was
found in module 'AzureRM', but the module could not be loaded. For
more information, run 'Import-Module AzureRM'.
The modules has been imported successfully but not sure why it fails while building the soln locally. Tried setting the execution policy to bypass, unrestricted. Also scoped to the current user but its not helping.
We have run out of ideas. Can anyone help please?
According to your error message, it seems you have not install Azure PowerShell correctly.
We can install download Azure PowerShell here. After download azure-powershell.4.2.0.msi completed, run as administrator.
We can find latest version of Azure powershell here.
We can run this command in Azure PowerShell version 4.2.0:
Azure error
The screenshot for the above error.

TFS build fails when running custom powershell script

I've added a Powershell script step to my on-premises TFS 2015 build definition. The script modifies assembly version in AssemblyInfo.cs file.
I tested the script with the Build Agent account in PowerShell ISE and it worked fine. However, the PowerShell step fails in TFS build with an access denied error.
The Build Agent account has full control permission to C:\agent\_work\11\s\source\MyProject\Properties folder.
Get-Content : Access to the path 'C:\agent_work\11\s\source\MyProject\Properties' is denied.
At C:\agent_work\11\s\source\MyProject\BuildScript\Update-AssembyInfoFile.ps1:64 char:10
+ (Get-Content $file) |
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\agent_work...MyProject\Properties:String) [Get-Content], Unauthorized
AccessException
+ FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
The script error was caused by missing the file name in the file path. The message Access to the path 'C:\agent_work\11\s\source\MyProject\Properties' is denied is kind of confusing but it gives you idea that the file name is missing in the path. The path in the error message is a folder name rather than a filename. Hence, the error occurred.

How to get rid of error while creating ACS Namespace on Azure Service Bus with PS?

Short story: I get the following error when trying to create a namespace on Azure Service Bus using Azure Powershell (Run as Administrator):
PS C:> New-AzureSBNamespace -Name mynewnamespace2 -Location "East US"
-CreateACSNamespace $true -Namespac New-AzureSBNamespace : Object reference not set to an instance of an object. At line:1 char:1
+ New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSBNamespace], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBNamespaceCommand
Long story: I created a first namespace in Azure Service Bus to use Relay in buffered mode (namespace=mynewnamespace). It works great except when you want to transfer a larger set of data. For this there is the streamed mode and I found this handy example (https://code.msdn.microsoft.com/How-to-send-a-large-c36ab70e), changed appropriate settings for namespace and credentials and ran the server part from the project and I get the error
{"The remote name could not be resolved:
'mynewnamespace-sb.accesscontrol.windows.net'"}
because, of course, this ACS namespace does not exist. So I found out that I need to create the namespace the old fashioned way using PS, installed Azure CLI and run the commands below with the following result:
For a list of all Azure cmdlets type 'get-help azure'.
For a list of Windows Azure Pack cmdlets type 'Get-Command wapack'.
PS C:> azure login
info: Executing command login
|info: To sign in, use a web
browser to open the page https://aka.ms/devicelogin. Enter the code EE226448L to
authenticate. If you're signing in as an Azure AD application, use the
--username and --password parameters.
/info: Added subscription Visual Studio Enterprise with MSDN info: Setting subscription
"Visual Studio Enterprise with MSDN" as default
info: login command OK
PS C:> New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $true -NamespaceType Messaging
WARNING: Microsoft Azure PowerShell collects data about how users use
PowerShell cmdlets and some pro encounter. Microsoft uses this
information to improve our PowerShell cmdlets. Participation is volu
choose to participate your device automatically sends information to
Microsoft about how you use Azure Powershell.
If you choose to participate, you can stop at any time by using Azure
PowerShell as follows:
1. Use the Disable-AzureDataCollection cmdlet to turn the feature Off. The cmdlet can be found in the AzureResourceManager module To disable
data collection: PS > Disable-AzureDataCollection
If you choose to not participate, you can enable at any time by using
Azure PowerShell as follows:
1. Use the Enable-AzureDataCollection cmdlet to turn the feature On. The cmdlet can be found in the AzureResourceManager module To enable
data collection: PS > Enable-AzureDataCollection
Select Y to enable data collection [Y/N]: WARNING: You choose not to
participate in Microsoft Azure PowerShell data collection. WARNING:
The setting profile has been saved to the following path
'C:\Users\PDube\AppData\Roaming\Windows Azure Powershell\AzureDataCollectionProfile.json'.
New-AzureSBNamespace :
Object reference not set to an instance of an object. At line:1 char:1
+ New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSBNamespace], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBNamespaceCommand
I tried to create the new namespace using Azure CLI on 2 different computers, thinking the first install was corrupted, but I get the exact same error.
How can I fix this error?

Azure App Service Scaling powershell

I have app service in my environment named "Standard" . Currently the app service is configured in standard tier small 1 instance.
Using powershell I am trying to scale the app service which will in turn scale the web apps inside this app service.
I want to change size to Medium and instances to 2.
Here is my snippet.
Login-AzureRmAccount
Set-AzureRMAppServicePlan -Name Standard -ResourceGroupName
MyWebAppRG - NumberofWorkers 2 -WorkerSize Medium
When I run this command I am getting following error
Set-AzureRMAppServicePlan : Could not load file or assembly 'Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=0.11.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
At line:11 char:1
+ Set-AzureRMAppServicePlan -Name Standard -ResourceGroupName MyWebAppRG -Numbero ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-AzureRMAppServicePlan], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans.SetAzureAppSe
rvicePlanCmdlet
I am not sure, what's wrong here? and what exactly this error means.
For the information, I am able to run other powershell commands just fine,example set-AzureRMResource and others. so isn't an environment issue.
Any help appreciated..
Thanks
What version of the Azure Powershell are you using? This was a known issue in Azure Powershell 1.0.0. If you are using that version, use the version below instead. Do post back if you still see issues.
https://github.com/Azure/azure-powershell/releases/tag/v1.0.1-November2015

Security Token Validation Error with JWT token -- HDInsight

I created a new storage account and provisioned an HDInsight cluster on Windows Azure. However, when I try to run any command on Windows Azure Powershell related to the cluster, I get the following error:
PS C:\> Get-AzureHDInsightCluster -Name $clusterName
Get-AzureHDInsightCluster : Request failed with code:Unauthorized
Content:<Error xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>AuthenticationFailed</Code><Message>A security token
validation error occured for the received JWT token.</Message></Error>
At line:1 char:1
+ Get-AzureHDInsightCluster -Name $clusterName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureHDInsightCluster], HttpLayerException
+ FullyQualifiedErrorId : Microsoft.Hadoop.Client.HttpLayerException,Microsoft.WindowsAzure.Management.HDInsight.C
mdlet.PSCmdlets.GetAzureHDInsightClusterCmdlet
I'm completely new to HDInsight, but I ran a script before this command to add the Azure account, create variables for the subscription name, storage account name, and container name from this page.
Do you know what this error means? And how to fix it? I'm trying to run a script with Pig commands after following this website.
It looks like the PowerShell environment is not properly setup. You should add your Azure subscription first with GetAzureSubscription. See: http://www.windowsazure.com/en-us/documentation/articles/install-configure-powershell/#Connect