Created
October 30, 2014 18:25
-
-
Save pcgeek86/8607e43677aaceade8c3 to your computer and use it in GitHub Desktop.
PPE October 2014 - Create Microsoft Azure Virtual Machine
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
Add-AzureAccount; | |
$Username = '[email protected]'; | |
$AzureCredential = Get-Credential -UserName $Username -Message 'Please enter your password'; | |
Add-AzureAccount -Credential $AzureCredential; | |
$ModuleName = 'Azure'; | |
Import-Module -Name $ModuleName; | |
Get-Command -Module $ModuleName; | |
Get-Command -Module $ModuleName -Name *sql*; | |
Get-Command -Module $ModuleName -Name *stor*; | |
Get-Command -Module $ModuleName -Name *automa*; | |
Get-Command -Module $ModuleName -Name *vm* | Sort-Object -Property Name; | |
# Select the appropriate Azure subscription | |
$SubscriptionName = 'Visual Studio Ultimate with MSDN'; | |
Select-AzureSubscription -SubscriptionName $SubscriptionName; | |
# Verify the currently selected Microsoft Azure subscription | |
Get-AzureSubscription -Current; | |
#region Create Azure Storage Account | |
$StorageAccount = @{ | |
StorageAccountName = 'fllppe2014'; | |
Location = 'East US'; | |
}; | |
if (!(Get-AzureStorageAccount -StorageAccountName $StorageAccount.StorageAccountName -ErrorAction SilentlyContinue)) { | |
New-AzureStorageAccount @StorageAccount; | |
} | |
Set-AzureStorageAccount -StorageAccountName $StorageAccount.StorageAccountName -Type Standard_LRS; | |
Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $StorageAccount.StorageAccountName; | |
#endregion | |
# Get a list of Azure VM images in the gallery | |
$ImageList = Get-AzureVMImage; | |
# Get a list of Azure VM (role) sizes | |
$RoleSizeList = Get-AzureRoleSize; | |
# Get a list of Azure datacenter regions (locations) | |
$LocationList = Get-AzureLocation; | |
#region Create Azure cloud service | |
$Service = @{ | |
ServiceName = 'fllppe2014-10'; | |
Location = 'East US'; | |
Description = 'This cloud service is used to host Azure virtual machines for the Florida PPE.'; | |
}; | |
New-AzureService @Service; | |
#endregion | |
#region Create Azure virtual machine | |
$VMConfig = @{ | |
InstanceSize = 'Standard_D2'; | |
Name = 'PPE-01'; | |
ImageName = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-Technical-Preview-201410.01-en.us-127GB.vhd'; | |
}; | |
$NewVMConfig = New-AzureVMConfig @VMConfig; | |
$ProvisioningConfig = @{ | |
AdminUsername = 'Trevor'; | |
Password = 'P@ssw0rd!!'; | |
Windows = $true; | |
VM = $NewVMConfig; | |
}; | |
Add-AzureProvisioningConfig @ProvisioningConfig; | |
# Set the VM subnet inside the Azure virtual network | |
Set-AzureSubnet -VM $NewVMConfig -SubnetNames Hosts; | |
$NewVM = @{ | |
ServiceName = $Service.ServiceName; | |
VNetName = 'pcgeek101'; | |
VMs = $NewVMConfig; | |
} | |
New-AzureVM @NewVM; | |
#endregion | |
Get-AzureRemoteDesktopFile -ServiceName $Service.ServiceName -Name $VMConfig.Name -Launch; | |
$PSOption = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck; | |
$VMCredential = New-Object -TypeName PScredential -ArgumentList $ProvisioningConfig.AdminUsername, (ConvertTo-SecureString -String $ProvisioningConfig.Password -AsPlainText -Force); | |
$Endpoint = Get-AzureEndpoint -Name PowerShell -VM (Get-AzureVM -ServiceName $Service.ServiceName -Name $VMConfig.Name); | |
$PSSession = @{ | |
ComputerName = '{0}.cloudapp.net' -f $Service.ServiceName; | |
Port = $Endpoint.Port; | |
Credential = $VMCredential; | |
SessionOption = $PSOption; | |
UseSSL = $true; | |
}; | |
#Enter-PSSession @PSSession; | |
Invoke-Command @PSSession -FilePath C:\test\ppe2014.ps1; | |
Get-AzureWinRMUri -ServiceName $Service.ServiceName -Name $VMConfig.Name; | |
New-PSSession - | |
$Job = Start-Job -ScriptBlock { Sleep 5; } | |
Wait-Job -Job $Job; | |
### | |
$VM = Get-AzureVM -ServiceName pcgeek86 -Name WinServ10-D2; | |
Set-AzureVMAccessExtension -UserName Trevor -Password P@ssw0rd!! -VM $VM.VM; | |
Update-AzureVM -ServiceName pcgeek86 -Name WinServ10-D2 -VM $VM.VM; | |
Restart-AzureVM -ServiceName pcgeek86 -Name WinServ10-D2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment