New-AzureRmResourceGroup command not working in powershell - powershell

I have logged into my Azure account and selected the appropriate subscription.
But it always gives the same error
PS C:\WINDOWS\system32> New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location "East US"
New-AzureRmResourceGroup : Run Login-AzureRmAccount to login.
At line:1 char:1
+ New-AzureRmResourceGroup -Name "AzureMediaServicesSample" -Location " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-AzureRmResourceGroup], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzur
eResourceGroupCmdlet

I have selected the subscription too using select-azuresubscription
select-azuresubscription is used for ASM mode.
For ARM mode, you need use Get-AzureRmSubscription -SubscriptionName "your sub" | Select-AzureRmSubscription to select your subscription.
More information please refer to this example.
Update:
You could use the following cmdlet to check Azure PowerShell version.
Get-Module -ListAvailable -Name Azure -Refresh
You could install the latest PowerShell from the link.

I had the same problem and I solved it by changing the environment setting from Bash to Powershell in the upper left corner of the Cloud Shell Window.

Related

Login-AzureRmAccount Error after running the command

Getting the below error even though I've Run the Login-AzureRmAccount command and I've also selected my subscription using the Select-AzureRmSubscription command. I'm not sure what could be causing this. any help would be greatly appreciated.
New-AzureRmServiceBusNamespace : Run Login-AzureRmAccount to login.
At line:1 char:2
+ New-AzureRmServiceBusNamespace -ResourceGroup AXFDEVRG -NamespaceNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-AzureRmServiceBusNamespace], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.ServiceBus.Commands.Namespace.NewAzureRmServiceBusNamespace
According to your error log, you could check as the following ways.
1.Try to create new Serviceus on Azure Portal. Please ensure your subscription has the permission to create SeviceBus.
2.Do you have multiple subscriptions? If yes, please ensure your subscription is correct.
Login-AzureRmAccount
#View all subscriptions for your account
Get-AzureRmSubscription
#Select a default subscription for your current session
Get-AzureRmSubscription –SubscriptionName "your subscription" | Select-AzureRmSubscription
3.If they don't work, please check your Azure PowerShell version.
Get-Module -ListAvailable -Name Azure -Refresh
For now, the latest version is 3.7.0. If your are old version, you could try to install the latest version from the link.

Submit U-SQL Script locally using Powershell

If I want to submit a U-SQL Script to ADLA account, I can do so, using the below powershell cmdlet.
`
Submit-AzureRmDataLakeAnalyticsJob -Account $adlaAccountName -ScriptPath $USQLFile -Name $folder -DegreeOfParallelism $degreeOfParallelism -Verbose`
But, I am not able to submit the script against local ADLA account. I am getting error:
Submit-AzureRmDataLakeAnalyticsJob : Run Login-AzureRmAccount to login.
At line:1 char:1
+ Submit-AzureRmDataLakeAnalyticsJob -Account "local" -ScriptPath GetIn ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Submit-AzureRmDataLakeAnalyticsJob], PSInvalidOperationExceptio
n
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.DataLakeAnalytics.SubmitAzureDataLakeAnalyti
csJob
How to submit U-SQL script against local ADLA account ?
In addition to ADL Tools, we have released standalone SDK as well.
https://www.nuget.org/packages/Microsoft.Azure.DataLake.USQL.SDK
And document here:
https://learn.microsoft.com/en-us/azure/data-lake-analytics/data-lake-analytics-data-lake-tools-local-run
Thanks a lot,
Yu Dong

New-AzureQuickVM not creating VM on exsisting Cloud Service?

