Giter Site home page Giter Site logo

azure-samples / managed-disks-powershell-getting-started Goto Github PK

View Code? Open in Web Editor NEW
28.0 33.0 35.0 65 KB

This repo contains sample Powershell scripts for various scenarios of using Azure Managed Disks

Home Page: https://azure.microsoft.com/en-us/services/managed-disks/

License: MIT License

PowerShell 100.00%

managed-disks-powershell-getting-started's Introduction

services platforms author
storage,virtual-machines
powershell
ramankum

Introduction

These samples demonstrate how to get started with Azure PowerShell to perform various operations on Azure Managed Disks for common scenarios. Each sample respresents a scenario that you want to implement using Azure PowerShell and Managed Disks.

Prerequisites

  1. Install the latest version of Azure PowerShell
  2. A Microsoft Azure subscription. If you don't have a Microsoft Azure subscription you can get a FREE trial account here

Samples

Running samples

  1. Start Windows PowerShell Integrated Scripting Environment (ISE) in Administrator Mode
  2. At this point, you can either:
    • Create a new script and copy and paste a script from this repo into the new file: Click File > New
    • Or download/clone this repo and open a script from this repo: Click File > Open
  3. Provide the appropriate values for each variable (e.g. "Subscription Name", "Storage Account Name", etc.). Note: The angled brackets should not be included in the values you provide.
  4. Run the script by pressing F5 or clicking the "Run Script" icon.

More information

managed-disks-powershell-getting-started's People

Contributors

microsoftopensource avatar msftgits avatar ramankumarlive avatar roygara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

managed-disks-powershell-getting-started's Issues

issue when creating vm from snapshot

PS C:\Windows\system32> $snapshot = Get-AzureRmSnapshot
PS C:\Windows\system32> $resourceGroupName ='prod'
PS C:\Windows\system32> $snapshotName = 'vm3copy'
PS C:\Windows\system32> $osDiskName = 'myvm3disk'
PS C:\Windows\system32> $virtualNetworkName = 'prod-vnet'
PS C:\Windows\system32> $virtualMachineName = 'myVM3'
PS C:\Windows\system32> $virtualMachineSize = 'Standard_DS3'
PS C:\Windows\system32> $snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
PS C:\Windows\system32> $diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy
PS C:\Windows\system32> $disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName
New-AzureRmDisk : The request content was invalid and could not be deserialized: Required property 'name' not found in 'sku'.
ErrorCode: InvalidRequestContent
ErrorMessage: The request content was invalid and could not be deserialized: Required property 'name' not found in 'sku'.
ErrorTarget:
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 78d284c4-7180-47c0-a808-907519b9827b
At line:1 char:9

  • $disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourc ...
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzureRmDisk], ComputeCloudException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmDisk

i'm also trying to launch a vm using existing managed os disk, my script is not working.

#Provide the name of your resource group
$resourceGroupName ='Demopractice'

#Provide the size of the virtual machine
$virtualMachineSize = 'Standard_DS3'

#Provide the name of the virtual machine
$virtualMachineName = 'demoserver1'

#Provide the name of an existing virtual network where virtual machine will be created
$virtualNetworkName = 'Demopractice-vnet'

#provide location where your os disk located
$loc='centralus'

#Provide the name of the Managed Disk...................
$managedDiskName='server1_OsDisk_1_256262bb5eec498bb8f574dfd9a4cd57'
#Get managed disk ID
$managedDiskId=Get-AzureRmDisk -ResourceGroupName Demopractice -DiskName 'server1_OsDisk_1_256262bb5eec498bb8f574dfd9a4cd57'
$AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName -Name "demo"
$nic=Get-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name "server1351"
$nsg = Get-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroupName -Name "server1-nsg"
$nic.NetworkSecurityGroup = $nsg
$nic | Set-AzureRmNetworkInterface

#Initialize virtual machine configuration
$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize -AvailabilitySetId $AvailabilitySet.Id
#Add a network interface to a new virtual machine
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $managedDiskId.Name -ManagedDiskId $managedDiskId.Id -CreateOption Attach -Windows -Caching ReadWrite -DiskSizeInGB $managedDiskId.DiskSizeGB
New-AzureRmVM -ResouceGroupName $resourceGroupName -Location $loc -VM $VirtualMachine.StorageProfile.OsDisk

On Which Account We should Login

On which account should we log in in order to copy the managed disk in other subscription, I got this error while running the script as it is:-

Select-AzureRmSubscription : Run Login-AzureRmAccount to login.
At line:32 char:1

  • Select-AzureRmSubscription -SubscriptionId $SubscriptionId
  •   + CategoryInfo          : CloseError: (:) [Set-AzureRmContext], PSInvalidOperationException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
    
    

New-AzureRmDisk : No account found in the context. Please login using Login-AzureRMAccount.
At line:36 char:1

  • New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupNa ...
  •   + CategoryInfo          : NotSpecified: (:) [New-AzureRmDisk], ArgumentException
      + FullyQualifiedErrorId : System.ArgumentException,Microsoft.Azure.Commands.Compute.Automation.NewAzureRmDisk
    

The last line of the script gives a "Resource Group could not be found" Error Message

The last line of the script gives a "Resource Group could not be found" Error Message

New-AzDisk : Resource group 'rgtools' could not be found.
ErrorCode: ResourceGroupNotFound
ErrorMessage: Resource group 'rgtools' could not be found.
ErrorTarget:
StatusCode: 404
ReasonPhrase: Not Found
OperationID : 6a1536f4-e85b-4b91-8da0-65bf5241f695
At line:30 char:1

  • New-AzDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGrou ...
  •   + CategoryInfo          : CloseError: (:) [New-AzDisk], ComputeCloudException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmDisk
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.