Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
424 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
How To Create An Azure Virtual Machine From A Snapshot/5babad9c5d66d222420e0802.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a TechSnips internal identifier text file. It can be safely removed if you've downloaded this. |
63 changes: 63 additions & 0 deletions
63
...zure Virtual Machine From A Snapshot/CreateavirtualmachinefromasnapshotwithPowerShell.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#Provide the subscription Id | ||
$subscriptionId = 'subscription id' | ||
|
||
#Provide the name of your resource group | ||
$resourceGroupName ='resource group' | ||
|
||
#Provide the name of the snapshot that will be used to create OS disk | ||
$snapshotName = 'snapshot name' | ||
|
||
#Provide the name of the OS disk that will be created using the snapshot | ||
$osDiskName = 'NewOSDisk' | ||
|
||
#Provide the name of an existing virtual network where virtual machine will be created | ||
$virtualNetworkName = 'vnet' | ||
|
||
#Provide the name of the virtual machine | ||
$VMname = 'NewVMfromSnapshot' | ||
|
||
<#Provide the size of the virtual machine | ||
e.g. Standard_DS3 | ||
Get all the vm sizes in a region using below script: | ||
e.g. Get-AzureRmVMSize -Location ukwest #> | ||
$virtualMachineSize = 'Standard_B1s' | ||
|
||
#Connect to Azure | ||
Connect-AzureRmAccount | ||
|
||
#Set the context to the subscription Id where Managed Disk will be created | ||
Select-AzureRmSubscription -SubscriptionId $SubscriptionId | ||
|
||
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName | ||
|
||
#Use splatting to declare common parameters | ||
$Location = $snapshot.Location | ||
|
||
$params = @{ | ||
ResourceGroupName = "$resourceGroupName" | ||
Location = "$Location" | ||
} | ||
|
||
$diskConfig = New-AzureRmDiskConfig -Location $Location -SourceResourceId $snapshot.Id -CreateOption Copy | ||
|
||
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName | ||
|
||
#Initialize virtual machine configuration | ||
$VirtualMachine = New-AzureRmVMConfig -VMName $VMname -VMSize $virtualMachineSize | ||
|
||
#Use the Managed Disk Resource Id to attach it to the virtual machine. Please change the OS type to linux if OS disk has linux OS | ||
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows | ||
|
||
#Create a public IP for the VM | ||
$publicIp = New-AzureRmPublicIpAddress -Name ($VMname.ToLower()+'_ip') -AllocationMethod Dynamic @params | ||
|
||
#Get the virtual network where virtual machine will be hosted | ||
$vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName | ||
|
||
# Create NIC in the first subnet of the virtual network | ||
$nic = New-AzureRmNetworkInterface -Name ($VMname.ToLower()+'_nic') -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id @params | ||
|
||
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id | ||
|
||
#Create the virtual machine with Managed Disk | ||
New-AzureRmVM -VM $VirtualMachine @params |
1 change: 1 addition & 0 deletions
1
...t A List Of All Azure Virtual Machine Names Using PowerShell/5c40baba7d7c9b630af239c2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a TechSnips internal identifier text file. It can be safely removed if you've downloaded this. |
13 changes: 13 additions & 0 deletions
13
How To Get A List Of All Azure Virtual Machine Names Using PowerShell/Sample_script.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#Login to Azure | ||
|
||
Login-AzureRmAccount | ||
|
||
#Declare Variable | ||
$RPMSubscriptions = Get-AzureRmSubscription | ||
|
||
#Foreach Statement | ||
foreach ($RPMSubscription in $RPMSubscriptions) | ||
{ | ||
Set-AzureRmContext -Subscription $RPMSubscription | ||
Get-AzureRmVM | Out-File -Append -FilePath "c:\users\rmorales\documents\psscript\$RPMSubscription.txt" | ||
} |
1 change: 1 addition & 0 deletions
1
How to Sign a Script with Powershell/5c3fb3a82298114442f31af0.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a TechSnips internal identifier text file. It can be safely removed if you've downloaded this. |
Oops, something went wrong.