Stop-AzureVM: No deployment found in service - powershell

I want to stop and de-allocate a Windows VM in Azure.
In PowerShell, I use the command:
Stop-AzureVM - ServiceName [servicename] - Name [machinename] - Force
However, I get the following error message in PowerShell:
WARNING: "No deployment found in service [servicename]
What could be wrong?

Troubleshooting steps:
Is the VM already in Shutdown or Deallocated state.
Do you have more than one subscriptions. If yes then select correct subscription using below cmdlet and then try to stop the VM:
Select-AzureSubscription -SubscriptionName "<<Your SubscriptionName here>>"
or
Select-AzureSubscription -Id "<<Your Subscription ID>>"
If you have only one Azure Subscription then check if you created the VM using ASM i.e. old portal (https://manage.windowsazure.com) or ARM i.e. new portal (https://portal.azure.com). If you used new portal then you need to use ARM related PowerShell cmdlets like below:
Stop-AzureRmVM -ResourceGroupName "resource group name" -Name "VM name"
Reference for ARM PowerShell cmdlets: Azure Resource Manager and PowerShell

Related

Still requiring Login-RmAzureAccount even after importing PublishSettings in Azure

I am attempting to login to an Azure account through a PowerShell script by means of making use of a publishsettings file; However, I am still finding that it is requiring me to login to my account using Login-AzureRmAccount, regardless of having those credentials.
My step-by step looks something like this:
Clear out all accounts that may be available:
Get-AzureAccount | ForEach-Object { Remove-AzureAccount $_.ID -Force }
Download the PublishSettings file: Import-AzurePublishSettingsFile –PublishSettingsFile $PublishSettingsFileNameWithPath
Select the Azure subscription using the subscription ID:
Select-AzureRMSubscription -SubscriptionId $SubscriptionId
And finally, create a new resource group in the subscription before deploying it: New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force 2>> .\errorCIMS_RG.txt | Out-File .\rgDetailsCIMS_RG.txt
However, this is when an error is thrown: Run Login-AzureRmAccount to login.
Assuming I have the PublishSettings file, and it hasnt expired, why would this be giving back an error?
As Mihail said, we should check Azure PowerShell version first, and install the latest version.
We can run this command to list Azure PowerShell version:
Get-Module -ListAvailable -Name Azure -Refresh
By the way, Import-AzurePublishSettingsFile work for ASM, New-AzureRmResourceGroup is ARM command, so if you want to create resource group, you should Login-AzureRmAccount first.
Note:
The AzureResourceManager module does not support publish settings
files.
More information about Import-AzurePublishSettingsFile, please refer to this link.
I solved this problem by updating to last version of azure powershell cmdlet.
You can find last one here:
https://github.com/Azure/azure-powershell/releases

Set-AzureWebsite: No default subscription has been designated.

I am using VSTS Release Management. In my release flow I add a task 'Azure PowerShell(Run a PowerShell script within an Azure environment)' to run a simple script to set some key vaues in the web.config of a web app:
Set-AzureWebsite -Name $AzureWebsiteName -AppSettings $appsettings
When I run the deployment, I get the following error (related to the script):
[error]No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
The task is configured to use the connection type "Azure Resource Manager" and so far I understood that 'Set-AzureWebsite' should be used in classic mode?
Is there another way to set the AppSettings with the Azure Ressource Manager Mode=
The name Azure websites changes to Azure App Service Web Apps in the ARM, so you can use: Set-AzureRmWebApp
Replace below command:
Set-AzureWebsite $webAppName -AppSettings $appSettingsHash
With this command:
Set-AzureRmWebApp -AppSettings $appSettingsHash -Name $webAppName -ResourceGroupName $resourceGroupName

VSTS Azure powershell : No default subscription has been designated

I'm trying to run some azure powershell commands as part of my Visual Studio Team Services build using Azure Resource Manager.
It gives me the following error:
No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
The commands I'm trying to run:
$website = Get-AzureWebsite | where {$_.Name -eq 'my-website'}
Write-Output ("##vso[task.setvariable variable=DeployUrl;]$website.HostNames")
When I tried to run it locally, I had to call
Add-AzureAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"
to get it working, but it is not possible in the VSTS build.
UPDATE:
I've configured it to use the azure classic mode instead of resource manager, at it works. I don't think that it is a feasible solution for production as azure classic mode is obsolete.
Since you are using Azure Resource Manager, please check the things below:
Make sure "Azure Resource Manager" service endpoint is added correctly.
Use "Get-AzureRmWebApp" command instead of "Get-AzureWebsite" command just as bmoore mentioned.
I have tested it at my side, it works correctly.
My PowerShell script:
$website = Get-AzureRmWebApp | where {$_.Name -eq 'eddieapp0930'}
Write-Host $website.HostNames
Run from "Azure PowerShell Script" task:
Thank you for your question.
If you are using service manager mode(classic mode), the correct cmdlet is:
Add-AzureAccount
Get-AzureSubscription -SubscriptionName “name” | Select-AzureSubscription
If you are using Resource Manager, the correct cmdlet is:
Login-AzureRmAccount
Get-AzureRmSubscription –SubscriptionName "name" | Select-AzureRmSubscription
or just use -SubscriptionId instead of -SubscriptionName.
More information about ASM and ARM, please refer to the link below:
https://azure.microsoft.com/en-us/documentation/articles/resource-manager-deployment-model/
If you still have questions, welcome to post back here. Thanks.

Access Azure VM with PowerShell and MS Live credentials

I want to change the size an Azure VM with powershell. The reason is: I use machine for development. I need A2 size for 4 hours a day. The owner of the VM asked to switch the size of the machine to A0 when I do not develop. I have access to the Azure subscription with my MS Live account. Now I change the size manually through Azure Portal. I want to automate this task with PowerShell. The script should set the size to A2, wait for 4 hours and set it back to A0. I just want to doubleclick the script before starting my development and just forget about the question.
I have the following understanding of the general procedure:
Run Import-AzurePublishSettings
Run Select-AzureSubscription
Get VM object with Get-AzureVM
Run Set-AzureVMSize
Update-AzureVM
I can not get publish profile, because I do not own the machine. Is there a way to authenticate with MS Live account?
Skip the Import-Azurepublish and do a Add-AzureAccount instead. That will popup UI for authenticating with your MS Live account.
Once that is done you can use Select-AzureSubscription
For Classic Deployment you need this:
# authenticate if no account is already added to the powershell session
if (!(Get-AzureAccount)){ Add-AzureAccount }
# Get the vm object out of azure
$vm = get-azurevm | where name -eq "name of the vm"
# Now all you need is to is update the VM with its new size:
$vm | Set-AzureVMSize -InstanceSize Medium | Update-AzureVM
If the VM is deployed via the Resource Manager (RM Model)
if (!(Get-AzureRMContext)){ Add-AzureRmAccount }
Select-AzureRmSubscription -SubscriptionId "{subscriptionId}"
$vm = Get-AzureRmVm | where name -eq "{vmName}"
$vm.HardwareProfile.vmSize = "Medium"
Update-AzureRmVM -VM $vm
btw. Medium is what A2 is called in the API.

manage azure resource manager storage powershell

I'm facing following issue
Switch-AzureMode AzureResourceManager
New-AzureStorageAccount -ResourceGroupName "XYZ" -Name "VmTemplateStorage" -Type "Standard_LRS"
# lists the account
Get-AzureStorageAccount
Set-AzureSubscription -SubscriptionName "ABC" -CurrentStorageAccountName -"VmTemplateStorage"
# now this outputs error saying: Storage account 'VmTemplateStorage' was not found.
Get-AzureStorageContainer
I'm aware that I can create storage account in "classic" mode. But then I'm unable to use it as a source for vm images deployed using resource manager.
This way however, I'm unable to manage the account and upload blobs using powershell.
Any ideas how to manage resource manager based storage accounts?
you can use the following new PowerShell commands to manage ARM (Azure Resource Manager) based storage accounts.
Note: You need to update your Azure PowerShell later versions which support this new feature such as the November 2015 release. Also, the Switch-AzureMode command is deprecated in the latest release.
New-AzureRmStorageAccount
Get-AzureRmStorageAccount
Set-AzureRmStorageAccount
Remove-AzureRmStorageAccount