It doesn't give the correct Provisioned throughput value which is of 500 but shows as "0"
PS C:\windows\system32> Get-AzCosmosDBSqlContainerThroughput -ResourceGroupName $resourceGroupName -AccountName $accountName -DatabaseName $databaseName -Name $containerName | select throughput
Throughput
----------
0
Full output:
PS C:\windows\system32> $container = Get-AzCosmosDBSqlContainerthroughput `
-ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $containerName
PS C:\windows\system32> $container
Name : ECvc
Id : /subscriptions/dxxxxx/resourceGroups/RG-01/providers/Microsoft.DocumentDB/databaseAccounts/xxxxx
01/sqlDatabases/xxxx/containers/cosmosscaleupordowntest/throughputSettings/default
Throughput : 0
MinimumThroughput :
OfferReplacePending :
Reference:
https://learn.microsoft.com/en-us/powershell/module/az.cosmosdb/get-azcosmosdbsqlcontainerthroughput?view=azps-3.7.0
Your script is correct and I am unable to repro this cmdlet returning zero. This is also not a scenario with shared database throughput as this cmdlet is designed to throw an exception if throughput is not set on a resource. My only suggestion is to try the latest version of this module, Az.CosmosDB 0.1.3. We just updated it 5 days ago. It may have a bug fix.
If this issue persists for you, please file an issue on the PowerShell Issues List. This will get routed to the engineers working on these cmdlets.
Thanks.
I didn't use (az) Powershell script but I'm able to read and update Cosmos DB RU using powershell.
$databasePrimaryKey = "************"
$cosmosDbAccountName = "************"
$databaseName = "************"
$primaryKey = ConvertTo-SecureString -String $databasePrimaryKey -AsPlainText –Force
Get the list of all container and configure RU (Collection name will not display)
Get-CosmosDbOffer -Context $cosmosDbContext
Update desire RU
Get-CosmosDbOffer -Context $cosmosDbContext -Id $collectionId |
Set-CosmosDbOffer -Context $cosmosDbContext -OfferThroughput 400 -
OfferIsRUPerMinuteThroughputEnabled $true
Hope it will help
Related
I created a custom, generalized (using Sysprep), Windows 11 image from an Azure hosted VM and stored it in a custom Azure Compute image gallery.
c:\Windows\system32\sysprep\sysprep.exe /quiet /generalize /oobe /quit
It works when I use the custom gallery image to create Azure hosted VMs with 4 cores and 16GB RAM (Standard_D4s_v5).
It DOES NOT work when I try to use it in Hyper-V on my local system with the same cores and RAM.
I download the custom image from the gallery using the method described here.
$version = Get-AzGalleryImageVersion -ResourceGroupName $ResourceGroupName `
-GalleryName $GalleryName -GalleryDefinitionName $GalleryDefinitionName `
-Name $GalleryImageVersionName -ErrorAction Stop;
$diskConfig = New-AzDiskConfig -Location $Location -CreateOption FromImage `
-GalleryImageReference #{ Id = $version.Id };
$diskName = Split-Path -Path $version.StorageProfile.Source.Id -Leaf;
$disk = New-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $diskName `
-Disk $diskConfig -ErrorAction Stop;
$diskAccess = Grant-AzDiskAccess -ResourceGroupName $disk.ResourceGroupName `
-DiskName $disk.Name -Access Read `
-DurationInSecond (New-TimeSpan -Minutes 60).TotalSeconds -ErrorAction Stop;
$vhdPath = "c:\downloads\$diskName.vhd";
Get-AzStorageBlobContent -Uri $diskAccess.AccessSAS -Destination $vhdPath `
-ErrorAction Stop;
Once that downloads I set up a VM locally with the code below.
$vm = New-VM -Name "TestVM" -VHDPath $vhdPath -MemoryStartupBytes 16GB `
-ErrorAction Stop;
$vm = $vM | Set-VM -ProcessorCount 4 -AutomaticCheckpointsEnabled $false `
-CheckpointType Standard -PassThru -ErrorAction Stop;
$vm | Start-VM -ErrorAction Stop;
It says it starts but when I connect to it using the Hyper-V Virtual Machine Connection window all it shows is a blank screen with a flashing cursor.
Evidence leads me to believe that this is not a graphics card issue (which other stack overflow articles address):
If I let it run for a few minutes and try to do a shutdown the operation fails with a "The device is not ready for use" error.
I've tried this on two different hosts and see the same thing.
Both of the hosts I've tried it on I can successfully run an image I created using Disk2VHD.
Note: I have also used the /mode:vm argument in the SysPrep command but it had no effect on the outcome.
Any ideas on how to get this to work?
The key to resolving this was understanding two things:
HyperVGeneration : V2
Windows 11 Hyper-V hosting requirements: VHDX
The following produces a running Win-11 VM:
$vhdxPath = "c:\downloads\$diskName.vhdx";
Convert-VHD -Path $vhdPath -DestinationPath $vhdxPath -VHDType Dynamic -ErrorAction Stop;
$vm = New-VM -Name "TestVM" -VHDPath $vhdxPath -MemoryStartupBytes 16GB -Generation 2 -ErrorAction Stop;
$vm = $vm | Set-VM -AutomaticCheckpointsEnabled $false -CheckpointType Standard -PassThru;
$vm | Set-VMProcessor -Count 4 -ExposeVirtualizationExtensions $true -PassThru;
$vm | Start-VM;
How do I add Azure Scale Set to Log analytics. From log analytics I am able to see the VM but unlike VMs the connect button is not enabled. What do I need to do. to enable this connection.
There is a MSDN post regarding this issue:
https://blogs.msdn.microsoft.com/timomta/2018/04/09/how-to-add-the-oms-client-to-a-vm-scale-set/
As mentioned in the post, we explain how to do this for VMs but not for VMSS. You can accomplish this via PowerShell and the linked blog above describes how to achieve it.
I will add the script below for users who don't want to follow the link
select-azurermsubscription -subscriptionid ‘your subscription id’
$PublicSettings = #{"workspaceId" = "your oms workspace id"}
$ProtectedSettings = #{"workspaceKey" = "your big base64 oms key"}
# Get information about the scale set
$vmss = Get-AzureRmVmss -ResourceGroupName 'VMSSRESOURCEGROUP' `
-VMScaleSetName 'VMSSNAME'
Add-AzureRmVmssExtension `
-VirtualMachineScaleSet $vmss `
-Name "Microsoft.EnterpriseCloud.Monitoring" `
-Publisher "Microsoft.EnterpriseCloud.Monitoring" `
-Type "MicrosoftMonitoringAgent" `
-TypeHandlerVersion 1.0 `
-AutoUpgradeMinorVersion $true `
-Setting $PublicSettings `
-ProtectedSetting $ProtectedSettings
# Update the scale set and apply the Custom Script Extension to the VM instances
Update-AzureRmVmss `
-ResourceGroupName $vmss.ResourceGroupName `
-Name $vmss.Name `
-VirtualMachineScaleSet $vmss
# Only needed for manual update VMSS – warning tells them all to update, so modify to suit
$jobs=#()
Get-AzureRmVmssVM -ResourceGroupName $vmss.ResourceGroupName -VMScaleSetName $vmss.Name | foreach {
$jobs+=Update-AzureRmVmssInstance -ResourceGroupName $vmss.ResourceGroupName -Name $vmss.Name -InstanceId $_.InstanceId -AsJob
}
$jobs | Wait-Job
$jobs | Receive-Job
Kudos to the author https://social.msdn.microsoft.com/profile/Tim+Omta
I'm new to Azure. I'm trying to create resources in Azure using powershell.
My requirement is to create an image from a VM. I have followed to ways to do it :
Process 1: Do it manually
Generalize the VM : Login to VM -> Open command prompt -> cd %windir%\system32\sysprep --> run sysprep.exe --> Check generalize button--> Shutdown.
Create snapshot : Go to Azure portal-> Go to the VM which is generalized --> Click on Capture button --> Give image name and mention resource group and click on Create.
This will create an Image.
Process 2: Do it with powershell
# create session of the VM
$UserName = "$IPAddress\$adminUsername"
$Password = ConvertTo-SecureString $adminPassword -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
$s = New-PSSession -ComputerName $IPAddress -Credential $psCred
# Run SysPrep for generalizing the VM
$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$arg = '/generalize /oobe /shutdown /quiet'
Invoke-Command -Session $s -ScriptBlock {param($sysprep,$arg)Start-Process -FilePath $sysprep -ArgumentList $arg} -ArgumentList $sysprep,$arg
#Stop the VM
Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $virtualMachineName -Force
# Generalize the VM
Set-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $virtualMachineName -Generalized
# Create the Image
$vm = Get-AzureRmVM -Name $virtualMachineName -ResourceGroupName $ResourceGroupName
$image = New-AzureRmImageConfig -Location $location -SourceVirtualMachineId $vm.ID
New-AzureRmImage -Image $image -ImageName $ImageName -ResourceGroupName $ResourceGroupName
Both the processes will create a Image. But the problem I'm facing here is when I spin VM from the image created from Process 1 , it is created successfully without any issue.
But when I spin VM from image created from Process2 , it is getting created but with below error message :
Provisioning failed. OS Provisioning for VM 'VM Name' did not finish
in the allotted time. However, the VM guest agent was detected
running. This suggests the guest OS has not been properly prepared to
be used as a VM image (with CreateOption=FromImage).
Can anyone tell me what it is I'm doing wrong with powershell script, that I'm getting this error.
Time seems to be the issue.
Sysprep normally takes 10 - 15 minutes, you have no sleep time. You are shutting down VM as soon as the sysprep script is sent, no time to actually sysprep system.
You can either put a sleep time or a loop to check when VM is in a Stopped state.
There are quite a few docs on papering and creating VMs from images in Azure. As the error suggests, you likely missed a step.
If you are uploading a VHD from on prem to use in Azure, start with these docs
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/prepare-for-upload-vhd-image
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/upload-generalized-managed
If the VM you are capturing an image of is already in Azure and working, then start with these
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-generalized-managed?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json
The last link shows you how to create the VM from that image via the portal or a simple PS command
New-AzVm `
-ResourceGroupName "myResourceGroup" `
-Name "myVMfromImage" `
-ImageName "myImage" `
-Location "East US" `
-VirtualNetworkName "myImageVnet" `
-SubnetName "myImageSubnet" `
-SecurityGroupName "myImageNSG" `
-PublicIpAddressName "myImagePIP" `
-OpenPorts 3389
I have an Azure Image, which when I use Azure Powershell to create a VM from, despite me setting the ComputerName in the script, the VM is created without setting the ComputerName to the provided value.
Script:
$ImageName = 'MyImage'
$RsgName = 'MyRsg'
$VmName = 'MyNewVM'
$DiagnosticStorageName = 'diagnosticsstore5048'
$cred = Get-Credential -Credential 'TheAdmin'
$Image = Get-AzureRmImage -ImageName $ImageName -ResourceGroupName $RsgName
# Get NIC
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $RsgName
# Configure the new VM
$Vm = New-AzureRmVMConfig -VMName $VmName -VMSize 'Standard_A2_v2'
$Vm = Set-AzureRmVMSourceImage -VM $Vm -Id $Image.Id
$Vm = Set-AzureRmVMOSDisk -VM $Vm -Name $VmName'-disk' -StorageAccountType 'StandardLRS' -DiskSizeInGB '128' -CreateOption FromImage -Caching ReadWrite
$Vm = Add-AzureRmVMNetworkInterface -VM $Vm -Id $nic.Id
$Vm = Set-AzureRmVMBootDiagnostics -VM $Vm -Enable -ResourceGroupName $RsgName -StorageAccountName $DiagnosticStorageName
$Vm = Set-AzureRmVMOperatingSystem -VM $Vm -Windows -ComputerName 'dor' -Credential $Cred -ProvisionVMAgent
New-AzureRmVM -VM $Vm -ResourceGroupName $RsgName -Location 'West Europe' -DisableBginfoExtension
Last time I run the script to create the VM, it left the new VM with a computer name of 'WIN-I80O6J22ENS'
The Image was created as per the process here: https://learn.microsoft.com/en-gb/azure/virtual-machines/windows/capture-image-resource?toc=%2Fazure%2Fvirtual-machines%2Fwindows%2Fclassic%2Ftoc.json
UPDATE
Alot of people think that I am not Generalizing the image correctly, so I wanted to add here how I am doing it.
Inside the VM I run:
Start-Process -FilePath $env:windir\System32\Sysprep\Sysprep.exe -ArgumentList "/generalize /oobe /shutdown /unattend:$env:windir\System32\Sysprep\unattend.xml"
Unattend.xml only has one setting in it which is to step the TimeZone.
Once this is completed and the VM OS has shut down, I run the following to get the VM, stop it, and set it to Generalized:
# Shutdown Source VM & Generalize
$SourceVM = Get-AzureRmVM -ResourceGroupName $SourceRsg -Name $SourceVMName
$Null = Stop-AzureRMVM -ResourceGroupName $SourceRsg -Name $SourceVMName -Force
Write-Host 'Stopped Source VM'
Set-AzureRmVm -ResourceGroupName $SourceRsg -Name $SourceVMName -Generalized
Write-Host 'Set Source VM to Generalized'
I have noticed that when the last command is ran, the output is:
OperationId :
Status :
StartTime :
EndTime :
Error :
It doesn't actually say if it was successful or not?
After this I create the Image from the VM disk.
It might be caused by the image not being "Generalized".
Take a look at the Create a managed image of a generalized VM in Azure guide.
Hope it helps!
If you have a specialized image, the Computer name will be missing because the old computer name and the new computer name share the same RID and SID number and on a ideal situation each virtual machine deployment has different RID and SID number. The Computer name can be displayed if the image is a generalized.
Check this article for more information:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource
The point everyone is trying to make, from your description of the issue, it seems the Image was not generalized correctly or aspect of the generalization failed.
The script work fine on my end, so the only issue is with the image. Screenshot
Try another deployment from that image an see is you get the same computer name (WIN-I80O6J22ENS).
If you get the same name that is a sure confirmation of issue with generalization.
If the name changes it might mean that the machine you imaged has a policy that is not accepting the name 'dor' so the system is generating default name.
Either way issue is not with the Powershell or Azure. Hope this helps.
How to check stopped virtual Machines with different resources by azure powershell script
iam tried to do that script please help me
To get status of the vm’s you can try the below script:
#login
Connect-AzureRmAccount
Select-AzureRmSubscription –SubscriptionName 'subscription-name'
Get-AzureRmVM -Status | Format-Table
If you want ResourceGroup group wise you try this script:
Connect-AzureRmAccount
Select-AzureRmSubscription –SubscriptionName 'subscription-name'
$RG = "ResourceGroupName"
$VM = "vmname"
$VMStats = (Get-AzureRmVM -Name $VM -ResourceGroupName $RG -Status).Statuses
($VMStats | Where Code -Like 'PowerState/*')[0].DisplayStatus