Last active
May 25, 2018 13:54
-
-
Save piyushawasthi/cd32fc3cbcdfb5211e50772b0e7da2ff to your computer and use it in GitHub Desktop.
Revisions
-
piyushawasthi revised this gist
May 25, 2018 . 1 changed file with 1 addition and 15 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,22 +39,8 @@ $vm = Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName -Status $vm.Statuses Save-AzureRmVMImage -ResourceGroupName $ResourceGroupName -Name $VMName -DestinationContainerName $ResourceGroupName.ToLower() -VHDNamePrefix $VHDNamePrefix -Path C:\testImage.json ``` 3. Run script on PowershellISE as -
piyushawasthi revised this gist
May 25, 2018 . 1 changed file with 11 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,17 @@ Create VM Image in Azure 1: Create VM to create Image for same. ``` a: Open the Command Prompt window as an administrator. b: Change the directory to %windir%\system32\sysprep cd C:\Windows\system32\sysprep c: run sysprep.exe .\sysprep.exe ``` 2: create-vmimage.ps1 ``` Param( -
piyushawasthi created this gist
May 25, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ Create VM Image in Azure 1: Create VM to create Image for same. a: Open the Command Prompt window as an administrator. b: Change the directory to %windir%\system32\sysprep ``` cd C:\Windows\system32\sysprep ``` c: run sysprep.exe ``` .\sysprep.exe ``` 2: create-vmimage.ps1 ``` Param( [Parameter(Mandatory=$true)] $ResourceGroupName, [Parameter(Mandatory=$true)] $SubscriptionId, [Parameter(Mandatory=$true)] $storageAccName, [Parameter(Mandatory=$true)] $VMName, [Parameter(Mandatory=$true)] $VHDNamePrefix ) Login-AzureRmAccount Select-AzureRmSubscription -SubscriptionId $SubscriptionId Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName -Force Set-AzureRmVm -ResourceGroupName $ResourceGroupName -Name $VMName -Generalized $vm = Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName -Status $vm.Statuses Save-AzureRmVMImage -ResourceGroupName $ResourceGroupName -Name $VMName -DestinationContainerName $ResourceGroupName.ToLower() -VHDNamePrefix $VHDNamePrefix $SA = Get-AzureRMStorageAccount -Name $storageAccName -ResourceGroupName $ResourceGroupName $Image = ($SA | Get-AzureStorageBlob -Container "system").Name |?{$_ -like "*$VHDNamePrefix-osDisk*.vhd"} $ImageURI = "https://$storageAccName.blob.core.windows.net/system/$Image" $ImageURI $SA = Get-AzureRMStorageAccount -Name $storageAccName -ResourceGroupName $ResourceGroupName $Image = ($SA | Get-AzureStorageBlob -Container "system").Name |?{$_ -like "*$VHDNamePrefix-osDisk*.vhd"} $ImageURI = "https://$storageAccName.blob.core.windows.net/system/$Image" $ImageURI ``` 3. Run script on PowershellISE as ``` .\create-vmimage.ps1 -ResourceGroupName <ResourceGroupName> -SubscriptionId <SubscriptionId> -storageAccName <storageAccName> -VMName <VMName> -VHDNamePrefix <imagenameyouwant> ```