From 48333a5534a899fc801e1a2ff2662c4fabd96399 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 4 Sep 2018 10:52:02 +0800 Subject: [PATCH 01/32] Update readme.md --- Azure/readme.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Azure/readme.md b/Azure/readme.md index ed1506f..30a427e 100644 --- a/Azure/readme.md +++ b/Azure/readme.md @@ -1 +1,7 @@ -Look into Basics folder first and follow the instructions +# Pre-requisites for using the scripts. + +Install Azure RM modules as per this script. +https://github.com/Brucius/PowerShell-for-Partners/blob/master/Azure/Basics/InstallUpdateAzureRM%26AD.ps1 + +For copying the managed disks without downtime across subscription in same AAD. +https://github.com/Brucius/PowerShell-for-Partners/blob/master/Azure/copyMDNoDowntime From c3e2357479888e46a941023a2356832cf1b6f02c Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 25 Sep 2018 10:25:57 +0800 Subject: [PATCH 02/32] Create addMarketPlaceTermstoVM --- addMarketPlaceTermstoVM | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 addMarketPlaceTermstoVM diff --git a/addMarketPlaceTermstoVM b/addMarketPlaceTermstoVM new file mode 100644 index 0000000..0bf2544 --- /dev/null +++ b/addMarketPlaceTermstoVM @@ -0,0 +1,16 @@ +$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" + +Set-AzureRmMarketplaceTerms -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" -Terms $agreementTerms -Accept +$nic = Get-AzureRmNetworkInterface -Name $nicName ` + -ResourceGroupName $destinationResourceGroup + + +$vmConfig = New-AzureRmVMConfig -VMName "AZUDMZSVNETPA02" -VMSize $vmSize -Zone "2" + +$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id + +$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType Standard_LRS ` + -DiskSizeInGB 128 -CreateOption Attach -Linux +$vm = Set-AzureRmVMPlan -VM $vm -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" + +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm From 23214bfff111427cf9a8be85f0e35a467ad45f9c Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 25 Sep 2018 10:29:00 +0800 Subject: [PATCH 03/32] Create moveDisktoAZ.ps1 --- Azure/moveDisktoAZ.ps1 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Azure/moveDisktoAZ.ps1 diff --git a/Azure/moveDisktoAZ.ps1 b/Azure/moveDisktoAZ.ps1 new file mode 100644 index 0000000..af49c07 --- /dev/null +++ b/Azure/moveDisktoAZ.ps1 @@ -0,0 +1,32 @@ +#commented lines are variables to be changed according to your needs +$managedDiskName = 'sourceDisk' #name of disk +$Zone = "1" #option of zone 1,2,3 + +$sourceResourceGroupName = 'sourceRG' + +$newDiskName = "$managedDiskName-AZ" +$snapshotName = "$newDiskName-temp" +$resourceGroupName = $sourceResourceGroupName +$targetResourceGroupName = $resourceGroupName +$location = 'region' #option for region + +$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName ` + -DiskName $managedDiskName + +$snapshotConfig = New-AzureRmSnapshotConfig ` + -SourceUri $disk.Id ` + -CreateOption Copy ` + -Location $location ` + +$snapShot = New-AzureRmSnapshot ` + -Snapshot $snapshotConfig ` + -SnapshotName $snapshotName ` + -ResourceGroupName $resourceGroupName + +$DataDisk = New-AzureRmDisk -DiskName $newDiskName -Disk ` + (New-AzureRmDiskConfig -Location $location -CreateOption Copy ` + -SourceResourceId $snapshot.Id ` + -Zone $zone) ` + -ResourceGroupName $resourceGroupName + +$managedDiskName From af505794f041d2a3813675ede6a9955deabd103c Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 25 Sep 2018 10:30:53 +0800 Subject: [PATCH 04/32] Update and rename copyMDNoDowntime to copyMDNoDowntime.ps1 --- Azure/{copyMDNoDowntime => copyMDNoDowntime.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Azure/{copyMDNoDowntime => copyMDNoDowntime.ps1} (100%) diff --git a/Azure/copyMDNoDowntime b/Azure/copyMDNoDowntime.ps1 similarity index 100% rename from Azure/copyMDNoDowntime rename to Azure/copyMDNoDowntime.ps1 From 560c07447d78f096e2dda94ad1bf26891993ce20 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 25 Sep 2018 18:21:11 +0800 Subject: [PATCH 05/32] Create cloneNSGsAcrossSub.ps1 --- Azure/cloneNSGsAcrossSub.ps1 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Azure/cloneNSGsAcrossSub.ps1 diff --git a/Azure/cloneNSGsAcrossSub.ps1 b/Azure/cloneNSGsAcrossSub.ps1 new file mode 100644 index 0000000..cb2b335 --- /dev/null +++ b/Azure/cloneNSGsAcrossSub.ps1 @@ -0,0 +1,36 @@ +#This script is adapted from https://gallery.technet.microsoft.com/scriptcenter/Azure-Clone-an-Network-84ea5fa3 +#Repurposed to clone the NSGs with multiple rules across subscription within the same AAD + +#name of NSG that you want to copy from source subscription +$sourceSubscriptionId = "sourceSubID" +$nsgOrigin = "sourceNSG" +#select source subscription +Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId + +#name new NSG +$nsgDestination = "targetNSG" +#Resource Group Name of source NSG +$rgName = "nsgsource" + +$nsg = Get-AzureRmNetworkSecurityGroup -Name $nsgOrigin -ResourceGroupName $rgName +$nsgRules = Get-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $nsg +$targetSubscriptionId="targetSubID" + +Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +#Resource Group Name when you want the new NSG placed +$rgNameDest = "nsgTarget" + +$newNsg = Get-AzureRmNetworkSecurityGroup -name $nsgDestination -ResourceGroupName $rgNameDest +foreach ($nsgRule in $nsgRules) { + Add-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $newNsg ` + -Name $nsgRule.Name ` + -Protocol $nsgRule.Protocol ` + -SourcePortRange $nsgRule.SourcePortRange ` + -DestinationPortRange $nsgRule.DestinationPortRange ` + -SourceAddressPrefix $nsgRule.SourceAddressPrefix ` + -DestinationAddressPrefix $nsgRule.DestinationAddressPrefix ` + -Priority $nsgRule.Priority ` + -Direction $nsgRule.Direction ` + -Access $nsgRule.Access +} +Set-AzureRmNetworkSecurityGroup -NetworkSecurityGroup $newNsg From fee7086458e0589ad3fb006eaa4e9051e5e5c168 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Sun, 11 Nov 2018 01:26:25 +0800 Subject: [PATCH 06/32] Create marketPlaceWithAvailabilityZones --- Azure/marketPlaceWithAvailabilityZones | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Azure/marketPlaceWithAvailabilityZones diff --git a/Azure/marketPlaceWithAvailabilityZones b/Azure/marketPlaceWithAvailabilityZones new file mode 100644 index 0000000..95631fc --- /dev/null +++ b/Azure/marketPlaceWithAvailabilityZones @@ -0,0 +1,64 @@ +<# This is for machines using marketplace Images that needs to be deployed +into availabilit zones. Deploy the machine first and get the error message +of failing due to marketplace terms then run this script #> + +$targetSubscriptionId='targetsubID' +Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +$vmName = 'vmName' +$resourceGroupName = 'rgName' +$Zone = "1" +$nicName = "nicName" +$vmSize = "Standard_E4_v3" + +$location = 'francecentral' +$snapshotName = "$vmName-temp" +$osDiskName = "$vmName-OS-Disk" + +$vm = Get-AzureRmVM -Name $vmName ` + -ResourceGroupName $resourceGroupName + +$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName ` + -DiskName $vm.StorageProfile.OsDisk.Name + +$snapshotConfig = New-AzureRmSnapshotConfig ` + -SourceUri $disk.Id ` + -OsType Linux ` + -CreateOption Copy ` + -Location $location + +$snapShot = New-AzureRmSnapshot ` + -Snapshot $snapshotConfig ` + -SnapshotName $snapshotName ` + -ResourceGroupName $resourceGroupName + +$destinationResourceGroup = $resourceGroupName + +$osDisk = New-AzureRmDisk -DiskName "$osDiskName" -Disk ` + (New-AzureRmDiskConfig -Location $location -CreateOption Copy ` + -SourceResourceId $snapshot.Id ` + -Zone "$Zone") ` + -ResourceGroupName $destinationResourceGroup + +Remove-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName + + +$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" + +Set-AzureRmMarketplaceTerms -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" -Terms $agreementTerms -Accept +$nic = Get-AzureRmNetworkInterface -Name $nicName ` + -ResourceGroupName $destinationResourceGroup + + +$vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize -Zone "$Zone" + +$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id + +$vm = Set-AzureRmVMOSDisk -VM $vm ` + -ManagedDiskId $osDisk.Id ` + -StorageAccountType Standard_LRS ` + -DiskSizeInGB 38 ` + -CreateOption Attach -Linux +$vm = Set-AzureRmVMPlan -VM $vm -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" + + +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm From 639800ef80b2a5c8d728a124447d7ed1d6777f8a Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 28 Nov 2018 17:39:17 +0800 Subject: [PATCH 07/32] Update copyMDNoDowntime.ps1 --- Azure/copyMDNoDowntime.ps1 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Azure/copyMDNoDowntime.ps1 b/Azure/copyMDNoDowntime.ps1 index a444ed5..4a32a2a 100644 --- a/Azure/copyMDNoDowntime.ps1 +++ b/Azure/copyMDNoDowntime.ps1 @@ -1,10 +1,17 @@ -$sourceSubscriptionId='SourceID' -$sourceResourceGroupName='SourceRG' -$managedDiskName='SourceOSDISK' -Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId -$managedDisk= Get-AzureRMDisk -ResourceGroupName $sourceResourceGroupName -DiskName $managedDiskName -$targetSubscriptionId='TargetID' -$targetResourceGroupName='TargetRG' -Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +### SOURCE DETAILS +$SourceSubId = 'SourceID' +$SourceRGName = 'SourceRG' +$SourceDiskName = 'SourceOSDISK' + +### TARGET DETAILS +$TargetSubId = 'TargetID' +$TargetRGName = 'TargetRG' + +### Select Source Context +Select-AzureRmSubscription -SubscriptionId $SourceSubId +$managedDisk= Get-AzureRMDisk -ResourceGroupName $SourceRGName -DiskName $SourceDiskName + +### Select Target Context +Select-AzureRmSubscription -SubscriptionId $TargetSubId $diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy -New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $targetResourceGroupName +New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $TargetRGName From 67491d33e7f21f75baf373a0bc64177d725390c5 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Fri, 7 Dec 2018 15:22:42 +0800 Subject: [PATCH 08/32] Update copyMDNoDowntime.ps1 --- Azure/copyMDNoDowntime.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Azure/copyMDNoDowntime.ps1 b/Azure/copyMDNoDowntime.ps1 index 4a32a2a..9b02c87 100644 --- a/Azure/copyMDNoDowntime.ps1 +++ b/Azure/copyMDNoDowntime.ps1 @@ -14,4 +14,4 @@ $managedDisk= Get-AzureRMDisk -ResourceGroupName $SourceRGName -DiskName $Source ### Select Target Context Select-AzureRmSubscription -SubscriptionId $TargetSubId $diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy -New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $TargetRGName +New-AzureRmDisk -Disk $diskConfig -DiskName $SourceDiskName -ResourceGroupName $TargetRGName From c53d80a4597f44e2a7934a560ec58d334df9661a Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 9 Jan 2019 09:58:10 +0800 Subject: [PATCH 09/32] refactor --- Azure/cloneNSGsAcrossSub.ps1 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Azure/cloneNSGsAcrossSub.ps1 b/Azure/cloneNSGsAcrossSub.ps1 index cb2b335..df81e5a 100644 --- a/Azure/cloneNSGsAcrossSub.ps1 +++ b/Azure/cloneNSGsAcrossSub.ps1 @@ -1,26 +1,25 @@ #This script is adapted from https://gallery.technet.microsoft.com/scriptcenter/Azure-Clone-an-Network-84ea5fa3 #Repurposed to clone the NSGs with multiple rules across subscription within the same AAD -#name of NSG that you want to copy from source subscription -$sourceSubscriptionId = "sourceSubID" +$sourceSubscriptionId = "sourceSubId" +$sourceTenantId = "sourceTenantId" $nsgOrigin = "sourceNSG" -#select source subscription -Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId +$rgName = "sourceRG" #Resource Group Name of source NSG -#name new NSG -$nsgDestination = "targetNSG" -#Resource Group Name of source NSG -$rgName = "nsgsource" +$targetSubscriptionId="targetSubId" +$targetTenantId = "targetTenantId" +$nsgDestination = "targetNSG" #name new NSG. Must create in target subscription first +$rgNameDest = "targetRG" #Resource Group Name when you want the new NSG placed +#select source subscription and get rules +Set-AzureRmContext -SubscriptionId $sourceSubscriptionId -TenantId $sourceTenantId $nsg = Get-AzureRmNetworkSecurityGroup -Name $nsgOrigin -ResourceGroupName $rgName $nsgRules = Get-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $nsg -$targetSubscriptionId="targetSubID" -Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId -#Resource Group Name when you want the new NSG placed -$rgNameDest = "nsgTarget" +Set-AzureRmContext -SubscriptionId $targetSubscriptionId -TenantId $targetTenantId -$newNsg = Get-AzureRmNetworkSecurityGroup -name $nsgDestination -ResourceGroupName $rgNameDest + +$newNsg = Get-AzureRmNetworkSecurityGroup -name $nsgDestination -ResourceGroupName $rgNameDest foreach ($nsgRule in $nsgRules) { Add-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $newNsg ` -Name $nsgRule.Name ` From 913eba2017a3424c3e4315db291517aca07d068a Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 9 Jan 2019 09:58:38 +0800 Subject: [PATCH 10/32] Update cloneNSGsAcrossSub.ps1 --- Azure/cloneNSGsAcrossSub.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Azure/cloneNSGsAcrossSub.ps1 b/Azure/cloneNSGsAcrossSub.ps1 index df81e5a..be4fac2 100644 --- a/Azure/cloneNSGsAcrossSub.ps1 +++ b/Azure/cloneNSGsAcrossSub.ps1 @@ -18,7 +18,6 @@ $nsgRules = Get-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $nsg Set-AzureRmContext -SubscriptionId $targetSubscriptionId -TenantId $targetTenantId - $newNsg = Get-AzureRmNetworkSecurityGroup -name $nsgDestination -ResourceGroupName $rgNameDest foreach ($nsgRule in $nsgRules) { Add-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $newNsg ` From 105f716a08763ac89b29e49352a37446667858b9 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 13 Feb 2019 16:38:21 +0800 Subject: [PATCH 11/32] Update marketPlaceWithAvailabilityZones --- Azure/marketPlaceWithAvailabilityZones | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Azure/marketPlaceWithAvailabilityZones b/Azure/marketPlaceWithAvailabilityZones index 95631fc..bb6ca43 100644 --- a/Azure/marketPlaceWithAvailabilityZones +++ b/Azure/marketPlaceWithAvailabilityZones @@ -42,23 +42,21 @@ $osDisk = New-AzureRmDisk -DiskName "$osDiskName" -Disk ` Remove-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName -$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" +$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" -Set-AzureRmMarketplaceTerms -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" -Terms $agreementTerms -Accept +Set-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" -Terms $agreementTerms -Accept $nic = Get-AzureRmNetworkInterface -Name $nicName ` -ResourceGroupName $destinationResourceGroup - -$vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize -Zone "$Zone" +$vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize $vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id $vm = Set-AzureRmVMOSDisk -VM $vm ` -ManagedDiskId $osDisk.Id ` -StorageAccountType Standard_LRS ` - -DiskSizeInGB 38 ` + -DiskSizeInGB 100 ` -CreateOption Attach -Linux -$vm = Set-AzureRmVMPlan -VM $vm -Publisher "riverbed" -Product "riverbed-steelhead-9-6-0" -Name "riverbed-steelhead-9-6-0" - +$vm = Set-AzureRmVMPlan -VM $vm -Publisher "publisherName" -Product "offerName" -Name "skuName" New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm From e62ca553d16be9e10d86001aa5d7fdbbed94bba3 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 13 Feb 2019 16:38:34 +0800 Subject: [PATCH 12/32] Update marketPlaceWithAvailabilityZones --- Azure/marketPlaceWithAvailabilityZones | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Azure/marketPlaceWithAvailabilityZones b/Azure/marketPlaceWithAvailabilityZones index bb6ca43..04cc1c6 100644 --- a/Azure/marketPlaceWithAvailabilityZones +++ b/Azure/marketPlaceWithAvailabilityZones @@ -1,5 +1,5 @@ <# This is for machines using marketplace Images that needs to be deployed -into availabilit zones. Deploy the machine first and get the error message +into availability zones. Deploy the machine first and get the error message of failing due to marketplace terms then run this script #> $targetSubscriptionId='targetsubID' From 6247865689d01a86bea95e8bfe29cf52610fdbef Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 13 Feb 2019 17:53:15 +0800 Subject: [PATCH 13/32] Update marketPlaceWithAvailabilityZones --- Azure/marketPlaceWithAvailabilityZones | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Azure/marketPlaceWithAvailabilityZones b/Azure/marketPlaceWithAvailabilityZones index 04cc1c6..3caa6ad 100644 --- a/Azure/marketPlaceWithAvailabilityZones +++ b/Azure/marketPlaceWithAvailabilityZones @@ -1,6 +1,17 @@ <# This is for machines using marketplace Images that needs to be deployed into availability zones. Deploy the machine first and get the error message -of failing due to marketplace terms then run this script #> +of failing due to marketplace terms then run this script. + +Reference Marketplace Source file +"storageProfile": { + "imageReference": { + "publisher": "checkpoint", + "offer": "check-point-vsec-r80", + "sku": "sg-byol", + "version": "latest" + } +} +#> $targetSubscriptionId='targetsubID' Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId From 526100883e97ed18386417109005b98a91150d7c Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 26 Feb 2019 13:19:37 +0800 Subject: [PATCH 14/32] Create checkMarketPlaceImage --- Azure/checkMarketPlaceImage | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Azure/checkMarketPlaceImage diff --git a/Azure/checkMarketPlaceImage b/Azure/checkMarketPlaceImage new file mode 100644 index 0000000..7efbe8d --- /dev/null +++ b/Azure/checkMarketPlaceImage @@ -0,0 +1,26 @@ +$locname=Get-AzureRmLocation | ` +select displayname | ` +Out-GridView -PassThru -Title "Choose a location" + +$pubname=Get-AzureRmVMImagePublisher ` +-Location $locname.DisplayName | ` +Out-GridView -PassThru -Title "Choose a publisher" + +$offername = Get-AzureRmVMImageOffer ` +-Location $locname.DisplayName ` +-PublisherName $pubname.PublisherName | ` +Out-GridView -PassThru -Title "Choose an offer" + +$title="SKUs for location: " + ` +$locname.DisplayName + ` +", Publisher: " + ` +$pubname.PublisherName + ` +", Offer: " + ` +$offername.Offer + +Get-AzureRmVMImageSku ` +-Location $locname.DisplayName ` +-PublisherName $pubname.PublisherName ` +-Offer $offername.Offer | ` +select SKUS | ` +Out-GridView -Title $title From 74135d82d0ea38771b1712b288960a085d4e0cdc Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Tue, 26 Feb 2019 13:20:13 +0800 Subject: [PATCH 15/32] Update checkMarketPlaceImage --- Azure/checkMarketPlaceImage | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Azure/checkMarketPlaceImage b/Azure/checkMarketPlaceImage index 7efbe8d..523b53a 100644 --- a/Azure/checkMarketPlaceImage +++ b/Azure/checkMarketPlaceImage @@ -1,3 +1,5 @@ +##From 4sysop + $locname=Get-AzureRmLocation | ` select displayname | ` Out-GridView -PassThru -Title "Choose a location" From d4da3d7bbd3a86c8bea0dc152b002063256b291d Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Wed, 20 Mar 2019 13:42:17 +0800 Subject: [PATCH 16/32] Create createBlobSAS.ps1 --- Azure/createBlobSAS.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Azure/createBlobSAS.ps1 diff --git a/Azure/createBlobSAS.ps1 b/Azure/createBlobSAS.ps1 new file mode 100644 index 0000000..859e2dd --- /dev/null +++ b/Azure/createBlobSAS.ps1 @@ -0,0 +1,25 @@ +#This script allows you to create an SAS policy on your existing storage account and lets you grab SAS key. +#Useful for this tutorial https://docs.microsoft.com/en-us/sql/relational-databases/tutorial-use-azure-blob-storage-service-with-sql-server-2016?view=sql-server-2017 +#SQL Server backing up to Azure Blob Storage + +#Defining Variables +$storageAccountName = "" +$resourceGroupName = "" +$containerName = "" +$policyName = "" + "policy" + +# Get the access keys for the Azure Resource Manager storage account +$accountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName + +# Create a new storage account context using an Azure Resource Manager storage account +$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $accountKeys[0].Value + +# Creates a new container in blob storage +$container = Get-AzureStorageContainer -Context $storageContext -Name $containerName + +# Sets up a Stored Access Policy and a Shared Access Signature for the new container +$policy = New-AzureStorageContainerStoredAccessPolicy -Container $containerName -Policy $policyName -Context $storageContext -StartTime $(Get-Date).ToUniversalTime().AddMinutes(-5) -ExpiryTime $(Get-Date).ToUniversalTime().AddYears(10) -Permission rwld + +# Gets the Shared Access Signature for the policy +$sas = New-AzureStorageContainerSASToken -name $containerName -Policy $policyName -Context $storageContext +Write-Host 'Shared Access Signature= '$($sas.Substring(1))'' From ebfcac05f54377ada971af7cbd56a5883d917edf Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Thu, 23 May 2019 22:56:14 +0800 Subject: [PATCH 17/32] Update InstallUpdateAzureRM&AD.ps1 --- Azure/Basics/InstallUpdateAzureRM&AD.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Azure/Basics/InstallUpdateAzureRM&AD.ps1 b/Azure/Basics/InstallUpdateAzureRM&AD.ps1 index 24e8134..b8db9ce 100644 --- a/Azure/Basics/InstallUpdateAzureRM&AD.ps1 +++ b/Azure/Basics/InstallUpdateAzureRM&AD.ps1 @@ -5,7 +5,7 @@ Install-Module -Name MSOnline ##Import Office 365 and Azure AD module Import-Module -Name MSOnline -#Check Existing AzureRM module +#Check Existing Powershell Version $PSVersionTable.PSVersion From 7232966e93da90a0933f08c0cd93bd661b56e3c3 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Fri, 26 Jul 2019 13:15:17 +0800 Subject: [PATCH 18/32] Directory Changes --- .../Scheduling-VMs/Turn off and on.ps1 | 86 ------------------- .../Azure-Automation/Scheduling-VMs/readme.md | 1 - .../AzureExpressRouteSetUDR.ps1 | 0 .../AzureRMCopyVHDManagedDisksfromMS.ps1 | 0 .../AzureRMInventorywithTags.ps1 | 0 .../Convert VHD to Fixed.ps1 | 0 ...tusLoopCopyManagedDisktoStorageAccount.ps1 | 0 .../addMarketPlaceTermstoVM.ps1 | 0 Azure/{azcopy => AzureRmTemplates/azcopy.ps1} | 0 .../checkMarketPlaceImage.ps1} | 0 .../cloneNSGsAcrossSub.ps1 | 0 .../copyMDNoDowntime.ps1 | 0 .../{ => AzureRmTemplates}/createBlobSAS.ps1 | 0 .../marketPlaceWithAvailabilityZones.ps1} | 0 Azure/{ => AzureRmTemplates}/moveDisktoAZ.ps1 | 0 Azure/{ => AzureRmTemplates}/readme.md | 0 .../Bulk MX Lookup.ps1 | 0 17 files changed, 87 deletions(-) delete mode 100644 Azure/Azure-Automation/Scheduling-VMs/Turn off and on.ps1 delete mode 100644 Azure/Azure-Automation/Scheduling-VMs/readme.md rename Azure/{ => AzureRmTemplates}/AzureExpressRouteSetUDR.ps1 (100%) rename Azure/{ => AzureRmTemplates}/AzureRMCopyVHDManagedDisksfromMS.ps1 (100%) rename Azure/{ => AzureRmTemplates}/AzureRMInventorywithTags.ps1 (100%) rename Azure/{ => AzureRmTemplates}/Convert VHD to Fixed.ps1 (100%) rename Azure/{ => AzureRmTemplates}/StatusLoopCopyManagedDisktoStorageAccount.ps1 (100%) rename addMarketPlaceTermstoVM => Azure/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 (100%) rename Azure/{azcopy => AzureRmTemplates/azcopy.ps1} (100%) rename Azure/{checkMarketPlaceImage => AzureRmTemplates/checkMarketPlaceImage.ps1} (100%) rename Azure/{ => AzureRmTemplates}/cloneNSGsAcrossSub.ps1 (100%) rename Azure/{ => AzureRmTemplates}/copyMDNoDowntime.ps1 (100%) rename Azure/{ => AzureRmTemplates}/createBlobSAS.ps1 (100%) rename Azure/{marketPlaceWithAvailabilityZones => AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1} (100%) rename Azure/{ => AzureRmTemplates}/moveDisktoAZ.ps1 (100%) rename Azure/{ => AzureRmTemplates}/readme.md (100%) rename Bulk MX Lookup.ps1 => Office-365/Bulk MX Lookup.ps1 (100%) diff --git a/Azure/Azure-Automation/Scheduling-VMs/Turn off and on.ps1 b/Azure/Azure-Automation/Scheduling-VMs/Turn off and on.ps1 deleted file mode 100644 index 4d167e5..0000000 --- a/Azure/Azure-Automation/Scheduling-VMs/Turn off and on.ps1 +++ /dev/null @@ -1,86 +0,0 @@ -## Place holder for VM scheduling -Param( - $AutomationRG = "ResourceGroup", - $AutomationAcct = "Automation Account", - $StartType = "Auto" -) - - -$connectionName = "AzureRunAsConnection" -try -{ - # Get the connection "AzureRunAsConnection " - $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName - - "Logging in to Azure..." - Add-AzureRmAccount ` - -ServicePrincipal ` - -TenantId $servicePrincipalConnection.TenantId ` - -ApplicationId $servicePrincipalConnection.ApplicationId ` - -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint -} -catch { - if (!$servicePrincipalConnection) - { - $ErrorMessage = "Connection $connectionName not found." - throw $ErrorMessage - } else{ - Write-Error -Message $_.Exception - throw $_.Exception - } -} - -function Get-AzureRmVMStatus { - [CmdletBinding()] - param ( - #The name of a resouce group in your subscription - [Parameter(Mandatory=$true)] - [string] - $ResourceGroupName - , - #VM name filter - [Parameter()] - [string] - $Name = '*' - ) - Get-AzureRmVM -ResourceGroupName $ResourceGroupName | ? {$_.Tags.Keys -eq "Start" -and $_.Tags.Values -eq "$StartType"} | - Get-AzureRmVM -Status | - Select-Object -Property Name, Statuses, ResourceGroupName | - Where-Object {$_.Name -like $Name} | - ForEach-Object { - $VMName = $_.Name - $ResourceGroupName = $_.ResourceGroupName - $_.Statuses | - Where-Object {$_.Code -like 'PowerState/*'} | - ForEach-Object { - New-Object -TypeName psobject -Property @{ - Name = $VMName - ResourceGroupName = $ResourceGroupName - Status = $_.DisplayStatus - } - } - } -} - -$subs = Get-AzureRmSubscription -WarningAction SilentlyContinue - -$subs | % {Select-AzureRmSubscription -SubscriptionId $_.SubscriptionId -$VMs = Get-AzureRmResourceGroup | % {Get-AzureRmVMStatus $_.ResourceGroupName} - -$ASVMs = $VMs | ? {$_.Status -eq "VM deallocated"} - -Foreach ($ASVM in $ASVMs) - { - $params = @{"Name"=$ASVM.name;"ResourceGroupName"=$ASVM.ResourceGroupName} - $msg = "Starting VM " - $msg += $ASVM.name - $msg += " on resouregroup " - $msg += $ASVM.ResourceGroupName - $msg += "......" - Write-Output " " - Write-Output $msg - Write-Output " " - Start-AzureRmAutomationRunbook -AutomationAccountName $AutomationAcct -Name "StartVM" -Parameters $params -ResourceGroupName $AutomationRG - } -} -## Turn machines on and off based on tagging diff --git a/Azure/Azure-Automation/Scheduling-VMs/readme.md b/Azure/Azure-Automation/Scheduling-VMs/readme.md deleted file mode 100644 index 188e3ab..0000000 --- a/Azure/Azure-Automation/Scheduling-VMs/readme.md +++ /dev/null @@ -1 +0,0 @@ -Boring instructions go here diff --git a/Azure/AzureExpressRouteSetUDR.ps1 b/Azure/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 similarity index 100% rename from Azure/AzureExpressRouteSetUDR.ps1 rename to Azure/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 diff --git a/Azure/AzureRMCopyVHDManagedDisksfromMS.ps1 b/Azure/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 similarity index 100% rename from Azure/AzureRMCopyVHDManagedDisksfromMS.ps1 rename to Azure/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 diff --git a/Azure/AzureRMInventorywithTags.ps1 b/Azure/AzureRmTemplates/AzureRMInventorywithTags.ps1 similarity index 100% rename from Azure/AzureRMInventorywithTags.ps1 rename to Azure/AzureRmTemplates/AzureRMInventorywithTags.ps1 diff --git a/Azure/Convert VHD to Fixed.ps1 b/Azure/AzureRmTemplates/Convert VHD to Fixed.ps1 similarity index 100% rename from Azure/Convert VHD to Fixed.ps1 rename to Azure/AzureRmTemplates/Convert VHD to Fixed.ps1 diff --git a/Azure/StatusLoopCopyManagedDisktoStorageAccount.ps1 b/Azure/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 similarity index 100% rename from Azure/StatusLoopCopyManagedDisktoStorageAccount.ps1 rename to Azure/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 diff --git a/addMarketPlaceTermstoVM b/Azure/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 similarity index 100% rename from addMarketPlaceTermstoVM rename to Azure/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 diff --git a/Azure/azcopy b/Azure/AzureRmTemplates/azcopy.ps1 similarity index 100% rename from Azure/azcopy rename to Azure/AzureRmTemplates/azcopy.ps1 diff --git a/Azure/checkMarketPlaceImage b/Azure/AzureRmTemplates/checkMarketPlaceImage.ps1 similarity index 100% rename from Azure/checkMarketPlaceImage rename to Azure/AzureRmTemplates/checkMarketPlaceImage.ps1 diff --git a/Azure/cloneNSGsAcrossSub.ps1 b/Azure/AzureRmTemplates/cloneNSGsAcrossSub.ps1 similarity index 100% rename from Azure/cloneNSGsAcrossSub.ps1 rename to Azure/AzureRmTemplates/cloneNSGsAcrossSub.ps1 diff --git a/Azure/copyMDNoDowntime.ps1 b/Azure/AzureRmTemplates/copyMDNoDowntime.ps1 similarity index 100% rename from Azure/copyMDNoDowntime.ps1 rename to Azure/AzureRmTemplates/copyMDNoDowntime.ps1 diff --git a/Azure/createBlobSAS.ps1 b/Azure/AzureRmTemplates/createBlobSAS.ps1 similarity index 100% rename from Azure/createBlobSAS.ps1 rename to Azure/AzureRmTemplates/createBlobSAS.ps1 diff --git a/Azure/marketPlaceWithAvailabilityZones b/Azure/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 similarity index 100% rename from Azure/marketPlaceWithAvailabilityZones rename to Azure/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 diff --git a/Azure/moveDisktoAZ.ps1 b/Azure/AzureRmTemplates/moveDisktoAZ.ps1 similarity index 100% rename from Azure/moveDisktoAZ.ps1 rename to Azure/AzureRmTemplates/moveDisktoAZ.ps1 diff --git a/Azure/readme.md b/Azure/AzureRmTemplates/readme.md similarity index 100% rename from Azure/readme.md rename to Azure/AzureRmTemplates/readme.md diff --git a/Bulk MX Lookup.ps1 b/Office-365/Bulk MX Lookup.ps1 similarity index 100% rename from Bulk MX Lookup.ps1 rename to Office-365/Bulk MX Lookup.ps1 From 0a3bf1e4e524bfd50fde584949e4cf76eda8a869 Mon Sep 17 00:00:00 2001 From: Oaker Min Date: Fri, 26 Jul 2019 13:44:32 +0800 Subject: [PATCH 19/32] azure install updates --- Azure/Basics/InstallUpdateAzureRM&AD.ps1 | 35 ------------------------ Azure/Basics/readme.md | 32 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 36 deletions(-) delete mode 100644 Azure/Basics/InstallUpdateAzureRM&AD.ps1 diff --git a/Azure/Basics/InstallUpdateAzureRM&AD.ps1 b/Azure/Basics/InstallUpdateAzureRM&AD.ps1 deleted file mode 100644 index b8db9ce..0000000 --- a/Azure/Basics/InstallUpdateAzureRM&AD.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -##Run POSH Terminal as Administrator - -#Install MSOnline PowerShell for Azure Active Directory (V1) -Install-Module -Name MSOnline -##Import Office 365 and Azure AD module -Import-Module -Name MSOnline - -#Check Existing Powershell Version -$PSVersionTable.PSVersion - - -#Install AzureRM module -Install-Module -Name AzureRM - -#Import AzureRM module -Import-Module -Name AzureRM - -#Update Azure RM module to latest -Update-Module -Name AzureRM -Install-Module -Name AzureRM -Repository PSGallery -Force - -#Import SharePoint Online module -Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking - -#Import Skype for Busines Online module -Import-Module SkypeOnlineConnector - -#Import Azure classic module -#Only used with legacy deployments, not relevant to Azure CSP -Install-Module Azure - - - -#For any updates, please refer to www.powershellgallery.com -#By Oaker Min (Bruce) Partner Enablement Specialist at rhipe. diff --git a/Azure/Basics/readme.md b/Azure/Basics/readme.md index 94af846..c3026d5 100644 --- a/Azure/Basics/readme.md +++ b/Azure/Basics/readme.md @@ -1 +1,31 @@ -Installing Modules and Selecting subscription as Partner +# Basics and Pre-requisites to run these scripts +Below modules are in the order of my personal preference. Currently the new Az modules do not work well with existing MsOnline modules. + +## To Install AzureRM module +``` +Install-Module -Name AzureRM +Import-Module -Name AzureRM +``` +## To Update AzureRm module to latest +```Update-Module -Name AzureRM``` + +## Install MSOnline PowerShell for Azure Active Directory (V1) +```Install-Module -Name MSOnline``` +Import Office 365 and Azure AD module +```Import-Module -Name MSOnline``` + + +## To Uninstall all AzureRM module +``` +$versions = (Get-InstalledModule AzureRM -AllVersions | Select-Object Version) +$versions | foreach { Uninstall-AllModules -TargetModule AzureRM -Version ($_.Version) -Force } +Get-Module -ListAvailable | Where-Object { $_.Name -like 'AzureRM*' } | Uninstall-Module +``` +## To Uninstall all Azure +```Get-Module -ListAvailable | Where-Object { $_.Name -like 'Azure*' } | Uninstall-Module``` + +## To Install the new Az module based on .Net Core. +Only install this module after uninstalling the Rm modules. +```Install-Module -Name Az``` +## To Update the module +```Install-Module -Name Az -AllowClobber -Force``` \ No newline at end of file From 66c8d61019c19b1a9f2ba6d06987656b36958f36 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 13:56:42 +0800 Subject: [PATCH 20/32] Another Directory change --- Azure/AzureRmTemplates/readme.md | 7 ------- AzureAzTemplates/readme.md | 14 ++++++++++++++ .../AzureExpressRouteSetUDR.ps1 | 0 .../AzureRMCopyVHDManagedDisksfromMS.ps1 | 0 .../AzureRMInventorywithTags.ps1 | 0 .../Convert VHD to Fixed.ps1 | 0 .../StatusLoopCopyManagedDisktoStorageAccount.ps1 | 0 .../addMarketPlaceTermstoVM.ps1 | 0 .../azcopy.ps1 | 0 .../checkMarketPlaceImage.ps1 | 0 .../cloneNSGsAcrossSub.ps1 | 0 .../copyMDNoDowntime.ps1 | 0 .../createBlobSAS.ps1 | 0 .../marketPlaceWithAvailabilityZones.ps1 | 0 .../moveDisktoAZ.ps1 | 0 .../p01_Select_Subscription.ps1 | 0 {Azure/Basics => AzureRmTemplates}/readme.md | 12 +++--------- 17 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 Azure/AzureRmTemplates/readme.md create mode 100644 AzureAzTemplates/readme.md rename {Azure/AzureRmTemplates => AzureRmTemplates}/AzureExpressRouteSetUDR.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/AzureRMCopyVHDManagedDisksfromMS.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/AzureRMInventorywithTags.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/Convert VHD to Fixed.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/StatusLoopCopyManagedDisktoStorageAccount.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/addMarketPlaceTermstoVM.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/azcopy.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/checkMarketPlaceImage.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/cloneNSGsAcrossSub.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/copyMDNoDowntime.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/createBlobSAS.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/marketPlaceWithAvailabilityZones.ps1 (100%) rename {Azure/AzureRmTemplates => AzureRmTemplates}/moveDisktoAZ.ps1 (100%) rename Azure/Basics/Select Subscription.ps1 => AzureRmTemplates/p01_Select_Subscription.ps1 (100%) rename {Azure/Basics => AzureRmTemplates}/readme.md (67%) diff --git a/Azure/AzureRmTemplates/readme.md b/Azure/AzureRmTemplates/readme.md deleted file mode 100644 index 30a427e..0000000 --- a/Azure/AzureRmTemplates/readme.md +++ /dev/null @@ -1,7 +0,0 @@ -# Pre-requisites for using the scripts. - -Install Azure RM modules as per this script. -https://github.com/Brucius/PowerShell-for-Partners/blob/master/Azure/Basics/InstallUpdateAzureRM%26AD.ps1 - -For copying the managed disks without downtime across subscription in same AAD. -https://github.com/Brucius/PowerShell-for-Partners/blob/master/Azure/copyMDNoDowntime diff --git a/AzureAzTemplates/readme.md b/AzureAzTemplates/readme.md new file mode 100644 index 0000000..1e8c5ed --- /dev/null +++ b/AzureAzTemplates/readme.md @@ -0,0 +1,14 @@ +## To Install the new Az module based on .Net Core. +Only install this module after uninstalling the Rm modules. +To Uninstall all AzureRM module +``` +$versions = (Get-InstalledModule AzureRM -AllVersions | Select-Object Version) +$versions | foreach { Uninstall-AllModules -TargetModule AzureRM -Version ($_.Version) -Force } +Get-Module -ListAvailable | Where-Object { $_.Name -like 'AzureRM*' } | Uninstall-Module +``` +To Uninstall all Azure +```Get-Module -ListAvailable | Where-Object { $_.Name -like 'Azure*' } | Uninstall-Module``` + +## To Install and Update the module +```Install-Module -Name Az +Install-Module -Name Az -AllowClobber -Force``` \ No newline at end of file diff --git a/Azure/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 b/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 similarity index 100% rename from Azure/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 rename to AzureRmTemplates/AzureExpressRouteSetUDR.ps1 diff --git a/Azure/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 b/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 similarity index 100% rename from Azure/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 rename to AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 diff --git a/Azure/AzureRmTemplates/AzureRMInventorywithTags.ps1 b/AzureRmTemplates/AzureRMInventorywithTags.ps1 similarity index 100% rename from Azure/AzureRmTemplates/AzureRMInventorywithTags.ps1 rename to AzureRmTemplates/AzureRMInventorywithTags.ps1 diff --git a/Azure/AzureRmTemplates/Convert VHD to Fixed.ps1 b/AzureRmTemplates/Convert VHD to Fixed.ps1 similarity index 100% rename from Azure/AzureRmTemplates/Convert VHD to Fixed.ps1 rename to AzureRmTemplates/Convert VHD to Fixed.ps1 diff --git a/Azure/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 b/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 similarity index 100% rename from Azure/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 rename to AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 diff --git a/Azure/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 b/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 similarity index 100% rename from Azure/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 rename to AzureRmTemplates/addMarketPlaceTermstoVM.ps1 diff --git a/Azure/AzureRmTemplates/azcopy.ps1 b/AzureRmTemplates/azcopy.ps1 similarity index 100% rename from Azure/AzureRmTemplates/azcopy.ps1 rename to AzureRmTemplates/azcopy.ps1 diff --git a/Azure/AzureRmTemplates/checkMarketPlaceImage.ps1 b/AzureRmTemplates/checkMarketPlaceImage.ps1 similarity index 100% rename from Azure/AzureRmTemplates/checkMarketPlaceImage.ps1 rename to AzureRmTemplates/checkMarketPlaceImage.ps1 diff --git a/Azure/AzureRmTemplates/cloneNSGsAcrossSub.ps1 b/AzureRmTemplates/cloneNSGsAcrossSub.ps1 similarity index 100% rename from Azure/AzureRmTemplates/cloneNSGsAcrossSub.ps1 rename to AzureRmTemplates/cloneNSGsAcrossSub.ps1 diff --git a/Azure/AzureRmTemplates/copyMDNoDowntime.ps1 b/AzureRmTemplates/copyMDNoDowntime.ps1 similarity index 100% rename from Azure/AzureRmTemplates/copyMDNoDowntime.ps1 rename to AzureRmTemplates/copyMDNoDowntime.ps1 diff --git a/Azure/AzureRmTemplates/createBlobSAS.ps1 b/AzureRmTemplates/createBlobSAS.ps1 similarity index 100% rename from Azure/AzureRmTemplates/createBlobSAS.ps1 rename to AzureRmTemplates/createBlobSAS.ps1 diff --git a/Azure/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 b/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 similarity index 100% rename from Azure/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 rename to AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 diff --git a/Azure/AzureRmTemplates/moveDisktoAZ.ps1 b/AzureRmTemplates/moveDisktoAZ.ps1 similarity index 100% rename from Azure/AzureRmTemplates/moveDisktoAZ.ps1 rename to AzureRmTemplates/moveDisktoAZ.ps1 diff --git a/Azure/Basics/Select Subscription.ps1 b/AzureRmTemplates/p01_Select_Subscription.ps1 similarity index 100% rename from Azure/Basics/Select Subscription.ps1 rename to AzureRmTemplates/p01_Select_Subscription.ps1 diff --git a/Azure/Basics/readme.md b/AzureRmTemplates/readme.md similarity index 67% rename from Azure/Basics/readme.md rename to AzureRmTemplates/readme.md index c3026d5..27e47f8 100644 --- a/Azure/Basics/readme.md +++ b/AzureRmTemplates/readme.md @@ -1,5 +1,5 @@ # Basics and Pre-requisites to run these scripts -Below modules are in the order of my personal preference. Currently the new Az modules do not work well with existing MsOnline modules. +The below cmdlets helps you install necessary moduesl the run the scripts on your local machine. ## To Install AzureRM module ``` @@ -11,10 +11,10 @@ Import-Module -Name AzureRM ## Install MSOnline PowerShell for Azure Active Directory (V1) ```Install-Module -Name MSOnline``` + Import Office 365 and Azure AD module ```Import-Module -Name MSOnline``` - ## To Uninstall all AzureRM module ``` $versions = (Get-InstalledModule AzureRM -AllVersions | Select-Object Version) @@ -22,10 +22,4 @@ $versions | foreach { Uninstall-AllModules -TargetModule AzureRM -Version ($_.Ve Get-Module -ListAvailable | Where-Object { $_.Name -like 'AzureRM*' } | Uninstall-Module ``` ## To Uninstall all Azure -```Get-Module -ListAvailable | Where-Object { $_.Name -like 'Azure*' } | Uninstall-Module``` - -## To Install the new Az module based on .Net Core. -Only install this module after uninstalling the Rm modules. -```Install-Module -Name Az``` -## To Update the module -```Install-Module -Name Az -AllowClobber -Force``` \ No newline at end of file +```Get-Module -ListAvailable | Where-Object { $_.Name -like 'Azure*' } | Uninstall-Module``` \ No newline at end of file From f11989a5668995faae1b49b56a055ff07396f348 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:11:12 +0800 Subject: [PATCH 21/32] minor script changes --- AzureAzTemplates/readme.md | 2 +- ...> SelectSubscriptionThruPartnerCenter.ps1} | 0 AzureRmTemplates/addMarketPlaceTermstoVM.ps1 | 16 --- AzureRmTemplates/copyMDNoDowntime.ps1 | 3 +- AzureRmTemplates/marketplaceCheckNDeploy.ps1 | 107 ++++++++++++++++++ AzureRmTemplates/readme.md | 2 +- 6 files changed, 111 insertions(+), 19 deletions(-) rename AzureRmTemplates/{p01_Select_Subscription.ps1 => SelectSubscriptionThruPartnerCenter.ps1} (100%) delete mode 100644 AzureRmTemplates/addMarketPlaceTermstoVM.ps1 create mode 100644 AzureRmTemplates/marketplaceCheckNDeploy.ps1 diff --git a/AzureAzTemplates/readme.md b/AzureAzTemplates/readme.md index 1e8c5ed..7682e80 100644 --- a/AzureAzTemplates/readme.md +++ b/AzureAzTemplates/readme.md @@ -1,5 +1,5 @@ ## To Install the new Az module based on .Net Core. -Only install this module after uninstalling the Rm modules. +Only install this module after uninstalling the RM modules. To Uninstall all AzureRM module ``` $versions = (Get-InstalledModule AzureRM -AllVersions | Select-Object Version) diff --git a/AzureRmTemplates/p01_Select_Subscription.ps1 b/AzureRmTemplates/SelectSubscriptionThruPartnerCenter.ps1 similarity index 100% rename from AzureRmTemplates/p01_Select_Subscription.ps1 rename to AzureRmTemplates/SelectSubscriptionThruPartnerCenter.ps1 diff --git a/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 b/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 deleted file mode 100644 index 0bf2544..0000000 --- a/AzureRmTemplates/addMarketPlaceTermstoVM.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" - -Set-AzureRmMarketplaceTerms -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" -Terms $agreementTerms -Accept -$nic = Get-AzureRmNetworkInterface -Name $nicName ` - -ResourceGroupName $destinationResourceGroup - - -$vmConfig = New-AzureRmVMConfig -VMName "AZUDMZSVNETPA02" -VMSize $vmSize -Zone "2" - -$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id - -$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType Standard_LRS ` - -DiskSizeInGB 128 -CreateOption Attach -Linux -$vm = Set-AzureRmVMPlan -VM $vm -Publisher "paloaltonetworks" -Product "vmseries1" -Name "byol" - -New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm diff --git a/AzureRmTemplates/copyMDNoDowntime.ps1 b/AzureRmTemplates/copyMDNoDowntime.ps1 index 9b02c87..1059cb5 100644 --- a/AzureRmTemplates/copyMDNoDowntime.ps1 +++ b/AzureRmTemplates/copyMDNoDowntime.ps1 @@ -1,3 +1,4 @@ +# The following script lets you copy a managed disk across 2 subscriptions in the same tenant instantaneously. ### SOURCE DETAILS $SourceSubId = 'SourceID' $SourceRGName = 'SourceRG' @@ -14,4 +15,4 @@ $managedDisk= Get-AzureRMDisk -ResourceGroupName $SourceRGName -DiskName $Source ### Select Target Context Select-AzureRmSubscription -SubscriptionId $TargetSubId $diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy -New-AzureRmDisk -Disk $diskConfig -DiskName $SourceDiskName -ResourceGroupName $TargetRGName +New-AzureRmDisk -Disk $diskConfig -DiskName $SourceDiskName -ResourceGroupName $TargetRGName \ No newline at end of file diff --git a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 new file mode 100644 index 0000000..4d416b5 --- /dev/null +++ b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 @@ -0,0 +1,107 @@ +#This command sets the execution policy to bypass for only the current PowerShell session. +#After the window is closed, the next PowerShell session will open running with the default execution policy. +#“Bypass” means nothing is blocked and no warnings, prompts, or messages will be displayed. +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass + +# From 4sysop +$locname=Get-AzureRmLocation | ` +select displayname | ` +Out-GridView -PassThru -Title "Choose a location" + +$pubname=Get-AzureRmVMImagePublisher ` +-Location $locname.DisplayName | ` +Out-GridView -PassThru -Title "Choose a publisher" + +$offername = Get-AzureRmVMImageOffer ` +-Location $locname.DisplayName ` +-PublisherName $pubname.PublisherName | ` +Out-GridView -PassThru -Title "Choose an offer" + +$title="SKUs for location: " + ` +$locname.DisplayName + ` +", Publisher: " + ` +$pubname.PublisherName + ` +", Offer: " + ` +$offername.Offer + +Get-AzureRmVMImageSku ` +-Location $locname.DisplayName ` +-PublisherName $pubname.PublisherName ` +-Offer $offername.Offer | ` +select SKUS | ` +Out-GridView -Title $title + + + +<# This is for machines using marketplace Images that needs to be deployed +into availability zones. Deploy the machine first and get the error message +of failing due to marketplace terms then run this script. + +Reference Marketplace Source file +"storageProfile": { + "imageReference": { + "publisher": "checkpoint", + "offer": "check-point-vsec-r80", + "sku": "sg-byol", + "version": "latest" + } +} +#> +$targetSubscriptionId='targetsubID' +Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId +$vmName = 'vmName' +$resourceGroupName = 'rgName' +$Zone = "1-2-3" +$nicName = "nicName" +$vmSize = "Standard_E4_v3" + +$location = 'francecentral' +$snapshotName = "$vmName-temp" +$osDiskName = "$vmName-OS-Disk" + +$vm = Get-AzureRmVM -Name $vmName ` + -ResourceGroupName $resourceGroupName + +$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName ` + -DiskName $vm.StorageProfile.OsDisk.Name + +$snapshotConfig = New-AzureRmSnapshotConfig ` + -SourceUri $disk.Id ` + -OsType Linux ` + -CreateOption Copy ` + -Location $location + +$snapShot = New-AzureRmSnapshot ` + -Snapshot $snapshotConfig ` + -SnapshotName $snapshotName ` + -ResourceGroupName $resourceGroupName + +$destinationResourceGroup = $resourceGroupName + +$osDisk = New-AzureRmDisk -DiskName "$osDiskName" -Disk ` + (New-AzureRmDiskConfig -Location $location -CreateOption Copy ` + -SourceResourceId $snapshot.Id ` + -Zone "$Zone") ` + -ResourceGroupName $destinationResourceGroup + +Remove-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName + + +$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" + +Set-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" -Terms $agreementTerms -Accept +$nic = Get-AzureRmNetworkInterface -Name $nicName ` + -ResourceGroupName $destinationResourceGroup + +$vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize + +$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id + +$vm = Set-AzureRmVMOSDisk -VM $vm ` + -ManagedDiskId $osDisk.Id ` + -StorageAccountType Standard_LRS ` + -DiskSizeInGB 100 ` ## This can be changed according to the disk size you need + -CreateOption Attach -Linux +$vm = Set-AzureRmVMPlan -VM $vm -Publisher "publisherName" -Product "offerName" -Name "skuName" + +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm \ No newline at end of file diff --git a/AzureRmTemplates/readme.md b/AzureRmTemplates/readme.md index 27e47f8..894d2be 100644 --- a/AzureRmTemplates/readme.md +++ b/AzureRmTemplates/readme.md @@ -1,5 +1,5 @@ # Basics and Pre-requisites to run these scripts -The below cmdlets helps you install necessary moduesl the run the scripts on your local machine. +The below cmdlets helps you install necessary modules to run the scripts on your local machine. ## To Install AzureRM module ``` From a5a5f73f1e02caa9f60f779c81cf68394ce25698 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:15:11 +0800 Subject: [PATCH 22/32] updated readme --- AzureAzTemplates/readme.md | 2 +- AzureRmTemplates/marketplaceCheckNDeploy.ps1 | 2 +- AzureRmTemplates/moveDisktoAZ.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AzureAzTemplates/readme.md b/AzureAzTemplates/readme.md index 7682e80..64e1ba0 100644 --- a/AzureAzTemplates/readme.md +++ b/AzureAzTemplates/readme.md @@ -1,5 +1,5 @@ ## To Install the new Az module based on .Net Core. -Only install this module after uninstalling the RM modules. +Currently in progress of converting existing RM scripts into Az. Contributions welcome! Only install this module after uninstalling the RM modules. To Uninstall all AzureRM module ``` $versions = (Get-InstalledModule AzureRM -AllVersions | Select-Object Version) diff --git a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 index 4d416b5..5aa3bc5 100644 --- a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 +++ b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 @@ -51,7 +51,7 @@ $targetSubscriptionId='targetsubID' Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId $vmName = 'vmName' $resourceGroupName = 'rgName' -$Zone = "1-2-3" +$Zone = "1-2-3" #option of zone 1,2,3 $nicName = "nicName" $vmSize = "Standard_E4_v3" diff --git a/AzureRmTemplates/moveDisktoAZ.ps1 b/AzureRmTemplates/moveDisktoAZ.ps1 index af49c07..1ee1146 100644 --- a/AzureRmTemplates/moveDisktoAZ.ps1 +++ b/AzureRmTemplates/moveDisktoAZ.ps1 @@ -16,7 +16,7 @@ $disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName ` $snapshotConfig = New-AzureRmSnapshotConfig ` -SourceUri $disk.Id ` -CreateOption Copy ` - -Location $location ` + -Location $location ` $snapShot = New-AzureRmSnapshot ` -Snapshot $snapshotConfig ` From 2db9e3da4868f1b34ce7e35658071f31c574c6a7 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:35:15 +0800 Subject: [PATCH 23/32] update readmes --- .../VerifyDomainWithAzureDNS.ps1 | 0 Office-365/Managing-Users/Readme.md | 1 - Office-365/{ => Setup-Tenant}/Bulk MX Lookup.ps1 | 0 Office-365/readme.md | 8 ++++++++ README.md | 16 ++++++++++++---- 5 files changed, 20 insertions(+), 5 deletions(-) rename Office-365/Setup-Tenant/Verify Domain with Azure DNS.ps1 => AzureRmTemplates/VerifyDomainWithAzureDNS.ps1 (100%) delete mode 100644 Office-365/Managing-Users/Readme.md rename Office-365/{ => Setup-Tenant}/Bulk MX Lookup.ps1 (100%) create mode 100644 Office-365/readme.md diff --git a/Office-365/Setup-Tenant/Verify Domain with Azure DNS.ps1 b/AzureRmTemplates/VerifyDomainWithAzureDNS.ps1 similarity index 100% rename from Office-365/Setup-Tenant/Verify Domain with Azure DNS.ps1 rename to AzureRmTemplates/VerifyDomainWithAzureDNS.ps1 diff --git a/Office-365/Managing-Users/Readme.md b/Office-365/Managing-Users/Readme.md deleted file mode 100644 index da522b4..0000000 --- a/Office-365/Managing-Users/Readme.md +++ /dev/null @@ -1 +0,0 @@ -#Big fat instructions go here diff --git a/Office-365/Bulk MX Lookup.ps1 b/Office-365/Setup-Tenant/Bulk MX Lookup.ps1 similarity index 100% rename from Office-365/Bulk MX Lookup.ps1 rename to Office-365/Setup-Tenant/Bulk MX Lookup.ps1 diff --git a/Office-365/readme.md b/Office-365/readme.md new file mode 100644 index 0000000..2402457 --- /dev/null +++ b/Office-365/readme.md @@ -0,0 +1,8 @@ +# Basics and Pre-requisites to run these scripts +The below cmdlets helps you install necessary modules to run the scripts on your local machine. + +## Install MSOnline PowerShell for Azure Active Directory (V1) +```Install-Module -Name MSOnline``` + +Import Office 365 and Azure AD module +```Import-Module -Name MSOnline``` \ No newline at end of file diff --git a/README.md b/README.md index aaff5e6..987a95c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ # PowerShell for Microsoft Partners -PowerShell script repository for Microsoft Partners +A curated repository of useful powershell scripts for Azure Administrators from Microsoft Cloud Solution Provider (CSP) Partner Organizations. -All scripts assume you have your own Office 365 tenant and Partner Admin Center enabled +All scripts assume you have your own Office 365 tenant and Partner Center enabled. +If you do not have Partner Center enabled, +https://youtu.be/7qnSVtwOYgU -Watch a video on that here
-https://www.youtube.com/watch?v=B-bMCewxYFc&t=19s +## AzureRM +To get started with AzureRM, go here. +https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureRmTemplates#basics-and-pre-requisites-to-run-these-scripts + + +## AzureAz +To get started with AzureAz, go here. (Currently in progress of converting RM to Az) +https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureAzTemplates#to-install-the-new-az-module-based-on-net-core \ No newline at end of file From d0045369fee360394aed33370630d5b0ff995347 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:39:13 +0800 Subject: [PATCH 24/32] readme update --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 987a95c..c4c2685 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ If you do not have Partner Center enabled, https://youtu.be/7qnSVtwOYgU ## AzureRM -To get started with AzureRM, go here. -https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureRmTemplates#basics-and-pre-requisites-to-run-these-scripts +To get started with AzureRM, [Go Here](https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureRmTemplates#basics-and-pre-requisites-to-run-these-scripts). + ## AzureAz -To get started with AzureAz, go here. (Currently in progress of converting RM to Az) -https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureAzTemplates#to-install-the-new-az-module-based-on-net-core \ No newline at end of file +To get started with AzureAz, [Go Here].(https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureAzTemplates#to-install-the-new-az-module-based-on-net-core). (Currently in progress of converting RM to Az) + From 07a5914ba5c679d1d773f420df81329d83e0e060 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:39:34 +0800 Subject: [PATCH 25/32] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4c2685..17b2d92 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,5 @@ To get started with AzureRM, [Go Here](https://github.com/Brucius/PowerShell-for ## AzureAz -To get started with AzureAz, [Go Here].(https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureAzTemplates#to-install-the-new-az-module-based-on-net-core). (Currently in progress of converting RM to Az) +To get started with AzureAz, [Go Here](https://github.com/Brucius/PowerShell-for-Partners/tree/master/AzureAzTemplates#to-install-the-new-az-module-based-on-net-core). (Currently in progress of converting RM to Az) From 7c226d60b2c8fdc03845598498e922799db3659c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2019 14:41:40 +0800 Subject: [PATCH 26/32] az readme update --- AzureAzTemplates/readme.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AzureAzTemplates/readme.md b/AzureAzTemplates/readme.md index 64e1ba0..58c8efc 100644 --- a/AzureAzTemplates/readme.md +++ b/AzureAzTemplates/readme.md @@ -7,8 +7,11 @@ $versions | foreach { Uninstall-AllModules -TargetModule AzureRM -Version ($_.Ve Get-Module -ListAvailable | Where-Object { $_.Name -like 'AzureRM*' } | Uninstall-Module ``` To Uninstall all Azure + ```Get-Module -ListAvailable | Where-Object { $_.Name -like 'Azure*' } | Uninstall-Module``` ## To Install and Update the module -```Install-Module -Name Az -Install-Module -Name Az -AllowClobber -Force``` \ No newline at end of file +``` +Install-Module -Name Az +Install-Module -Name Az -AllowClobber -Force +``` \ No newline at end of file From 440a4f8ecf26c6f736a3b082a80571c3ce264f13 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 29 Jul 2019 11:38:57 +0800 Subject: [PATCH 27/32] refactor statusloopcopy managed disk --- ...tusLoopCopyManagedDisktoStorageAccount.ps1 | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 b/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 index d656bb4..8c095c5 100644 --- a/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 +++ b/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 @@ -1,11 +1,24 @@ +#This command sets the execution policy to bypass for only the current PowerShell session. +#After the window is closed, the next PowerShell session will open running with the default execution policy. +#“Bypass” means nothing is blocked and no warnings, prompts, or messages will be displayed. +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass + +##Define variables +$sourceRG = "sourceRgName" +$sourceDisk = "sourceDiskName" +$targetStorageAccount = "targetStorageAccountName" +$targetStorageAccountKey = "targetStorageAccountKey" +$targetStorageAccountContainer = "targetStorageAccountContainerName" +$targetDisk = "targetDiskName.vhd" + ##Login -Add-AzureRmAccount +Login-AzureRmAccount -$sas = Grant-AzureRmDiskAccess -ResourceGroupName "$RG" -DiskName "$diskname" -DurationInSecond 3600 -Access Read +$sas = Grant-AzureRmDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDisk -DurationInSecond 3600 -Access Read -$destContext = New-AzureStorageContext –StorageAccountName "$SAName" -StorageAccountKey "$SAKey" +$destContext = New-AzureStorageContext –StorageAccountName $targetStorageAccount -StorageAccountKey $targetStorageAccountKey -$blob1 = Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer "$SAContainer" -DestContext $destContext -DestBlob '$diskname.vhd' +$blob1 = Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageAccountContainer -DestContext $destContext -DestBlob $targetDisk ### Retrieve the current status of the copy operation ### $status = $blob1 | Get-AzureStorageBlobCopyState  From 9fddef8669c0dc2d30f220706d5f441b13f9beb5 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 31 Jul 2019 11:30:33 +0800 Subject: [PATCH 28/32] not much changes --- AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 b/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 index 3caa6ad..ff1ea67 100644 --- a/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 +++ b/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 @@ -47,7 +47,7 @@ $destinationResourceGroup = $resourceGroupName $osDisk = New-AzureRmDisk -DiskName "$osDiskName" -Disk ` (New-AzureRmDiskConfig -Location $location -CreateOption Copy ` -SourceResourceId $snapshot.Id ` - -Zone "$Zone") ` + -Zone "$Zone") l -ResourceGroupName $destinationResourceGroup Remove-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName From f43207a7befc237fe33398be925a2c55e93f3423 Mon Sep 17 00:00:00 2001 From: Oaker Min <7734956+Brucius@users.noreply.github.com> Date: Fri, 11 Oct 2019 15:25:09 +0800 Subject: [PATCH 29/32] Update copyMDNoDowntime.ps1 --- AzureRmTemplates/copyMDNoDowntime.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AzureRmTemplates/copyMDNoDowntime.ps1 b/AzureRmTemplates/copyMDNoDowntime.ps1 index 1059cb5..a91b03f 100644 --- a/AzureRmTemplates/copyMDNoDowntime.ps1 +++ b/AzureRmTemplates/copyMDNoDowntime.ps1 @@ -5,14 +5,15 @@ $SourceRGName = 'SourceRG' $SourceDiskName = 'SourceOSDISK' ### TARGET DETAILS -$TargetSubId = 'TargetID' +$TargetSubId = 'SubID' +$TargetTenantId = 'TenantID' $TargetRGName = 'TargetRG' ### Select Source Context -Select-AzureRmSubscription -SubscriptionId $SourceSubId +Select-AzureRmContext -SubscriptionId $TargetSubId -TenantId $TargetTenantId $managedDisk= Get-AzureRMDisk -ResourceGroupName $SourceRGName -DiskName $SourceDiskName ### Select Target Context Select-AzureRmSubscription -SubscriptionId $TargetSubId $diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy -New-AzureRmDisk -Disk $diskConfig -DiskName $SourceDiskName -ResourceGroupName $TargetRGName \ No newline at end of file +New-AzureRmDisk -Disk $diskConfig -DiskName $SourceDiskName -ResourceGroupName $TargetRGName From 501042713e81ac8ae0af464bbd5700fe215b0ce7 Mon Sep 17 00:00:00 2001 From: Oaker Min <7734956+Brucius@users.noreply.github.com> Date: Fri, 4 Sep 2020 14:41:47 +0800 Subject: [PATCH 30/32] Update marketplaceCheckNDeploy.ps1 --- AzureRmTemplates/marketplaceCheckNDeploy.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 index 5aa3bc5..ff2f7b1 100644 --- a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 +++ b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 @@ -47,15 +47,19 @@ Reference Marketplace Source file } } #> + $targetSubscriptionId='targetsubID' Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId $vmName = 'vmName' $resourceGroupName = 'rgName' $Zone = "1-2-3" #option of zone 1,2,3 -$nicName = "nicName" -$vmSize = "Standard_E4_v3" +$nicName = 'nicName' +$vmSize = 'Standard_E4_v3' +$OSDiskSize = 100 +$OSDiskCreateOption = 'Attach' +$location = 'francecentral' + -$location = 'francecentral' $snapshotName = "$vmName-temp" $osDiskName = "$vmName-OS-Disk" @@ -97,11 +101,7 @@ $vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize $vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id -$vm = Set-AzureRmVMOSDisk -VM $vm ` - -ManagedDiskId $osDisk.Id ` - -StorageAccountType Standard_LRS ` - -DiskSizeInGB 100 ` ## This can be changed according to the disk size you need - -CreateOption Attach -Linux +$vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType Standard_LRS -DiskSizeInGB $OSDiskSize -CreateOption $OSDiskCreateOption -Linux $vm = Set-AzureRmVMPlan -VM $vm -Publisher "publisherName" -Product "offerName" -Name "skuName" -New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm \ No newline at end of file +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm From 1deba8ac83030829e7aa36b8eea90dbf15572a35 Mon Sep 17 00:00:00 2001 From: Oaker Min <7734956+Brucius@users.noreply.github.com> Date: Fri, 4 Sep 2020 14:45:19 +0800 Subject: [PATCH 31/32] Update marketplaceCheckNDeploy.ps1 --- AzureRmTemplates/marketplaceCheckNDeploy.ps1 | 27 ++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 index ff2f7b1..46e6618 100644 --- a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 +++ b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 @@ -48,6 +48,20 @@ Reference Marketplace Source file } #> +<# This is for machines using marketplace Images that needs to be deployed +into availability zones. Deploy the machine first and get the error message +of failing due to marketplace terms then run this script. +Reference Marketplace Source file +"storageProfile": { + "imageReference": { + "publisher": "checkpoint", + "offer": "check-point-vsec-r80", + "sku": "sg-byol", + "version": "latest" + } +} +#> + $targetSubscriptionId='targetsubID' Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId $vmName = 'vmName' @@ -55,9 +69,12 @@ $resourceGroupName = 'rgName' $Zone = "1-2-3" #option of zone 1,2,3 $nicName = 'nicName' $vmSize = 'Standard_E4_v3' -$OSDiskSize = 100 -$OSDiskCreateOption = 'Attach' +$oSDiskSize = 100 +$oSDiskCreateOption = 'Attach' $location = 'francecentral' +$publisherName = "" +$productName = "" +$skuName = "" $snapshotName = "$vmName-temp" @@ -91,9 +108,9 @@ $osDisk = New-AzureRmDisk -DiskName "$osDiskName" -Disk ` Remove-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName -$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" +$agreementTerms = Get-AzureRmMarketplaceTerms -Publisher $publisherName -Product $productName -Name $skuName -Set-AzureRmMarketplaceTerms -Publisher "publisherName" -Product "offerName" -Name "skuName" -Terms $agreementTerms -Accept +Set-AzureRmMarketplaceTerms -Publisher $publisherName -Product $productName -Name $skuName -Terms $agreementTerms -Accept $nic = Get-AzureRmNetworkInterface -Name $nicName ` -ResourceGroupName $destinationResourceGroup @@ -102,6 +119,6 @@ $vmConfig = New-AzureRmVMConfig -VMName "$vmName" -VMSize $vmSize $vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id $vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType Standard_LRS -DiskSizeInGB $OSDiskSize -CreateOption $OSDiskCreateOption -Linux -$vm = Set-AzureRmVMPlan -VM $vm -Publisher "publisherName" -Product "offerName" -Name "skuName" +$vm = Set-AzureRmVMPlan -VM $vm -Publisher $publisherName -Product $productName -Name $skuName New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm From cd11c7f84cc4bf84aedad6436683055767be7c2b Mon Sep 17 00:00:00 2001 From: Oaker Min <7734956+Brucius@users.noreply.github.com> Date: Tue, 12 Jan 2021 12:31:34 +0800 Subject: [PATCH 32/32] Create registerMove.ps1 --- AzureAzTemplates/registerMove.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 AzureAzTemplates/registerMove.ps1 diff --git a/AzureAzTemplates/registerMove.ps1 b/AzureAzTemplates/registerMove.ps1 new file mode 100644 index 0000000..4d94a83 --- /dev/null +++ b/AzureAzTemplates/registerMove.ps1 @@ -0,0 +1,16 @@ +############################################################## +########## Register Backup and Managed Disk ################## +############################################################## +Register-AzProviderFeature -ProviderNamespace Microsoft.RecoveryServices -FeatureName RecoveryServicesResourceMove +Register-AzResourceProvider -ProviderNamespace Microsoft.RecoveryServices +Register-AzProviderFeature -FeatureName ManagedResourcesMove -ProviderNamespace Microsoft.Compute +Register-AzResourceProvider -ProviderNamespace Microsoft.Compute +do { + $getMdStatus = Get-AzProviderFeature -FeatureName ManagedResourcesMove -ProviderNamespace Microsoft.Compute + $getvaultStatus = Get-AzProviderFeature -FeatureName RecoveryServicesResourceMove -ProviderNamespace Microsoft.RecoveryServices + $getMdStatus + $getVaultStatus + Start-Sleep -Seconds 20 +} +while ($getMdStatus.RegistrationState.Equals("Registering") -and $getVaultStatus.RegistrationState.Equals("Registering")) +Write-Host "Registration Completed."