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/Basics/InstallUpdateAzureRM&AD.ps1 b/Azure/Basics/InstallUpdateAzureRM&AD.ps1 deleted file mode 100644 index 24e8134..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 AzureRM module -$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 deleted file mode 100644 index 94af846..0000000 --- a/Azure/Basics/readme.md +++ /dev/null @@ -1 +0,0 @@ -Installing Modules and Selecting subscription as Partner diff --git a/Azure/StatusLoopCopyManagedDisktoStorageAccount.ps1 b/Azure/StatusLoopCopyManagedDisktoStorageAccount.ps1 deleted file mode 100644 index d656bb4..0000000 --- a/Azure/StatusLoopCopyManagedDisktoStorageAccount.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -##Login -Add-AzureRmAccount - -$sas = Grant-AzureRmDiskAccess -ResourceGroupName "$RG" -DiskName "$diskname" -DurationInSecond 3600 -Access Read - -$destContext = New-AzureStorageContext –StorageAccountName "$SAName" -StorageAccountKey "$SAKey" - -$blob1 = Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer "$SAContainer" -DestContext $destContext -DestBlob '$diskname.vhd' - -### Retrieve the current status of the copy operation ### -$status = $blob1 | Get-AzureStorageBlobCopyState  -  -### Print out status ###  -$status  -  -### Loop until complete ###                                     -While($status.Status -eq "Pending"){ -  $status = $blob1 | Get-AzureStorageBlobCopyState  -  Start-Sleep 10 -  ### Print out status ### -  $status -} diff --git a/Azure/copyMDNoDowntime b/Azure/copyMDNoDowntime deleted file mode 100644 index a444ed5..0000000 --- a/Azure/copyMDNoDowntime +++ /dev/null @@ -1,10 +0,0 @@ -$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 -$diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy -New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $targetResourceGroupName diff --git a/Azure/readme.md b/Azure/readme.md deleted file mode 100644 index ed1506f..0000000 --- a/Azure/readme.md +++ /dev/null @@ -1 +0,0 @@ -Look into Basics folder first and follow the instructions diff --git a/AzureAzTemplates/readme.md b/AzureAzTemplates/readme.md new file mode 100644 index 0000000..58c8efc --- /dev/null +++ b/AzureAzTemplates/readme.md @@ -0,0 +1,17 @@ +## To Install the new Az module based on .Net Core. +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) +$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/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." diff --git a/Azure/AzureExpressRouteSetUDR.ps1 b/AzureRmTemplates/AzureExpressRouteSetUDR.ps1 similarity index 100% rename from Azure/AzureExpressRouteSetUDR.ps1 rename to AzureRmTemplates/AzureExpressRouteSetUDR.ps1 diff --git a/Azure/AzureRMCopyVHDManagedDisksfromMS.ps1 b/AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 similarity index 100% rename from Azure/AzureRMCopyVHDManagedDisksfromMS.ps1 rename to AzureRmTemplates/AzureRMCopyVHDManagedDisksfromMS.ps1 diff --git a/Azure/AzureRMInventorywithTags.ps1 b/AzureRmTemplates/AzureRMInventorywithTags.ps1 similarity index 100% rename from Azure/AzureRMInventorywithTags.ps1 rename to AzureRmTemplates/AzureRMInventorywithTags.ps1 diff --git a/Azure/Convert VHD to Fixed.ps1 b/AzureRmTemplates/Convert VHD to Fixed.ps1 similarity index 100% rename from Azure/Convert VHD to Fixed.ps1 rename to AzureRmTemplates/Convert VHD to Fixed.ps1 diff --git a/Azure/Basics/Select Subscription.ps1 b/AzureRmTemplates/SelectSubscriptionThruPartnerCenter.ps1 similarity index 100% rename from Azure/Basics/Select Subscription.ps1 rename to AzureRmTemplates/SelectSubscriptionThruPartnerCenter.ps1 diff --git a/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 b/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 new file mode 100644 index 0000000..8c095c5 --- /dev/null +++ b/AzureRmTemplates/StatusLoopCopyManagedDisktoStorageAccount.ps1 @@ -0,0 +1,35 @@ +#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 +Login-AzureRmAccount + +$sas = Grant-AzureRmDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDisk -DurationInSecond 3600 -Access Read + +$destContext = New-AzureStorageContext –StorageAccountName $targetStorageAccount -StorageAccountKey $targetStorageAccountKey + +$blob1 = Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageAccountContainer -DestContext $destContext -DestBlob $targetDisk + +### Retrieve the current status of the copy operation ### +$status = $blob1 | Get-AzureStorageBlobCopyState  +  +### Print out status ###  +$status  +  +### Loop until complete ###                                     +While($status.Status -eq "Pending"){ +  $status = $blob1 | Get-AzureStorageBlobCopyState  +  Start-Sleep 10 +  ### Print out status ### +  $status +} 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/Azure/azcopy b/AzureRmTemplates/azcopy.ps1 similarity index 100% rename from Azure/azcopy rename to AzureRmTemplates/azcopy.ps1 diff --git a/AzureRmTemplates/checkMarketPlaceImage.ps1 b/AzureRmTemplates/checkMarketPlaceImage.ps1 new file mode 100644 index 0000000..523b53a --- /dev/null +++ b/AzureRmTemplates/checkMarketPlaceImage.ps1 @@ -0,0 +1,28 @@ +##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 diff --git a/AzureRmTemplates/cloneNSGsAcrossSub.ps1 b/AzureRmTemplates/cloneNSGsAcrossSub.ps1 new file mode 100644 index 0000000..be4fac2 --- /dev/null +++ b/AzureRmTemplates/cloneNSGsAcrossSub.ps1 @@ -0,0 +1,34 @@ +#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 + +$sourceSubscriptionId = "sourceSubId" +$sourceTenantId = "sourceTenantId" +$nsgOrigin = "sourceNSG" +$rgName = "sourceRG" #Resource Group Name of source NSG + +$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 + +Set-AzureRmContext -SubscriptionId $targetSubscriptionId -TenantId $targetTenantId + +$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 diff --git a/AzureRmTemplates/copyMDNoDowntime.ps1 b/AzureRmTemplates/copyMDNoDowntime.ps1 new file mode 100644 index 0000000..a91b03f --- /dev/null +++ b/AzureRmTemplates/copyMDNoDowntime.ps1 @@ -0,0 +1,19 @@ +# The following script lets you copy a managed disk across 2 subscriptions in the same tenant instantaneously. +### SOURCE DETAILS +$SourceSubId = 'SourceID' +$SourceRGName = 'SourceRG' +$SourceDiskName = 'SourceOSDISK' + +### TARGET DETAILS +$TargetSubId = 'SubID' +$TargetTenantId = 'TenantID' +$TargetRGName = 'TargetRG' + +### Select Source Context +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 diff --git a/AzureRmTemplates/createBlobSAS.ps1 b/AzureRmTemplates/createBlobSAS.ps1 new file mode 100644 index 0000000..859e2dd --- /dev/null +++ b/AzureRmTemplates/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))'' diff --git a/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 b/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 new file mode 100644 index 0000000..ff1ea67 --- /dev/null +++ b/AzureRmTemplates/marketPlaceWithAvailabilityZones.ps1 @@ -0,0 +1,73 @@ +<# 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" +$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") l + -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 ` + -CreateOption Attach -Linux +$vm = Set-AzureRmVMPlan -VM $vm -Publisher "publisherName" -Product "offerName" -Name "skuName" + +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm diff --git a/AzureRmTemplates/marketplaceCheckNDeploy.ps1 b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 new file mode 100644 index 0000000..46e6618 --- /dev/null +++ b/AzureRmTemplates/marketplaceCheckNDeploy.ps1 @@ -0,0 +1,124 @@ +#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" + } +} +#> + +<# 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" #option of zone 1,2,3 +$nicName = 'nicName' +$vmSize = 'Standard_E4_v3' +$oSDiskSize = 100 +$oSDiskCreateOption = 'Attach' +$location = 'francecentral' +$publisherName = "" +$productName = "" +$skuName = "" + + +$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 $productName -Name $skuName + +Set-AzureRmMarketplaceTerms -Publisher $publisherName -Product $productName -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 $OSDiskSize -CreateOption $OSDiskCreateOption -Linux +$vm = Set-AzureRmVMPlan -VM $vm -Publisher $publisherName -Product $productName -Name $skuName + +New-AzureRmVM -ResourceGroupName $destinationResourceGroup -Location $location -VM $vm diff --git a/AzureRmTemplates/moveDisktoAZ.ps1 b/AzureRmTemplates/moveDisktoAZ.ps1 new file mode 100644 index 0000000..1ee1146 --- /dev/null +++ b/AzureRmTemplates/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 diff --git a/AzureRmTemplates/readme.md b/AzureRmTemplates/readme.md new file mode 100644 index 0000000..894d2be --- /dev/null +++ b/AzureRmTemplates/readme.md @@ -0,0 +1,25 @@ +# Basics and Pre-requisites to run these scripts +The below cmdlets helps you install necessary modules to run the scripts on your local machine. + +## 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``` \ No newline at end of file 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/Bulk MX Lookup.ps1 b/Office-365/Setup-Tenant/Bulk MX Lookup.ps1 similarity index 100% rename from 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..17b2d92 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 + +## 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](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) -Watch a video on that here
-https://www.youtube.com/watch?v=B-bMCewxYFc&t=19s