I'm trying to run the following Azure Powershell cmdlet to provision a new Virtual Machine on a existing Cloud Service.
PS C:\> Get-AzureService | ft ServiceName
ServiceName
-----------
$AZURETEST-EUWEST0
$AZURETEST-JPWEST0
$AZURETEST-USEAST0
$AZURETEST-USWEST0
PS C:\> $image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201505.01-en.us-127GB.vhd"
PS C:\> New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -ImageName $image -Password Password1 -AdminUsername admin -WaitForBoot
New-AzureQuickVM : ResourceNotFound: The deployment name '$AZURETEST-USEAST0' does not exist.
At line:1 char:1
+ New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -Im ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
New-AzureQuickVM : Sequence contains no matching element
At line:1 char:1
+ New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -Im ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
PS C:\>
What doesn't make sense is I'm getting an error that says my Cloud Service - or Deployment Name doesn't exist when you can clearly see it returned when I listed all the available Cloud Services!
First of all, admin as administrator account name will not work. It's a reserved word, once you get past the service name, it will break on this one.
Second, there's nothing wrong with your powershell command and I tested exactly with the same parameters to make sure. I can bet it's the "$" you used for the cloud service name that is being misinterpreted by the cmdlet.
Since you can't rename cloud services, create a new one without the "$" and try again to see if it works.
Update: This is what happens when i try to create CS from the portal with the "$" as first character:
"This field can contain only letters, numbers, and hyphens. The first
and last character in the field must be a letter or number.
Trademarks, reserved words, and offensive words are not allowed."
Try to enter all parameters inline without using named parameters (e.g $image). that solved it for me.
Here is a working example:
$image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-20160229-en.us-127GB.vhd"
$location = 'West Europe'
New-AzureQuickVM -Windows -Location $location -ServiceName "RamiSOTest1-cs" -name "RamiSOTest1-VM" -ImageName $image -Password 'RamiPass-1' -AdminUsername 'rami' -WaitForBoot

how to rename azure subscription name through powershell

i am trying to rename my azure subscription name with powershell
Get-AzureSubscription "Visual Studio Professional with MSDN" | Set-AzureSubscription "MSDN"
but its not working for me .error is below -
Set-AzureSubscription : Cannot bind positional parameters because no names were given.
At line:1 char:64
+ Get-AzureSubscription "Visual Studio Professional with MSDN" | Set-AzureSubscrip ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AzureSubscription], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousPositionalParameterNoName,Microsoft.WindowsAzure.Commands.Profile.SetAzureSubscriptionCommand
You cannot rename it with PowerShell at the moment.
Here is a list of all supported Azure PowerShell commands related to manage a profile:
https://msdn.microsoft.com/library/dn790379.aspx
You can see that there is is no command to change a subscription name. The only command to change a subscription is the Set-AzureSubscription, but it uses the -SubscriptionName parameter as the identifier:
https://msdn.microsoft.com/library/dn790376.aspx
So basically, with Set-AzureSubscription you can change all other properties except the name.

Azure Powershell to stop VM's in a subscription

I am new to Powershell, and to be specific entirely new to Azure Powershell. I need to create a powershell script to switch off all the VM's found on a subscription. I guess this needs to be done with the help of management certificate. But not sure where to start. I just done some simple lines of code to list all VM's as shown below:
Add-AzureAccount -Environment "AzureCloud"
$subscription = "my-sub-scri-ption"
Select-AzureSubscription -Current "SubName"
Set-AzureSubscription -SubscriptionName "SubName"
Get-AzureVM -ServiceName "VM1"
The output recieved is "Get-AzureVM : Value cannot be null.
Parameter name: subscriptionId".
Can someone please help me in this regard?
**EDIT:**
The powershell script which I am using is given below:
Add-AzureAccount -Environment "AzureCloud"
Set-AzureSubscription -SubscriptionName "My Subs"
$serviceName = "Service01"
$vmName = "Service01"
Get-AzureVM | Stop-AzureVM -Force
Though while running it shows script execution is successful, I can see still that vm is powered on. Please note that the serviceName and vmName is same in my case. Anything wrong here in my code?
**Re-Edit**
Executed code:
Add-AzureAccount -Environment "AzureCloud"
Set-AzureSubscription -SubscriptionName "My Subs"
$serviceName = "Service01"
$vmName = "Service01"
Get-AzureVM
Error for the above code:
Get-AzureVM : Value cannot be null.
Parameter name: subscriptionId
At D:\TC_PS\Untitled1.ps1:5 char:1
+ Get-AzureVM
+ ~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureVM], ArgumentNullException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand
You can start from here: Getting Started with Windows Azure PowerShell
Then you can simply run Get-AzureVM that will return all the virtual machines for every cloud service.
To stop a VM: Stop-AzureVM -ServiceName xxx -Name vm-test-01
To stop all the VMs in the subscription simply run: Get-AzureVM | Stop-AzureVM -Force
The -Force switch is necessary to stop the last virtual machine of the cloud service, otherwise the system would throw an error when trying to stop the last VM in the service, to avoid drop all the resources of your published app.
If you don't specify the -StayProvisioned switch, the virtual machine will be deallocated. This is the default behavior of Stop-AzureVM.