Table of Contents

Azure

https://docs.microsoft.com/de-de/azure/virtual-machines/scripts/virtual-machines-windows-powershell-sample-create-vm

https://aka.ms/installazurecliwindows

Powershell Commands

$PSVersionTable.PSVersion                                                                                 #get version
Get-Module -Name PowerShellGet -ListAvailable | Select-Object -Property Name,Version,Path                 #
Import-Module PowerShellGet -Force                                                                        #Update Powershell version
Get-ExecutionPolicy                                                                                       #check policy
Set-ExecutionPolicy Unrestricted                                                                          #set policy to unrestricted
Install-Module -Name AZureRM -AllowClobber                                                                #install azure module
Import-Module -Name AzureRM                                                                               #import azure module - "Get-ExecutionPolicy" has to be set to unrestricted!
Login-AzureRmAccount                                                                                      #login
Get-AzureRmSubscription                                                                                   #check active login
New-AzureRMRecourceGroup -Name groupname -Location westeurope                                             #creates new resourcegroup

Create Recource Group

Login-AzureRmAccount

$location = "westeurope"
$group = "test-vm-rg"

New-AzureRMRecourceGroup -Name $group -Location $location

Create Storageaccount

Login-AzureRmAccount

Get-AzureRmSubscription

cd\
cls

$location = "westeurope"
$group = "test-vm-rg"

$account = New-AzureRmStorageAccount -ResourceGroupName $group -Name tw012018 -Location $location -SkuName Standard_LRS

Get-AzureRMStorageAccount | Select StorageAccountName, Location

Create VirtualNetwork

Login-AzureRmAccount

Get-AzureRmSubscription

cd\
cls

$location = "westeurope"
$group = "test-vm-rg"

# Create Subnet
$vnet = New-AzureRmVirtualNetwork -Name vnet-test-powershell -ResourceGroupName $group -Location $location `
                -AddressPrefix "10.2.0.0/24"

Add-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name BaseSubnet -AddressPrefix "10.2.0.32/27"
Add-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name WebSubnet -AddressPrefix "10.2.0.64/27"
Add-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name DBSubnet -AddressPrefix "10.2.0.96/27"

Set-AzureRmVirtualNetwork -VirtualNetwork $vnet

Virtual Machine

Login-AzureRmAccount

Get-AzureRmSubscription

cd\
cls

New-AzureRmVm `
    -ResourceGroupName "test-vm-rg" `
    -Name "myVM" `
    -Location "westeurope" `
    -VirtualNetworkName "VMs-Testumgebung" `
    -SubnetName "test-network-vm" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "myPublicIpAddress" `
    -OpenPorts 80,3389
Remove-azvm -Name myVM -ResourceGroupName test-vm-rg

Azure CLI

https://docs.microsoft.com/de-de/cli/azure/install-azure-cli?view=azure-cli-latest

Powershell install

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'
Get-Command *az*
az login --use-device-code                                                                                #generate url + machine-code
az login
az group list --out table                                                                                 #show resource groups

Recource Group

az login

$group = "test-vm-rg"
$location = "westeurope"

az group create -l $location -n $group
az group delete -n $group

Create storage account

az login

$group = "test-vm-rg"
$location = "westeurope"
$account = "tw012018"

az storage account create --resource-group-name $group --location $location --sku Standard_LRS --name $account

az storage account show --resource-group $group --name $account

Create VirtualNetwork

az login --use-device-code

$group = "test-vm-rg"
$location = "westeurope"


az network vnet create --resource-group $group --location $location --name vnet-test-azurecli --address-prefixes "10.1.0.0/24" --subnet-name BaseSubnet --subnet-prefix "10.1.0.0/27"
az network vnet subnet create --resource-group $group --vnet-name vnet-test-azurecli --name WebSubnet --address-prefix "10.1.0.32/27"
az network vnet subnet create --resource-group $group --vnet-name vnet-test-azurecli --name DBSubnet --address-prefix "10.1.0.64/27"

VM

# Create Master Node - This will have a public IP
az vm create -n kube-master -g CustomKubeCluster --image ubuntults \
  --size Standard_DS2_v2 \
  --data-disk-sizes-gb 10 --generate-ssh-keys \
  --admin-username azureuser \
  --admin-password $AdminPassword \
  --public-ip-address-dns-name kubeadm-master
az vm list -g <resource-group-name> -d -o table
az vm image list --output table