Azure Server Farm Not Found - powershell

I am trying to create an azure website via a powershell script. The hosting plan has already been create, I simply wish to add a new website to it.
The script I'm using is this:
Switch-AzureMode AzureResourceManager
$targetServicePlan = Get-AzureResource -Name my-serviceplan -OutputObjectFormat New
New-AzureResource -Name MyTestSite -Location "West Europe" `
-ResourceGroupName Default-Web-WestEurope `
-ResourceType 'Microsoft.Web/sites' `
-PropertyObject #{"name" = "MyTestSite"; "ServerFarmId" = $targetServicePlan.ResourceId } `
-OutputObjectFormat New
The server farm ($targetServicePlan) has a resource id, so I'm assuming that it exists (there is also a hosting plan in the azure portal with this name). Yet when I try to create the website I get the error: "Server farm with name my-serviceplan not found."
The full error is:
New-AzureResource : {"Code":"NotFound","Message":"Server farm with name my-serviceplan not found.","Target":null,"Details":[{"Message":"Server farm with name
my-serviceplan not found."},{"Code":"NotFound"},{"ErrorEntity":{"Code":"NotFound","Message":"Server farm with name my-serviceplan not
found.","ExtendedCode":"11001","MessageTemplate":"Server farm with name {0} not found.","Parameters":["my-serviceplan"],"InnerErrors":null}}],"Innererror":null}
At line:1 char:1
+ New-AzureResource -Name MyTestSite -Location "West Europe" -ResourceGrou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : NotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceCmdlet
What am I missing?

Is your $targetServicePlan in 'West Europe'? If not that could be the reason for that not-so-helpful error.

Related

Creation of an Azure Automation Connection via PowerShell - error 'account was not found'

I am running the following PowerShell code:
Get-AzureRmAutomationAccount `
-ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
-Name $AUTOMATION_ACCOUNT_NAME
New-AzureRmAutomationConnection
-ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
-AutomationAccountName $AUTOMATION_ACCOUNT_NAME `
-Name $ConnectionAssetName `
-ConnectionTypeName AzureServicePrincipal `
-ConnectionFieldValues $ConnectionFieldValues
The Get-AzureRmAutomationAccount displays details of the automation account, but New-AzureRmAutomationConnection (although using exactly the same parameter values) throws the following error:
New-AzureRmAutomationConnection : The Automation account was not found.
At line:2 char:1
+ New-AzureRmAutomationConnection -ResourceGroupName $AUTOMATION_ACCOUN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmAutomationConnection], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationConnection
Any suggestions what I may be missing are appreciated! :)
The error is misleading, the error you are most likely seeing is related to a bad field. Run the cmdlet with debug to see the value is it failing on. You will have to scroll up a bit to find the exception in the body.
Ensure you have your cert thumbprint, sub id, tenant, and app id. I just tested with the following and it worked as expected. (replaced my values of course). Hope this helps!
New-AzureRmAutomationConnection `
-ResourceGroupName TestAzureAuto `
-AutomationAccountName TestAzureAuto `
-Name "MyAsset2" `
-ConnectionTypeName AzureServicePrincipal `
-ConnectionFieldValues #{"CertificateThumbprint"="0000000000000000000000000000000000000000";"SubscriptionID"="00000000-0000-0000-0000-000000000000";"ApplicationId" = "00000000-0000-0000-0000-000000000000"; "TenantId" = "00000000-0000-0000-0000-000000000000" }

Cannot start Azure VM from PowerShell

I'm trying to start an Azure VM using the following PowerShell script:
$subscriptionId = "00000000-0000-0000-0000-000000000000"
$azureVM = "VS2017"
$resourceGroup = "VS2017ResourceGroup"
Add-AzureRmAccount # here start interactive login
Select-AzureSubscription -SubscriptionId $subscriptionId
Start-AzureRmVM - -ResourceGroupName $resourceGroup -Name $azureVM
When executing the script, I receive the following response:
Start-AzureRmVM : A positional parameter cannot be found that accepts argument '-'.
At C:\Users\ralbano\Desktop\Senza nome7.ps1:11 char:1
+ Start-AzureRmVM - -ResourceGroupName "VS2017ResourceGroup" -Name $azu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-AzureRmVM], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Azure.Commands.Compute.StartAzureVMCommand
I am using Windows PowerShell ISE to run the script.
Am I doing something wrong?
I checked the subscription id and the resource group name and are correct (of course in the sample above the subscription id is a fake). The VM is in "Stopped (deallocated)" state on Azure.
Start-AzureRmVM - -ResourceGroupName $resourceGroup -Name $azureVM
According to your error message, we should use this command like this:
Start-AzureRmVM -ResourceGroupName $resourceGroup -Name $azureVM

Retrieve Azure Service Bus Shared Access Connection String via Powershell

It's possible to retrieve the access key to an Azure storage account using Get-AzureRmStorageAccountKey from Powershell. How would I get hold of the access key to a shared access policy of an Azure Service Bus?
More clarification
This is what I get when I use the Get-AzureRmServiceBusNamespaceKey cmdlet:
PS C:\Windows\system32> Login-AzureRmAccount -Credential $cred
Environment : AzureCloud
Account : ***redacted***
TenantId : ***redacted***
SubscriptionId : ***redacted***
CurrentStorageAccount :
PS C:\Windows\system32> Set-AzureRmContext -SubscriptionId ***redacted***
Environment : AzureCloud
Account : ***redacted***
TenantId : ***redacted***
SubscriptionId : ***redacted***
CurrentStorageAccount :
PS C:\Windows\system32> Get-AzureRmServiceBusNamespaceKey -ResourceGroup testresourcegroup -Name test-bus -AuthorizationRuleName SendPolicy
Get-AzureRmServiceBusNamespaceKey : Run Login-AzureRmAccount to login.
At line:1 char:1
+ Get-AzureRmServiceBusNamespaceKey -ResourceGroup testresourcegroup -Name test-bus ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-AzureRmServiceBusNamespaceKey], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.ServiceBus.Commands.Namespace.GetAzure RmServiceBusNamespaceKey
PS C:\Windows\system32> Get-AzureRmStorageAccountKey -ResourceGroupName testresourcegroup -Name teststoragexxx
Key1 Key2
---- ----
***redacted*** ***redacted***
Not with Get-AzureRmStorageAccountKey, but you can use Get-AzureRmServiceBusNamespaceKey
$resourceGroup = "myResourceGroup"
$serviceBusName ="myservicebusname"
$policyName = "policyname"
Get-AzureRmServiceBusNamespaceKey -ResourceGroup $resourceGroup -Name
$serviceBusName -AuthorizationRuleName $policyName
This will return the whole object, so you can pass it into a variable and get the keys or connection strings from that.
Please have a try to login with tenantId and ServicePrincipal. I do a demo test about that, it works correctly for me.
Login-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal -SubscriptionId $subscriptionId
The following is may detail steps.
1 . We need to install service Bus module if it is not install. More detail info about AzureRM.ServiceBus please refer to document.
Install-Module -Name AzureRM.ServiceBus
2.More detail info about Automatically login script please refer to another SO thread.
3.Run the test script and check the result.
$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$subscriptionId="Your subcription"
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Login-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal -SubscriptionId $subscriptionId
$resourceGroup = "Resource Group name"
$serviceBusName ="Service Bus Name"
$policyName = "Policy Name"
Get-AzureRmServiceBusNamespaceKey -ResourceGroup $resourceGroup -Name $serviceBusName -AuthorizationRuleName $policyName

"Pipeline Stopped" error while setting up Azure VM DSC Extension via Powershell

PowerShell version: 5
I've uploaded a DSC ps1 file in a zip to Azure storage using the command:
publish-azurermvmdscconfiguration
With the appropriate parameters and arguments. Then I enter:
Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName <VmName> -ArchiveBlobName Run-DSCPython.zip -ArchiveStorageAccountName <storageAccountName> -Version 2.2 -Verbose
And I get the following (generally opaque) error message in PowerShell:
Set-AzureRmVmDSCExtension : The pipeline has been stopped.
At line:1 char:1
+ Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName Download ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmVMDscExtension], PipelineStoppedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Extension.DSC.SetAzureVMDscExtensionCommand
Set-AzureRmVmDSCExtension : Long running operation failed with status 'Failed'.
At line:1 char:1
+ Set-AzureRmVmDSCExtension -ResourceGroupName Pollers -VmName Download ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Set-AzureRmVMDscExtension], CloudException
    + FullyQualifiedErrorId : InvalidResult,Microsoft.Azure.Commands.Compute.Extension.DSC.SetAzureVMDscExtensionCommand
In the Azure Portal though, I dig up a more detailed log, it's very long so I'll post here only the part I believe is connected to the error itself:
[ERROR] An error occurred while executing script or module 'Run-DSCPython':
 The specified module 'Run-DSCPython' was not loaded because no valid module file
was found in any module directory.
Any idea what I need here? What module is it looking for?
While not exactly an answer to your question, I would propose you compile mofs in Azure Automation and register your VM's as nodes to Azure Automation, the process is a bit lengthy to write out here, I'll write a short guide:
# You can compile mof on your own PC and import, or compile in Azure Automation (preferred way)
<#
Import-AzureRmAutomationDscNodeConfiguration -Path "C:\localhost.mof" -ConfigurationName $configurationName `
-ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Force
#>
$AutomationAccountName = "Automation"
$ResourceGroupName = "Azure"
$Location = "West Europe"
$VnetName = "VNet"
$configurationName = "Configuration-1"
$credName = "Name of credential asset in Azure Automation"
$nodeName = "localhost"
$StorageAccountName = "something"
# Import Configuration
$sourcePath = "C:\DSC.ps1"
Import-AzureRmAutomationDscConfiguration -SourcePath $sourcePath `
-ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Published -Force
# Compile mof
$ConfigurationData = #{
AllNodes = #(
#{
NodeName = $nodeName
PSDscAllowPlainTextPassword = $true
RebootNodeIfNeeded = $true
DebugMode = "All"
}
)
}
$Parameters = #{
"storageAccountName" = $storageAccountName
"nodeName" = $nodeName
"credential" = $credName
}
Start-AzureRmAutomationDscCompilationJob -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName `
-ConfigurationName $configurationName -Parameters $Parameters -ConfigurationData $ConfigurationData
# Register VM and apply mof
$VmName = "VM-Name";
Register-AzureRmAutomationDscNode -AutomationAccountName $AutomationAccountName -AzureVMName $VmName `
-ResourceGroupName $ResourceGroupName -NodeConfigurationName "$configurationName.localhost"
Edit: forgot to tell you the reasoning, I've wasted 2-3 weeks trying to make DSC extension to work RELIABLY. I failed miserably, Azure Automation on the other hand was far more reliable, although really tricky at the beginning.

Get-AzureResource failing

I am automating the creation of an Azure web site and want to set the pricing tier. I found a few good articles (https://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/, http://www.troyhunt.com/2015/01/automating-web-hosting-creation-in.html) that pointed me to Get-AzureResource but I cannot get it to work.
I originally had AuthenticationFailed errors with the Azure 0.8 Powershell module then upgraded to 0.9.3. I now am getting two different errors depending on the parameters I supply to Get-AzureResource. I tried different ApiVersion switches, found that I'm running 2014-04-01-preview which concerns me a bit, and confirmed that my subscription supports AzureResourceManager via Get-AzureSubscriptions. What am I missing?
PS > Switch-AzureMode AzureResourceManager
WARNING: The Switch-AzureMode cmdlet is deprecated and will be removed in a future release.
$DebugPreference="Continue"
PS > Get-AzureResource -OutputObjectFormat New
DEBUG: 3:21:09 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on the
specified scope.'.
DEBUG: 3:21:09 PM - using account id '###'...
Get-AzureResource : One or more errors occurred.
At line:1 char:1
+ Get-AzureResource -OutputObjectFormat New
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureResource], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementatio
n.GetAzureResourceCmdlet
PS > Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -ResourceType Microsoft.Web/sites -ApiVersion 2015-05-01 -OutputObjectFormat New
DEBUG: 3:31:55 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on thespecified scope.'.
DEBUG: 3:31:55 PM - using account id '#####'...
Get-AzureResource : {
"Error": {
"Code": "AuthenticationFailed",
"Message": "Authentication failed. The 'Authorization' header is not present or provided in an invalid format.",
"Target": null,
"Details": null
}
}
At line:1 char:1
+ Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -Res ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : AuthenticationFailed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Get
AzureResourceCmdlet
The normal flow for managing Azure resources would be something like:
Switch-AzureMode -Name AzureResourceManager
Add-AzureAccount # windows pops up to enter Microsoft account credentials
Select-AzureSubscription -SubscriptionId '<sub-id>' # switch to the correct subscription
Get-AzureResource -Name <site-name> -ResourceGroupName <rg-name> -ResourceType Microsoft.Web/sites
It's possible that you missed one of these steps.