Skip to content

Instantly share code, notes, and snippets.

View astaykov's full-sized avatar

Anton Staykov astaykov

  • Microsoft (former Microsoft Azure MVP)
  • Berlin, Germany
  • X @astaykov
View GitHub Profile
@astaykov
astaykov / azureADsetup.ps1
Created March 27, 2014 23:19
Azure VM - AD/DC with DNS Server and a Client
# first authenticate using your Azure Active Directory credentials
Add-AzureAccount
# then list all the subscriptions to get the name
Get-AzureSubscription
# now set the subscription context as well as default storage account that
# will be used for rest of the operations
# note, the account has to be created in the same Affinity Group as the Virtual Network !!
Set-AzureSubscription "[YOUR Subscription Name]" -CurrentStorageAccountName "[azurestorageaccount]"
@astaykov
astaykov / non-interactive-azure-manage
Created August 13, 2014 15:57
Non-interactive Azrue PowerShell management
# first save encrypted password to a file that can later be used
read-host -assecurestring | convertfrom-securestring | out-file d:\tmp\securestring.txt
# then use the saved password
$password = cat d:\tmp\securestring.txt | convertto-securestring
# currently (August, the 13nd, 2014) only organizational accounts are supported (also with custom domain).
# Microsoft Accounts (Live ID) are not supported
$username = "user@tenant.onmicrosoft.com" # or user@yourdomain.com if 'yourdomain.com' is registered with AAD
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password
Add-AzureAccount -credential $mycred
@astaykov
astaykov / azure-powershell-bulk-add-endpoints
Created August 14, 2014 07:01
Azure IaaS PowerShell bulk add endpoints
Add-AzureAccount
Select-AzureSubscription -SubscriptionName "Your_Subscription_Name"
$vm = Get-AzureVM -ServiceName "CloudServiceName" -Name "VM_Name"
for ($i=6100; $i -le 6120; $i++)
{
$EndpointName = "FtpEndpoint_"
$EndpointName += $i
Add-AzureEndpoint -Name $EndpointName -Protocol "tcp" -PublicPort $i -LocalPort $i -VM $vm
}
$vm | Update-AzureVM
cmd.exe /c $env:windir\system32\inetsrv\appcmd.exe list apppool "apppoolname" /text:ProcessModel.Password
@astaykov
astaykov / AzureCloudServiceAntiMalwareProtection.ps1
Created September 15, 2014 12:53
Azure Cloud Service Antimalware Protection extension
Add-AzureAccount
# use Select-AzureSubscription in case your account has more than one
Select-AzureSubscription -SubscriptionName 'PUT HERE YOUR SUBSCRIPTION'
[System.Xml.XmlDocument] $XmlConfig = New-Object System.Xml.XmlDocument
# load the Antimalware extension configuration from external XML file
# The content of the XML needs to be:
# <AntimalwareConfig><AntimalwareEnabled>true</AntimalwareEnabled></AntimalwareConfig>
# ref.: http://msdn.microsoft.com/en-US/library/azure/dn771718
$XmlConfig.load('D:\tmp\AntiMalware.config')
Set-AzureServiceAntimalwareExtension -ServiceName "PUT HERE THE CLOUD SERVICE NAME" -AntimalwareConfiguration $XmlConfig
netsh http add urlacl url=https://+:4444/ user=[Existing user on the system]
netsh http add sslcert ipport=0.0.0.0:4444 certhash=[thumbprint of SSL cert] appid={[GUID - a freely chosen GUID]}
@astaykov
astaykov / Azure_Update_ServiceConfig
Created September 29, 2014 06:46
Update service configuration of Cloud Service
# Add the Azure Account first - this will create a login promppt
Add-AzureAccount
# when you have more then one subscription - you have explicitly select the one
# which holds your cloud service you want to update
Select-AzureSubscription "<Subscription name with spaces goes here>"
# then Update the configuration for the cloud service
Set-AzureDeployment -Config -ServiceName "<cloud_service_name_goes_here>" `
-Configuration "D:/tmp/cloud/ServiceConfiguration.Cloud.cscfg" `
-Slot "Production"
@astaykov
astaykov / ReserveIPforVM.ps1
Created February 24, 2015 07:01
Move existing Azure VM to a Cloud Service with Reserved IP Address
$subName = "<your_subscription_name>"
$storageName = "<your_storage_account_name>"
$reservedIPname = "<pick_a_name_for_the_reserved_ip>"
$reservedIPlabel = "<pick_a_label_for_the_ip>"
$reservedIPlocation "<set_the_location>" # i.e. West Europe
$serviceName = "<cloud_service_name_of_the_deployed_vm>"
$vmName = "<namne_of_the_vm>"
$vnetSiteName = "<name_of_the_vnet_site>" # if the VM will be part of Virtual Network.
$pathToVMConfig "<enter local path where to save current vm configuration>"
Add-AzureAccount
Clear-AzureProfile -Force
cls
Add-AzureAccount
Select-AzureSubscription -SubscriptionName '<your subscription name here>'
Set-AzureSubscription -SubscriptionName '<your subscription name here>' -CurrentStorageAccountName '<storage account name where disks should be placed>'
$vm = Get-AzureVM | Where-Object { $_.Name -eq '<name of the VM to update>' }
Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel '<label of data disk 1>' -HostCaching ReadOnly -LUN 2 -VM $vm.VM
Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel '<label of data disk 2>' -HostCaching ReadOnly -LUN 3 -VM $vm.VM
Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel '<label of data disk 3>' -HostCaching ReadOnly -LUN 4 -VM $vm.VM
Update-AzureVM -Name $vm.Name -ServiceName $vm.ServiceName -VM $vm.VM
@astaykov
astaykov / azurewebsites_in_farm.ps1
Created March 31, 2015 23:42
Create Azure Web Sites in given Farm
Switch-AzureMode -Name AzureResourceManager
Add-AzureAccount
Select-AzureSubscription "Your Subscription Name"
New-AzureResource -Name NewWebSite `
-Location "West Europe" `
-ResourceGroupName 'Default-Web-WestEurope' `
-ResourceType 'Microsoft.Web/sites' `
-ApiVersion '2014-04-01-preview' `
-PropertyObject @{ 'ServerFarm' = 'DefaultServerFarm' }