From 82de5858f44308ff8886fb88d8bed5663d839e5b Mon Sep 17 00:00:00 2001 From: Stephen Tramer Date: Fri, 25 Jan 2019 10:08:19 -0800 Subject: [PATCH] Migrate virtual-machine/ AzureRM->Az --- ...isks-to-same-or-different-subscription.ps1 | 10 +- ...y-managed-disks-vhd-to-storage-account.ps1 | 10 +- ...shot-to-same-or-different-subscription.ps1 | 10 +- .../copy-snapshot-to-storage-account.ps1 | 10 +- .../create-docker-host/create-docker-host.ps1 | 32 +-- .../create-managed-disk-from-snapshot.ps1 | 12 +- ...sks-from-vhd-in-different-subscription.ps1 | 8 +- ...ots-from-vhd-in-different-subscription.ps1 | 8 +- .../create-vm-customdata.ps1 | 32 +-- .../create-vm-detailed/create-vm-detailed.ps1 | 26 +-- .../create-windows-vm-detailed.ps1 | 24 +-- .../create-windows-vm-quick.ps1 | 6 +- .../create-windows-vm-iis-dsc.ps1 | 6 +- .../create-vm-from-managed-os-disk.ps1 | 22 +- .../create-vm-from-snapshot.ps1 | 24 +-- .../create-vm-iis/create-windows-vm-iis.ps1 | 8 +- .../create-vm-monitor-oms.ps1 | 30 +-- .../create-windows-vm-detailed-oms.ps1 | 6 +- .../create-vm-nginx/create-vm-nginx.ps1 | 32 +-- .../create-vm-nlb/create-vm-nlb.ps1 | 68 +++---- .../create-wordpress-mysql.ps1 | 30 +-- .../encrypt-vm/encrypt-windows-vm.ps1 | 188 +++++++++--------- .../install-iis-format-disk.ps1 | 2 +- virtual-machine/sap/sap-scripts.psm1 | 4 +- 24 files changed, 304 insertions(+), 304 deletions(-) diff --git a/virtual-machine/copy-managed-disks-to-same-or-different-subscription/copy-managed-disks-to-same-or-different-subscription.ps1 b/virtual-machine/copy-managed-disks-to-same-or-different-subscription/copy-managed-disks-to-same-or-different-subscription.ps1 index 23607f40..ee8ed824 100644 --- a/virtual-machine/copy-managed-disks-to-same-or-different-subscription/copy-managed-disks-to-same-or-different-subscription.ps1 +++ b/virtual-machine/copy-managed-disks-to-same-or-different-subscription/copy-managed-disks-to-same-or-different-subscription.ps1 @@ -8,10 +8,10 @@ $sourceResourceGroupName='mySourceResourceGroupName' $managedDiskName='myDiskName' #Set the context to the subscription Id where Managed Disk exists -Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId +Select-AzSubscription -SubscriptionId $sourceSubscriptionId #Get the source managed disk -$managedDisk= Get-AzureRMDisk -ResourceGroupName $sourceResourceGroupName -DiskName $managedDiskName +$managedDisk= Get-AzDisk -ResourceGroupName $sourceResourceGroupName -DiskName $managedDiskName #Provide the subscription Id of the subscription where managed disk will be copied to #If managed disk is copied to the same subscription then you can skip this step @@ -22,9 +22,9 @@ $targetResourceGroupName='myTargetResourceGroupName' #Set the context to the subscription Id where managed disk will be copied to #If snapshot is copied to the same subscription then you can skip this step -Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +Select-AzSubscription -SubscriptionId $targetSubscriptionId -$diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy +$diskConfig = New-AzDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy #Create a new managed disk in the target subscription and resource group -New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $targetResourceGroupName \ No newline at end of file +New-AzDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $targetResourceGroupName diff --git a/virtual-machine/copy-managed-disks-vhd-to-storage-account/copy-managed-disks-vhd-to-storage-account.ps1 b/virtual-machine/copy-managed-disks-vhd-to-storage-account/copy-managed-disks-vhd-to-storage-account.ps1 index cffc3f4d..2075f94b 100644 --- a/virtual-machine/copy-managed-disks-vhd-to-storage-account/copy-managed-disks-vhd-to-storage-account.ps1 +++ b/virtual-machine/copy-managed-disks-vhd-to-storage-account/copy-managed-disks-vhd-to-storage-account.ps1 @@ -8,7 +8,7 @@ $resourceGroupName ="yourResourceGroupName" $diskName = "yourDiskName" #Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600. -#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1 +#Know more about SAS here: https://docs.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1 $sasExpiryDuration = "3600" #Provide storage account name where you want to copy the underlying VHD of the managed disk. @@ -25,13 +25,13 @@ $destinationVHDFileName = "yourvhdfilename" # Set the context to the subscription Id where managed disk is created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId #Generate the SAS for the managed disk -$sas = Grant-AzureRmDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read +$sas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $diskName -DurationInSecond $sasExpiryDuration -Access Read   #Create the context of the storage account where the underlying VHD of the managed disk will be copied -$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  +$destinationContext = New-AzStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  #Copy the VHD of the managed disk to the storage account -Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName \ No newline at end of file +Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName diff --git a/virtual-machine/copy-snapshot-to-same-or-different-subscription/copy-snapshot-to-same-or-different-subscription.ps1 b/virtual-machine/copy-snapshot-to-same-or-different-subscription/copy-snapshot-to-same-or-different-subscription.ps1 index df698770..9666d8f1 100644 --- a/virtual-machine/copy-snapshot-to-same-or-different-subscription/copy-snapshot-to-same-or-different-subscription.ps1 +++ b/virtual-machine/copy-snapshot-to-same-or-different-subscription/copy-snapshot-to-same-or-different-subscription.ps1 @@ -8,10 +8,10 @@ $sourceResourceGroupName='yourResourceGroupName' $snapshotName='yourSnapshotName' #Set the context to the subscription Id where snapshot exists -Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId +Select-AzSubscription -SubscriptionId $sourceSubscriptionId #Get the source snapshot -$snapshot= Get-AzureRmSnapshot -ResourceGroupName $sourceResourceGroupName -Name $snapshotName +$snapshot= Get-AzSnapshot -ResourceGroupName $sourceResourceGroupName -Name $snapshotName #Provide the subscription Id of the subscription where snapshot will be copied to #If snapshot is copied to the same subscription then you can skip this step @@ -22,9 +22,9 @@ $targetResourceGroupName='yourTargetResourceGroupName' #Set the context to the subscription Id where snapshot will be copied to #If snapshot is copied to the same subscription then you can skip this step -Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +Select-AzSubscription -SubscriptionId $targetSubscriptionId -$snapshotConfig = New-AzureRmSnapshotConfig -SourceResourceId $snapshot.Id -Location $snapshot.Location -CreateOption Copy +$snapshotConfig = New-AzSnapshotConfig -SourceResourceId $snapshot.Id -Location $snapshot.Location -CreateOption Copy #Create a new snapshot in the target subscription and resource group -New-AzureRmSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotName -ResourceGroupName $targetResourceGroupName \ No newline at end of file +New-AzSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotName -ResourceGroupName $targetResourceGroupName diff --git a/virtual-machine/copy-snapshot-to-storage-account/copy-snapshot-to-storage-account.ps1 b/virtual-machine/copy-snapshot-to-storage-account/copy-snapshot-to-storage-account.ps1 index aeef1375..52833cae 100644 --- a/virtual-machine/copy-snapshot-to-storage-account/copy-snapshot-to-storage-account.ps1 +++ b/virtual-machine/copy-snapshot-to-storage-account/copy-snapshot-to-storage-account.ps1 @@ -8,7 +8,7 @@ $resourceGroupName ="yourResourceGroupName" $snapshotName = "yourSnapshotName" #Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600. -#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1 +#Know more about SAS here: https://docs.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1 $sasExpiryDuration = "3600" #Provide storage account name where you want to copy the snapshot. @@ -25,13 +25,13 @@ $destinationVHDFileName = "yourvhdfilename" # Set the context to the subscription Id where Snapshot is created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId #Generate the SAS for the snapshot -$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read +$sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read   #Create the context for the storage account which will be used to copy snapshot to the storage account -$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  +$destinationContext = New-AzStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  #Copy the snapshot to the storage account -Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName \ No newline at end of file +Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName diff --git a/virtual-machine/create-docker-host/create-docker-host.ps1 b/virtual-machine/create-docker-host/create-docker-host.ps1 index 6e4ca549..53b67b87 100644 --- a/virtual-machine/create-docker-host/create-docker-host.ps1 +++ b/virtual-machine/create-docker-host/create-docker-host.ps1 @@ -8,53 +8,53 @@ $securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword) # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 22 -$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` +$nsgRuleSSH = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 22 -Access Allow # Create an inbound network security group rule for port 80 -$nsgRuleHTTP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` +$nsgRuleHTTP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` -Direction Inbound -Priority 2000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 80 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleSSH,$nsgRuleHTTP # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D1 | ` -Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` -Set-AzureRmVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D1 | ` +Set-AzVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` +Set-AzVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` +Add-AzVMNetworkInterface -Id $nic.Id # Configure SSH Keys $sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" -Add-AzureRmVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" +Add-AzVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig # Install Docker and run container $PublicSettings = '{"docker": {"port": "2375"},"compose": {"web": {"image": "nginx","ports": ["80:80"]}}}' -Set-AzureRmVMExtension -ExtensionName "Docker" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "Docker" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.Azure.Extensions" -ExtensionType "DockerExtension" -TypeHandlerVersion 1.0 ` - -SettingString $PublicSettings -Location $location \ No newline at end of file + -SettingString $PublicSettings -Location $location diff --git a/virtual-machine/create-managed-disk-from-snapshot/create-managed-disk-from-snapshot.ps1 b/virtual-machine/create-managed-disk-from-snapshot/create-managed-disk-from-snapshot.ps1 index 9f979636..75688320 100644 --- a/virtual-machine/create-managed-disk-from-snapshot/create-managed-disk-from-snapshot.ps1 +++ b/virtual-machine/create-managed-disk-from-snapshot/create-managed-disk-from-snapshot.ps1 @@ -19,15 +19,15 @@ $storageType = 'PremiumLRS' #Provide the Azure region (e.g. westus) where Managed Disks will be located. #This location should be same as the snapshot location #Get all the Azure location using command below: -#Get-AzureRmLocation +#Get-AzLocation $location = 'westus' #Set the context to the subscription Id where Managed Disk will be created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId -$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName +$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName   -$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id +$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id +  +New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName   -New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName -  \ No newline at end of file diff --git a/virtual-machine/create-managed-disks-from-vhd-in-different-subscription/create-managed-disks-from-vhd-in-different-subscription.ps1 b/virtual-machine/create-managed-disks-from-vhd-in-different-subscription/create-managed-disks-from-vhd-in-different-subscription.ps1 index cd4f1fcc..44f66ee1 100644 --- a/virtual-machine/create-managed-disks-from-vhd-in-different-subscription/create-managed-disks-from-vhd-in-different-subscription.ps1 +++ b/virtual-machine/create-managed-disks-from-vhd-in-different-subscription/create-managed-disks-from-vhd-in-different-subscription.ps1 @@ -16,7 +16,7 @@ $storageType = 'PremiumLRS' #Provide the Azure region (e.g. westus) where Managed Disk will be located. #This location should be same as the storage account where VHD file is stored #Get all the Azure location using command below: -#Get-AzureRmLocation +#Get-AzLocation $location = 'westus' #Provide the URI of the VHD file (page blob) in a storage account. Please not that this is NOT the SAS URI of the storage container where VHD file is stored. @@ -30,9 +30,9 @@ $sourceVHDURI = 'https://contosostorageaccount1.blob.core.windows.net/vhds/conto $storageAccountId = '/subscriptions/yourSubscriptionId/resourceGroups/yourResourceGroupName/providers/Microsoft.Storage/storageAccounts/yourStorageAccountName' #Set the context to the subscription Id where Managed Disk will be created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId -$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI +$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI   -New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName +New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName   diff --git a/virtual-machine/create-snapshots-from-vhd-in-different-subscription/create-snapshots-from-vhd-in-different-subscription.ps1 b/virtual-machine/create-snapshots-from-vhd-in-different-subscription/create-snapshots-from-vhd-in-different-subscription.ps1 index ac8f8c40..3a074e79 100644 --- a/virtual-machine/create-snapshots-from-vhd-in-different-subscription/create-snapshots-from-vhd-in-different-subscription.ps1 +++ b/virtual-machine/create-snapshots-from-vhd-in-different-subscription/create-snapshots-from-vhd-in-different-subscription.ps1 @@ -13,7 +13,7 @@ $storageType = 'StandardLRS' #Provide the Azure region (e.g. westus) where snapshot will be located. #This location should be same as the storage account location where VHD file is stored #Get all the Azure location using command below: -#Get-AzureRmLocation +#Get-AzLocation $location = 'westus' #Provide the URI of the VHD file (page blob) in a storage account. Please not that this is NOT the SAS URI of the storage container where VHD file is stored. @@ -27,9 +27,9 @@ $sourceVHDURI = 'https://yourStorageAccountName.blob.core.windows.net/vhds/yourV $storageAccountId = '/subscriptions/yourSubscriptionId/resourceGroups/yourResourceGroupName/providers/Microsoft.Storage/storageAccounts/yourStorageAccountName' #Set the context to the subscription Id where Managed Disk will be created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId -$snapshotConfig = New-AzureRmSnapshotConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI +$snapshotConfig = New-AzSnapshotConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI   -New-AzureRmSnapshot -Snapshot $snapshotConfig -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName +New-AzSnapshot -Snapshot $snapshotConfig -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName   diff --git a/virtual-machine/create-vm-customdata/create-vm-customdata.ps1 b/virtual-machine/create-vm-customdata/create-vm-customdata.ps1 index 7b7af591..c3d7ba82 100644 --- a/virtual-machine/create-vm-customdata/create-vm-customdata.ps1 +++ b/virtual-machine/create-vm-customdata/create-vm-customdata.ps1 @@ -7,15 +7,15 @@ $vmName = "myVM" $cred = Get-Credential # Create a resource group -New-AzureRmResourceGroup -ResourceGroupName myResourceGroup -Location eastus +New-AzResourceGroup -ResourceGroupName myResourceGroup -Location eastus # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig ` +$subnetConfig = New-AzVirtualNetworkSubnetConfig ` -Name mySubnet ` -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork ` +$vnet = New-AzVirtualNetwork ` -ResourceGroupName $resourceGroup ` -Location $location ` -Name myVnet ` @@ -23,14 +23,14 @@ $vnet = New-AzureRmVirtualNetwork ` -Subnet $subnetConfig # Create a public IP address -$pip = New-AzureRmPublicIpAddress ` +$pip = New-AzPublicIpAddress ` -ResourceGroupName $resourceGroup ` -Location $location ` -AllocationMethod Static ` -Name myPublicIPAddress # Create a network security group rule for port 80 -$nsgRule = New-AzureRmNetworkSecurityRuleConfig ` +$nsgRule = New-AzNetworkSecurityRuleConfig ` -Name myNSGRule ` -Protocol Tcp ` -Direction Inbound ` @@ -42,14 +42,14 @@ $nsgRule = New-AzureRmNetworkSecurityRuleConfig ` -Access Allow # Create a network security group using the rule -$nsg = New-AzureRmNetworkSecurityGroup ` +$nsg = New-AzNetworkSecurityGroup ` -ResourceGroupName $resourceGroup ` -Location $location ` -Name myNetworkSecurityGroup ` -SecurityRules $nsgRule # Create a network interface -$nic = New-AzureRmNetworkInterface ` +$nic = New-AzNetworkInterface ` -ResourceGroupName $resourceGroup ` -Location $location ` -Name myNic ` @@ -62,12 +62,12 @@ $encoded = [System.Text.Encoding]::UTF8.GetBytes("Add-WindowsFeature Web-Server; $etext = [System.Convert]::ToBase64String($encoded) # Create a VM configuration object -$vm = New-AzureRmVMConfig ` +$vm = New-AzVMConfig ` -VMName $vmName ` -VMSize Standard_D1 # Configure the operating system for the VM using the credentials and encoded commands -$vm = Set-AzureRmVMOperatingSystem ` +$vm = Set-AzVMOperatingSystem ` -VM $vm ` -Windows ` -ComputerName myVM ` @@ -77,7 +77,7 @@ $vm = Set-AzureRmVMOperatingSystem ` -EnableAutoUpdate # Define the image to use for the VM -$vm = Set-AzureRmVMSourceImage ` +$vm = Set-AzVMSourceImage ` -VM $vm ` -PublisherName MicrosoftWindowsServer ` -Offer WindowsServer ` @@ -85,7 +85,7 @@ $vm = Set-AzureRmVMSourceImage ` -Version latest # Configure the OS disk for the VM -$vm = Set-AzureRmVMOSDisk ` +$vm = Set-AzVMOSDisk ` -VM $vm ` -Name myOsDisk ` -StorageAccountType StandardLRS ` @@ -94,24 +94,24 @@ $vm = Set-AzureRmVMOSDisk ` -Caching ReadWrite # Get the Id of the network interface and add it to the VM configuration -$nic = Get-AzureRmNetworkInterface ` +$nic = Get-AzNetworkInterface ` -ResourceGroupName $resourceGroup ` -Name myNic -$vm = Add-AzureRmVMNetworkInterface ` +$vm = Add-AzVMNetworkInterface ` -VM $vm ` -Id $nic.Id # Create a VM -New-AzureRmVM -ResourceGroupName $resourceGroup ` +New-AzVM -ResourceGroupName $resourceGroup ` -Location eastus ` -VM $vm # Run the encoded commands on the VM to install IIS -Set-AzureRmVMExtension -ResourceGroupName $resourceGroup ` +Set-AzVMExtension -ResourceGroupName $resourceGroup ` -ExtensionName IIS ` -VMName $vmName ` -Publisher Microsoft.Compute ` -ExtensionType CustomScriptExtension ` -TypeHandlerVersion 1.4 ` -SettingString '{"commandToExecute":"powershell \"[System.Text.Encoding]::UTF8.GetString([System.convert]::FromBase64String((Get-Content C:\\AzureData\\CustomData.bin))) | Out-File .\\command.ps1; powershell.exe .\\command.ps1\""}' ` - -Location $location \ No newline at end of file + -Location $location diff --git a/virtual-machine/create-vm-detailed/create-vm-detailed.ps1 b/virtual-machine/create-vm-detailed/create-vm-detailed.ps1 index c4ae5761..7902545f 100644 --- a/virtual-machine/create-vm-detailed/create-vm-detailed.ps1 +++ b/virtual-machine/create-vm-detailed/create-vm-detailed.ps1 @@ -8,41 +8,41 @@ $securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword) # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 22 -$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` +$nsgRuleSSH = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 22 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleSSH # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D1 | -Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | -Set-AzureRmVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D1 | +Set-AzVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | +Set-AzVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | +Add-AzVMNetworkInterface -Id $nic.Id # Configure SSH Keys $sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" -Add-AzureRmVMSshPublicKey -VM $vmconfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" +Add-AzVMSshPublicKey -VM $vmconfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig diff --git a/virtual-machine/create-vm-detailed/create-windows-vm-detailed.ps1 b/virtual-machine/create-vm-detailed/create-windows-vm-detailed.ps1 index 8f9bc369..d1c7e5a9 100644 --- a/virtual-machine/create-vm-detailed/create-windows-vm-detailed.ps1 +++ b/virtual-machine/create-vm-detailed/create-windows-vm-detailed.ps1 @@ -7,37 +7,37 @@ $vmName = "myVM" $cred = Get-Credential -Message "Enter a username and password for the virtual machine." # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 3389 -$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP -Protocol Tcp ` +$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 3389 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleRDP # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D1 | ` -Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName -Credential $cred | ` -Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version latest | ` -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D1 | ` +Set-AzVMOperatingSystem -Windows -ComputerName $vmName -Credential $cred | ` +Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version latest | ` +Add-AzVMNetworkInterface -Id $nic.Id # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig \ No newline at end of file +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig diff --git a/virtual-machine/create-vm-detailed/create-windows-vm-quick.ps1 b/virtual-machine/create-vm-detailed/create-windows-vm-quick.ps1 index 92eb485a..c9969927 100644 --- a/virtual-machine/create-vm-detailed/create-windows-vm-quick.ps1 +++ b/virtual-machine/create-vm-detailed/create-windows-vm-quick.ps1 @@ -7,10 +7,10 @@ $vmName = "myVM" $cred = Get-Credential -Message "Enter a username and password for the virtual machine." # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a virtual machine -New-AzureRmVM ` +New-AzVM ` -ResourceGroupName $resourceGroup ` -Name $vmName ` -Location $location ` @@ -20,4 +20,4 @@ New-AzureRmVM ` -SecurityGroupName "myNetworkSecurityGroup" ` -PublicIpAddressName "myPublicIp" ` -Credential $cred ` - -OpenPorts 3389 \ No newline at end of file + -OpenPorts 3389 diff --git a/virtual-machine/create-vm-dsc/create-windows-vm-iis-dsc.ps1 b/virtual-machine/create-vm-dsc/create-windows-vm-iis-dsc.ps1 index 19a743a2..4e7af177 100644 --- a/virtual-machine/create-vm-dsc/create-windows-vm-iis-dsc.ps1 +++ b/virtual-machine/create-vm-dsc/create-windows-vm-iis-dsc.ps1 @@ -4,13 +4,13 @@ $location = "westeurope" $vmName = "myVM" # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create user object $cred = Get-Credential -Message "Enter a username and password for the virtual machine." # Create a virtual machine -New-AzureRmVM ` +New-AzVM ` -ResourceGroupName $resourceGroup ` -Name $vmName ` -Location $location ` @@ -25,6 +25,6 @@ New-AzureRmVM ` # Install IIS $PublicSettings = '{"ModulesURL":"https://github.com/Azure/azure-quickstart-templates/raw/master/dsc-extension-iis-server-windows-vm/ContosoWebsite.ps1.zip", "configurationFunction": "ContosoWebsite.ps1\\ContosoWebsite", "Properties": {"MachineName": "myVM"} }' -Set-AzureRmVMExtension -ExtensionName "DSC" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "DSC" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.Powershell" -ExtensionType "DSC" -TypeHandlerVersion 2.19 ` -SettingString $PublicSettings -Location $location diff --git a/virtual-machine/create-vm-from-managed-os-disk/create-vm-from-managed-os-disk.ps1 b/virtual-machine/create-vm-from-managed-os-disk/create-vm-from-managed-os-disk.ps1 index 8f154a13..c2ce255b 100644 --- a/virtual-machine/create-vm-from-managed-os-disk/create-vm-from-managed-os-disk.ps1 +++ b/virtual-machine/create-vm-from-managed-os-disk/create-vm-from-managed-os-disk.ps1 @@ -12,7 +12,7 @@ $diskName = 'yourDiskName' #Provide the Azure region (e.g. westus) where virtual machine will be located. #This location should be same as the Managed Disk location #Get all the Azure location using command below: -#Get-AzureRmLocation +#Get-AzLocation $location = 'westus' #Provide the name of an existing virtual network where virtual machine will be created @@ -24,32 +24,32 @@ $virtualMachineName = 'yourVirtualMachineName' #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 westus +#e.g. Get-AzVMSize -Location westus $virtualMachineSize = 'Standard_DS3' #Set the context to the subscription Id where Managed Disk will be created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId #Get the Managed Disk based on the resource group and the disk name -$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName $diskName +$disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName #Initialize virtual machine configuration -$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize +$VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -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 +$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows #Create a public IP for the VM -$publicIp = New-AzureRmPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $location -AllocationMethod Dynamic +$publicIp = New-AzPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $location -AllocationMethod Dynamic #Get the virtual network where virtual machine will be hosted -$vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName +$vnet = Get-AzVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName # Create NIC in the first subnet of the virtual network -$nic = New-AzureRmNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName $resourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id +$nic = New-AzNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName $resourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id -$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id +$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id #Create the virtual machine with Managed Disk -New-AzureRmVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $location \ No newline at end of file +New-AzVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $location diff --git a/virtual-machine/create-vm-from-snapshot/create-vm-from-snapshot.ps1 b/virtual-machine/create-vm-from-snapshot/create-vm-from-snapshot.ps1 index 45fcde5b..6215f312 100644 --- a/virtual-machine/create-vm-from-snapshot/create-vm-from-snapshot.ps1 +++ b/virtual-machine/create-vm-from-snapshot/create-vm-from-snapshot.ps1 @@ -19,34 +19,34 @@ $virtualMachineName = 'yourVMName' #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 westus +#e.g. Get-AzVMSize -Location westus $virtualMachineSize = 'Standard_DS3' #Set the context to the subscription Id where Managed Disk will be created -Select-AzureRmSubscription -SubscriptionId $SubscriptionId +Select-AzSubscription -SubscriptionId $SubscriptionId -$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName +$snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName   -$diskConfig = New-AzureRmDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy +$diskConfig = New-AzDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy   -$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName +$disk = New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName #Initialize virtual machine configuration -$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize +$VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -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 +$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows #Create a public IP for the VM -$publicIp = New-AzureRmPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $snapshot.Location -AllocationMethod Dynamic +$publicIp = New-AzPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $snapshot.Location -AllocationMethod Dynamic #Get the virtual network where virtual machine will be hosted -$vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName +$vnet = Get-AzVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName # Create NIC in the first subnet of the virtual network -$nic = New-AzureRmNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName $resourceGroupName -Location $snapshot.Location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id +$nic = New-AzNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName $resourceGroupName -Location $snapshot.Location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id -$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id +$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id #Create the virtual machine with Managed Disk -New-AzureRmVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $snapshot.Location +New-AzVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $snapshot.Location diff --git a/virtual-machine/create-vm-iis/create-windows-vm-iis.ps1 b/virtual-machine/create-vm-iis/create-windows-vm-iis.ps1 index 1fffb547..49533cf1 100644 --- a/virtual-machine/create-vm-iis/create-windows-vm-iis.ps1 +++ b/virtual-machine/create-vm-iis/create-windows-vm-iis.ps1 @@ -7,10 +7,10 @@ $vmName = "myVM" $cred = Get-Credential -Message "Enter a username and password for the virtual machine." # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a virtual machine -New-AzureRmVM ` +New-AzVM ` -ResourceGroupName $resourceGroup ` -Name $vmName ` -Location $location ` @@ -25,6 +25,6 @@ New-AzureRmVM ` # Install IIS $PublicSettings = '{"commandToExecute":"powershell Add-WindowsFeature Web-Server"}' -Set-AzureRmVMExtension -ExtensionName "IIS" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "IIS" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.Compute" -ExtensionType "CustomScriptExtension" -TypeHandlerVersion 1.4 ` - -SettingString $PublicSettings -Location $location \ No newline at end of file + -SettingString $PublicSettings -Location $location diff --git a/virtual-machine/create-vm-monitor-oms/create-vm-monitor-oms.ps1 b/virtual-machine/create-vm-monitor-oms/create-vm-monitor-oms.ps1 index 5aefece3..51b2cd2d 100644 --- a/virtual-machine/create-vm-monitor-oms/create-vm-monitor-oms.ps1 +++ b/virtual-machine/create-vm-monitor-oms/create-vm-monitor-oms.ps1 @@ -12,50 +12,50 @@ $securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword) # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 22 -$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` +$nsgRuleSSH = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 22 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleSSH # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D1 | ` -Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` -Set-AzureRmVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D1 | ` +Set-AzVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` +Set-AzVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` +Add-AzVMNetworkInterface -Id $nic.Id # Configure SSH Keys $sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" -Add-AzureRmVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" +Add-AzVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig # Install and configure the OMS agent $PublicSettings = New-Object psobject | Add-Member -PassThru NoteProperty workspaceId $omsId | ConvertTo-Json $protectedSettings = New-Object psobject | Add-Member -PassThru NoteProperty workspaceKey $omsKey | ConvertTo-Json -Set-AzureRmVMExtension -ExtensionName "OMS" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "OMS" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.EnterpriseCloud.Monitoring" -ExtensionType "OmsAgentForLinux" ` -TypeHandlerVersion 1.0 -SettingString $PublicSettings ` -ProtectedSettingString $protectedSettings ` - -Location $location \ No newline at end of file + -Location $location diff --git a/virtual-machine/create-vm-monitor-oms/create-windows-vm-detailed-oms.ps1 b/virtual-machine/create-vm-monitor-oms/create-windows-vm-detailed-oms.ps1 index acdc4475..83ba3b45 100644 --- a/virtual-machine/create-vm-monitor-oms/create-windows-vm-detailed-oms.ps1 +++ b/virtual-machine/create-vm-monitor-oms/create-windows-vm-detailed-oms.ps1 @@ -11,10 +11,10 @@ $vmName = "myVM" $cred = Get-Credential -Message "Enter a username and password for the virtual machine." # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a virtual machine -New-AzureRmVM ` +New-AzVM ` -ResourceGroupName $resourceGroup ` -Name $vmName ` -Location $location ` @@ -30,7 +30,7 @@ New-AzureRmVM ` $PublicSettings = New-Object psobject | Add-Member -PassThru NoteProperty workspaceId $omsId | ConvertTo-Json $protectedSettings = New-Object psobject | Add-Member -PassThru NoteProperty workspaceKey $omsKey | ConvertTo-Json -Set-AzureRmVMExtension -ExtensionName "OMS" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "OMS" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.EnterpriseCloud.Monitoring" -ExtensionType "MicrosoftMonitoringAgent" ` -TypeHandlerVersion 1.0 -SettingString $PublicSettings -ProtectedSettingString $protectedSettings ` -Location $location diff --git a/virtual-machine/create-vm-nginx/create-vm-nginx.ps1 b/virtual-machine/create-vm-nginx/create-vm-nginx.ps1 index 56953213..785d3775 100644 --- a/virtual-machine/create-vm-nginx/create-vm-nginx.ps1 +++ b/virtual-machine/create-vm-nginx/create-vm-nginx.ps1 @@ -8,53 +8,53 @@ $securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword) # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 22 -$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` +$nsgRuleSSH = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 22 -Access Allow # Create an inbound network security group rule for port 80 -$nsgRuleHTTP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` +$nsgRuleHTTP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` -Direction Inbound -Priority 2000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 80 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleSSH,$nsgRuleHTTP # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D1 | ` -Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` -Set-AzureRmVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmName -VMSize Standard_D1 | ` +Set-AzVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` +Set-AzVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` +Add-AzVMNetworkInterface -Id $nic.Id # Configure SSH Keys $sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" -Add-AzureRmVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" +Add-AzVMSshPublicKey -VM $vmConfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig # Install NGINX. $PublicSettings = '{"commandToExecute":"apt-get -y update && apt-get -y install nginx"}' -Set-AzureRmVMExtension -ExtensionName "NGINX" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "NGINX" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.Azure.Extensions" -ExtensionType "CustomScript" -TypeHandlerVersion 2.0 ` - -SettingString $PublicSettings -Location $location \ No newline at end of file + -SettingString $PublicSettings -Location $location diff --git a/virtual-machine/create-vm-nlb/create-vm-nlb.ps1 b/virtual-machine/create-vm-nlb/create-vm-nlb.ps1 index 14d3877f..ce294b05 100644 --- a/virtual-machine/create-vm-nlb/create-vm-nlb.ps1 +++ b/virtual-machine/create-vm-nlb/create-vm-nlb.ps1 @@ -6,79 +6,79 @@ $location='eastus' $cred = Get-Credential -Message 'Enter a username and password for the virtual machine.' # Create a resource group. -New-AzureRmResourceGroup -Name $rgName -Location $location +New-AzResourceGroup -Name $rgName -Location $location # Create a virtual network. -$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name 'MySubnet' -AddressPrefix 192.168.1.0/24 +$subnet = New-AzVirtualNetworkSubnetConfig -Name 'MySubnet' -AddressPrefix 192.168.1.0/24 -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name 'MyVnet' ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $rgName -Name 'MyVnet' ` -AddressPrefix 192.168.0.0/16 -Location $location -Subnet $subnet # Create a public IP address. -$publicIp = New-AzureRmPublicIpAddress -ResourceGroupName $rgName -Name 'myPublicIP' ` +$publicIp = New-AzPublicIpAddress -ResourceGroupName $rgName -Name 'myPublicIP' ` -Location $location -AllocationMethod Dynamic # Create a front-end IP configuration for the website. -$feip = New-AzureRmLoadBalancerFrontendIpConfig -Name 'myFrontEndPool' -PublicIpAddress $publicIp +$feip = New-AzLoadBalancerFrontendIpConfig -Name 'myFrontEndPool' -PublicIpAddress $publicIp # Create the back-end address pool. -$bepool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name 'myBackEndPool' +$bepool = New-AzLoadBalancerBackendAddressPoolConfig -Name 'myBackEndPool' # Creates a load balancer probe on port 80. -$probe = New-AzureRmLoadBalancerProbeConfig -Name 'myHealthProbe' -Protocol Http -Port 80 ` +$probe = New-AzLoadBalancerProbeConfig -Name 'myHealthProbe' -Protocol Http -Port 80 ` -RequestPath / -IntervalInSeconds 360 -ProbeCount 5 # Creates a load balancer rule for port 80. -$rule = New-AzureRmLoadBalancerRuleConfig -Name 'myLoadBalancerRuleWeb' -Protocol Tcp ` +$rule = New-AzLoadBalancerRuleConfig -Name 'myLoadBalancerRuleWeb' -Protocol Tcp ` -Probe $probe -FrontendPort 80 -BackendPort 80 ` -FrontendIpConfiguration $feip -BackendAddressPool $bePool # Create three NAT rules for port 3389. -$natrule1 = New-AzureRmLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP1' -FrontendIpConfiguration $feip ` +$natrule1 = New-AzLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP1' -FrontendIpConfiguration $feip ` -Protocol tcp -FrontendPort 4221 -BackendPort 3389 -$natrule2 = New-AzureRmLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP2' -FrontendIpConfiguration $feip ` +$natrule2 = New-AzLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP2' -FrontendIpConfiguration $feip ` -Protocol tcp -FrontendPort 4222 -BackendPort 3389 -$natrule3 = New-AzureRmLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP3' -FrontendIpConfiguration $feip ` +$natrule3 = New-AzLoadBalancerInboundNatRuleConfig -Name 'myLoadBalancerRDP3' -FrontendIpConfiguration $feip ` -Protocol tcp -FrontendPort 4223 -BackendPort 3389 # Create a load balancer. -$lb = New-AzureRmLoadBalancer -ResourceGroupName $rgName -Name 'MyLoadBalancer' -Location $location ` +$lb = New-AzLoadBalancer -ResourceGroupName $rgName -Name 'MyLoadBalancer' -Location $location ` -FrontendIpConfiguration $feip -BackendAddressPool $bepool ` -Probe $probe -LoadBalancingRule $rule -InboundNatRule $natrule1,$natrule2,$natrule3 # Create a network security group rule for port 3389. -$rule1 = New-AzureRmNetworkSecurityRuleConfig -Name 'myNetworkSecurityGroupRuleRDP' -Description 'Allow RDP' ` +$rule1 = New-AzNetworkSecurityRuleConfig -Name 'myNetworkSecurityGroupRuleRDP' -Description 'Allow RDP' ` -Access Allow -Protocol Tcp -Direction Inbound -Priority 1000 ` -SourceAddressPrefix Internet -SourcePortRange * ` -DestinationAddressPrefix * -DestinationPortRange 3389 # Create a network security group rule for port 80. -$rule2 = New-AzureRmNetworkSecurityRuleConfig -Name 'myNetworkSecurityGroupRuleHTTP' -Description 'Allow HTTP' ` +$rule2 = New-AzNetworkSecurityRuleConfig -Name 'myNetworkSecurityGroupRuleHTTP' -Description 'Allow HTTP' ` -Access Allow -Protocol Tcp -Direction Inbound -Priority 2000 ` -SourceAddressPrefix Internet -SourcePortRange * ` -DestinationAddressPrefix * -DestinationPortRange 80 # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $RgName -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $RgName -Location $location ` -Name 'myNetworkSecurityGroup' -SecurityRules $rule1,$rule2 # Create three virtual network cards and associate with public IP address and NSG. -$nicVM1 = New-AzureRmNetworkInterface -ResourceGroupName $rgName -Location $location ` +$nicVM1 = New-AzNetworkInterface -ResourceGroupName $rgName -Location $location ` -Name 'MyNic1' -LoadBalancerBackendAddressPool $bepool -NetworkSecurityGroup $nsg ` -LoadBalancerInboundNatRule $natrule1 -Subnet $vnet.Subnets[0] -$nicVM2 = New-AzureRmNetworkInterface -ResourceGroupName $rgName -Location $location ` +$nicVM2 = New-AzNetworkInterface -ResourceGroupName $rgName -Location $location ` -Name 'MyNic2' -LoadBalancerBackendAddressPool $bepool -NetworkSecurityGroup $nsg ` -LoadBalancerInboundNatRule $natrule2 -Subnet $vnet.Subnets[0] -$nicVM3 = New-AzureRmNetworkInterface -ResourceGroupName $rgName -Location $location ` +$nicVM3 = New-AzNetworkInterface -ResourceGroupName $rgName -Location $location ` -Name 'MyNic3' -LoadBalancerBackendAddressPool $bepool -NetworkSecurityGroup $nsg ` -LoadBalancerInboundNatRule $natrule3 -Subnet $vnet.Subnets[0] # Create an availability set. -$as = New-AzureRmAvailabilitySet -ResourceGroupName $rgName -Location $location ` +$as = New-AzAvailabilitySet -ResourceGroupName $rgName -Location $location ` -Name 'MyAvailabilitySet' -Sku Aligned -PlatformFaultDomainCount 3 -PlatformUpdateDomainCount 3 # Create three virtual machines. @@ -86,32 +86,32 @@ $as = New-AzureRmAvailabilitySet -ResourceGroupName $rgName -Location $location # ############## VM1 ############### # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName 'myVM1' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` - Set-AzureRmVMOperatingSystem -Windows -ComputerName 'myVM1' -Credential $cred | ` - Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` - -Skus 2016-Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $nicVM1.Id +$vmConfig = New-AzVMConfig -VMName 'myVM1' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` + Set-AzVMOperatingSystem -Windows -ComputerName 'myVM1' -Credential $cred | ` + Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` + -Skus 2016-Datacenter -Version latest | Add-AzVMNetworkInterface -Id $nicVM1.Id # Create a virtual machine -$vm1 = New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmConfig +$vm1 = New-AzVM -ResourceGroupName $rgName -Location $location -VM $vmConfig # ############## VM2 ############### # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName 'myVM2' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` - Set-AzureRmVMOperatingSystem -Windows -ComputerName 'myVM2' -Credential $cred | ` - Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` - -Skus 2016-Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $nicVM2.Id +$vmConfig = New-AzVMConfig -VMName 'myVM2' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` + Set-AzVMOperatingSystem -Windows -ComputerName 'myVM2' -Credential $cred | ` + Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` + -Skus 2016-Datacenter -Version latest | Add-AzVMNetworkInterface -Id $nicVM2.Id # Create a virtual machine -$vm2 = New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmConfig +$vm2 = New-AzVM -ResourceGroupName $rgName -Location $location -VM $vmConfig # ############## VM3 ############### # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName 'myVM3' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` - Set-AzureRmVMOperatingSystem -Windows -ComputerName 'myVM3' -Credential $cred | ` - Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` - -Skus 2016-Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $nicVM3.Id +$vmConfig = New-AzVMConfig -VMName 'myVM3' -VMSize Standard_DS2 -AvailabilitySetId $as.Id | ` + Set-AzVMOperatingSystem -Windows -ComputerName 'myVM3' -Credential $cred | ` + Set-AzVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` + -Skus 2016-Datacenter -Version latest | Add-AzVMNetworkInterface -Id $nicVM3.Id # Create a virtual machine -$vm3 = New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmConfig +$vm3 = New-AzVM -ResourceGroupName $rgName -Location $location -VM $vmConfig diff --git a/virtual-machine/create-wordpress-mysql/create-wordpress-mysql.ps1 b/virtual-machine/create-wordpress-mysql/create-wordpress-mysql.ps1 index d5e11da8..6bfecbce 100644 --- a/virtual-machine/create-wordpress-mysql/create-wordpress-mysql.ps1 +++ b/virtual-machine/create-wordpress-mysql/create-wordpress-mysql.ps1 @@ -8,54 +8,54 @@ $securePassword = ConvertTo-SecureString ' ' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword) # Create a resource group -New-AzureRmResourceGroup -Name $resourceGroup -Location $location +New-AzResourceGroup -Name $resourceGroup -Location $location # Create a subnet configuration -$subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 +$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name mySubnet -AddressPrefix 192.168.1.0/24 # Create a virtual network -$vnet = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` +$vnet = New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Location $location ` -Name MYvNET -AddressPrefix 192.168.0.0/16 -Subnet $subnetConfig # Create a public IP address and specify a DNS name -$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` +$pip = New-AzPublicIpAddress -ResourceGroupName $resourceGroup -Location $location ` -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4 # Create an inbound network security group rule for port 22 -$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` +$nsgRuleSSH = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleSSH -Protocol Tcp ` -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 22 -Access Allow # Create an inbound network security group rule for port 80 -$nsgRuleHTTP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` +$nsgRuleHTTP = New-AzNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleHTTP -Protocol Tcp ` -Direction Inbound -Priority 2000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * ` -DestinationPortRange 80 -Access Allow # Create a network security group -$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` +$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location ` -Name myNetworkSecurityGroup -SecurityRules $nsgRuleSSH,$nsgRuleHTTP # Create a virtual network card and associate with public IP address and NSG -$nic = New-AzureRmNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` +$nic = New-AzNetworkInterface -Name myNic -ResourceGroupName $resourceGroup -Location $location ` -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id # Create a virtual machine configuration -$vmConfig = New-AzureRmVMConfig -VMName $vmname -VMSize Standard_D1 | ` -Set-AzureRmVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` -Set-AzureRmVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` -Add-AzureRmVMNetworkInterface -Id $nic.Id +$vmConfig = New-AzVMConfig -VMName $vmname -VMSize Standard_D1 | ` +Set-AzVMOperatingSystem -Linux -ComputerName $vmName -Credential $cred -DisablePasswordAuthentication | ` +Set-AzVMSourceImage -PublisherName Canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version latest | ` +Add-AzVMNetworkInterface -Id $nic.Id # Configure SSH Keys $sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub" -Add-AzureRmVMSshPublicKey -VM $vmconfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" +Add-AzVMSshPublicKey -VM $vmconfig -KeyData $sshPublicKey -Path "/home/azureuser/.ssh/authorized_keys" # Create a virtual machine -New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig +New-AzVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig # Start a CustomScript extension to use a simple bash script to update, download and install WordPress and MySQL $PublicSettings = '{"fileUris":["https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/wordpress-single-vm-ubuntu/install_wordpress.sh"],"commandToExecute":"sh install_wordpress.sh"}' -Set-AzureRmVMExtension -ExtensionName "WordPress" -ResourceGroupName $resourceGroup -VMName $vmName ` +Set-AzVMExtension -ExtensionName "WordPress" -ResourceGroupName $resourceGroup -VMName $vmName ` -Publisher "Microsoft.Azure.Extensions" -ExtensionType "CustomScript" -TypeHandlerVersion 2.0 ` -SettingString $PublicSettings ` -Location $location diff --git a/virtual-machine/encrypt-vm/encrypt-windows-vm.ps1 b/virtual-machine/encrypt-vm/encrypt-windows-vm.ps1 index 9c34f9bb..c21f4b75 100644 --- a/virtual-machine/encrypt-vm/encrypt-windows-vm.ps1 +++ b/virtual-machine/encrypt-vm/encrypt-windows-vm.ps1 @@ -1,94 +1,94 @@ -# Edit these global variables with you unique Key Vault name, resource group name and location -#Name of the Key Vault -$keyVaultName = "myKeyVault00" -#Resource Group Name -$rgName = "myResourceGroup" -#Region -$location = "East US" -#Password to place w/in the KeyVault -$securePassword = ConvertTo-SecureString -String "P@ssword!" -AsPlainText -Force -#Name for the Azure AD Application -$appName = "My App" -#Name for the VM to be encrypt -$vmName = "myEncryptedVM" -#user name for the admin account in the vm being created and then encrypted -$vmAdminName = "encryptedUser" - -# Register the Key Vault provider and create a resource group -New-AzureRmResourceGroup -Location $location -Name $rgName - -# Create a Key Vault and enable it for disk encryption -New-AzureRmKeyVault ` - -Location $location ` - -ResourceGroupName $rgName ` - -VaultName $keyVaultName ` - -EnabledForDiskEncryption - -# Create a key in your Key Vault -Add-AzureKeyVaultKey ` - -VaultName $keyVaultName ` - -Name "myKey" ` - -Destination "Software" - -# Put the password in the Key Vault as a Key Vault Secret so we can use it later -# We should never put passwords in scripts. -Set-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds -SecretValue $securePassword -Set-AzureKeyVaultSecret -VaultName $keyVaultName -Name protectValue -SecretValue $password - - -# Create Azure Active Directory app and service principal -$app = New-AzureRmADApplication -DisplayName $appName ` - -HomePage "https://myapp0.contoso.com" ` - -IdentifierUris "https://contoso.com/myapp0" ` - -Password (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValue - -New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId - -# Set permissions to allow your AAD service principal to read keys from Key Vault -Set-AzureRmKeyVaultAccessPolicy -VaultName $keyvaultName ` - -ServicePrincipalName $app.ApplicationId ` - -PermissionsToKeys decrypt,encrypt,unwrapKey,wrapKey,verify,sign,get,list,update ` - -PermissionsToSecrets get,list,set,delete,backup,restore,recover,purge - -# Create PSCredential object for VM -$cred = New-Object System.Management.Automation.PSCredential($vmAdminName, (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValue) - -# Create a virtual machine -New-AzureRmVM ` - -ResourceGroupName $rgName ` - -Name $vmName ` - -Location $location ` - -ImageName "Win2016Datacenter" ` - -VirtualNetworkName "myVnet" ` - -SubnetName "mySubnet" ` - -SecurityGroupName "myNetworkSecurityGroup" ` - -PublicIpAddressName "myPublicIp" ` - -Credential $cred ` - -OpenPorts 3389 - -# Define required information for our Key Vault and keys -$keyVault = Get-AzureRmKeyVault -VaultName $keyVaultName -ResourceGroupName $rgName; -$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; -$keyVaultResourceId = $keyVault.ResourceId; -$keyEncryptionKeyUrl = (Get-AzureKeyVaultKey -VaultName $keyVaultName -Name "myKey").Key.kid; - -# Encrypt our virtual machine -Set-AzureRmVMDiskEncryptionExtension ` - -ResourceGroupName $rgName ` - -VMName $vmName ` - -AadClientID $app.ApplicationId ` - -AadClientSecret (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValueText ` - -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl ` - -DiskEncryptionKeyVaultId $keyVaultResourceId ` - -KeyEncryptionKeyUrl $keyEncryptionKeyUrl ` - -KeyEncryptionKeyVaultId $keyVaultResourceId - -# View encryption status -Get-AzureRmVmDiskEncryptionStatus -ResourceGroupName $rgName -VMName $vmName - -<# -#clean up -Remove-AzureRmResourceGroup -Name $rgName -#removes all of the Azure AD Applications you created w/ the same name -Remove-AzureRmADApplication -ObjectId $app.ObjectId -Force -#> +# Edit these global variables with you unique Key Vault name, resource group name and location +#Name of the Key Vault +$keyVaultName = "myKeyVault00" +#Resource Group Name +$rgName = "myResourceGroup" +#Region +$location = "East US" +#Password to place w/in the KeyVault +$securePassword = ConvertTo-SecureString -String "P@ssword!" -AsPlainText -Force +#Name for the Azure AD Application +$appName = "My App" +#Name for the VM to be encrypt +$vmName = "myEncryptedVM" +#user name for the admin account in the vm being created and then encrypted +$vmAdminName = "encryptedUser" + +# Register the Key Vault provider and create a resource group +New-AzResourceGroup -Location $location -Name $rgName + +# Create a Key Vault and enable it for disk encryption +New-AzKeyVault ` + -Location $location ` + -ResourceGroupName $rgName ` + -VaultName $keyVaultName ` + -EnabledForDiskEncryption + +# Create a key in your Key Vault +Add-AzureKeyVaultKey ` + -VaultName $keyVaultName ` + -Name "myKey" ` + -Destination "Software" + +# Put the password in the Key Vault as a Key Vault Secret so we can use it later +# We should never put passwords in scripts. +Set-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds -SecretValue $securePassword +Set-AzureKeyVaultSecret -VaultName $keyVaultName -Name protectValue -SecretValue $password + + +# Create Azure Active Directory app and service principal +$app = New-AzADApplication -DisplayName $appName ` + -HomePage "https://myapp0.contoso.com" ` + -IdentifierUris "https://contoso.com/myapp0" ` + -Password (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValue + +New-AzADServicePrincipal -ApplicationId $app.ApplicationId + +# Set permissions to allow your AAD service principal to read keys from Key Vault +Set-AzKeyVaultAccessPolicy -VaultName $keyvaultName ` + -ServicePrincipalName $app.ApplicationId ` + -PermissionsToKeys decrypt,encrypt,unwrapKey,wrapKey,verify,sign,get,list,update ` + -PermissionsToSecrets get,list,set,delete,backup,restore,recover,purge + +# Create PSCredential object for VM +$cred = New-Object System.Management.Automation.PSCredential($vmAdminName, (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValue) + +# Create a virtual machine +New-AzVM ` + -ResourceGroupName $rgName ` + -Name $vmName ` + -Location $location ` + -ImageName "Win2016Datacenter" ` + -VirtualNetworkName "myVnet" ` + -SubnetName "mySubnet" ` + -SecurityGroupName "myNetworkSecurityGroup" ` + -PublicIpAddressName "myPublicIp" ` + -Credential $cred ` + -OpenPorts 3389 + +# Define required information for our Key Vault and keys +$keyVault = Get-AzKeyVault -VaultName $keyVaultName -ResourceGroupName $rgName; +$diskEncryptionKeyVaultUrl = $keyVault.VaultUri; +$keyVaultResourceId = $keyVault.ResourceId; +$keyEncryptionKeyUrl = (Get-AzureKeyVaultKey -VaultName $keyVaultName -Name "myKey").Key.kid; + +# Encrypt our virtual machine +Set-AzVMDiskEncryptionExtension ` + -ResourceGroupName $rgName ` + -VMName $vmName ` + -AadClientID $app.ApplicationId ` + -AadClientSecret (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name adminCreds).SecretValueText ` + -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl ` + -DiskEncryptionKeyVaultId $keyVaultResourceId ` + -KeyEncryptionKeyUrl $keyEncryptionKeyUrl ` + -KeyEncryptionKeyVaultId $keyVaultResourceId + +# View encryption status +Get-AzVmDiskEncryptionStatus -ResourceGroupName $rgName -VMName $vmName + +<# +#clean up +Remove-AzResourceGroup -Name $rgName +#removes all of the Azure AD Applications you created w/ the same name +Remove-AzADApplication -ObjectId $app.ObjectId -Force +#> diff --git a/virtual-machine/install-iis-format-disk/install-iis-format-disk.ps1 b/virtual-machine/install-iis-format-disk/install-iis-format-disk.ps1 index d00764d7..eec6e2f1 100644 --- a/virtual-machine/install-iis-format-disk/install-iis-format-disk.ps1 +++ b/virtual-machine/install-iis-format-disk/install-iis-format-disk.ps1 @@ -2,4 +2,4 @@ # Install IIS on the VM Add-WindowsFeature Web-Server # Format the data disk that has been added to the VM -Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "myDataDisk" -Confirm:$false \ No newline at end of file +Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "myDataDisk" -Confirm:$false diff --git a/virtual-machine/sap/sap-scripts.psm1 b/virtual-machine/sap/sap-scripts.psm1 index 7f946de3..56659a97 100644 --- a/virtual-machine/sap/sap-scripts.psm1 +++ b/virtual-machine/sap/sap-scripts.psm1 @@ -1,4 +1,4 @@ - + function Update-SAPASCSSCSProfile{ <# .SYNOPSIS @@ -423,4 +423,4 @@ PROCESS{ Write-Host Write-Host "[INFO] Update of $PathToDEFAULTProfile profile done!" } -} \ No newline at end of file +}