Last active
August 29, 2015 14:07
-
-
Save petermreid/816e6a6e4aced5f6d0e8 to your computer and use it in GitHub Desktop.
Add Azure Web Server to farm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$subscriptionName = <subscriptonname> | |
$storageLocation = <vhdstorage> | |
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccountName $storageLocation | |
Select-AzureSubscription -SubscriptionName $subscriptionName | |
$username = <username> | |
$password = <password> | |
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force | |
$vmPrefix = “O365Accel” | |
$vmImageLocation = "http://" $storageLocation ".blob.core.windows.net/vhd" | |
#the name of the syspreped captured image | |
$vmImageName = "O365Accelerator" | |
$cloudService = "O365Accel" | |
$azureRegion = "Southeast Asia" | |
#$countVMs = ((Get-AzureVM -ServiceName $cloudService)|measure).Count | |
$countVMs = 4 | |
#create a farm of VMs from the template and add them into the farm behind a load balancer | |
ForEach ($vm in (1..$countVMs)) | |
{ | |
$vmName = $vmPrefix+"{0:00}" -f ($vm -as [int]) | |
$vmConfig = New-AzureVMConfig -Name $vmName -InstanceSize Small -MediaLocation $vmImageLocation -ImageName $vmImageName | |
$vmConfig = $vmConfig | Add-AzureProvisioningConfig -Windows -AdminUsername $username -Password $password | |
$vmConfig = $vmConfig | Set-AzureAvailabilitySet “O365AccelSet” | |
$vmConfig = $vmConfig | Add-AzureEndpoint -LBSetName "HTTPLB" -Name "HTTP" -Protocol "tcp" -LocalPort 80 -PublicPort 80 -DefaultProbe | |
$vmConfig = $vmConfig | Add-AzureEndpoint -LBSetName "HTTPSLB" -Name "HTTPS" -Protocol "tcp" -LocalPort 443 –PublicPort 443 -DefaultProbe | |
$vmConfig | New-AzureVM -ServiceName $cloudService -Location $azureRegion | |
write-host "Creating " $vmName | |
} | |
#now wait on the servers to be in ready state | |
ForEach ($vm in (1..$countVMs)) | |
{ | |
# Wait for servers to boot | |
$vmName = $vmPrefix+"{0:00}" -f ($vm -as [int]) | |
$vmInstance = Get-AzureVM -ServiceName $cloudService -name $vmName | |
$service = Get-AzureService -ServiceName $cloudService | |
While ($vmInstance.InstanceStatus -ne "ReadyRole") | |
{ | |
write-host "Waiting... " $vmName $vmInstance.Status | |
Start-Sleep -Seconds 10 | |
$vmInstance = Get-AzureVM -ServiceName $cloudService -name $vmName | |
} | |
write-host "Done... " $vmName $vmInstance.Status | |
# connect to the remote powershell interface | |
$remotePS = $vmInstance | Get-AzureEndpoint | Where Name -eq “PowerShell” | |
$credentials = New-Object System.Management.Automation.PSCredential($username, $secpasswd) | |
if ($remotePS -ne $null) | |
{ | |
# and do the per server configuration | |
write-host "Configuring... " $vmName | |
# reinstall the certificates lost after sysprep and then delete the pfx files | |
$s = New-PSSession -ComputerName ([Uri]$vmInstance.DNSName).DnsSafeHost -Port $remotePS.Port -UseSSL:$true -SessionOption (New-PSSessionOption -SkipCACheck) -Credential $credentials | |
Invoke-Command -Session $s -ScriptBlock { ` | |
Import-PfxCertificate -FilePath c:\certs\cdn.sharepointonline.com.pfx -CertStoreLocation Cert:\LocalMachine\WebHosting -Exportable | |
Import-PfxCertificate -FilePath c:\certs\prod.msocdn.com.pfx -CertStoreLocation Cert:\LocalMachine\WebHosting -Exportable | |
Import-PfxCertificate -FilePath c:\certs\<site>-my.sharepoint.com.pfx -CertStoreLocation Cert:\LocalMachine\WebHosting -Exportable | |
Import-PfxCertificate -FilePath c:\certs\<site>.sharepoint.com.pfx -CertStoreLocation Cert:\LocalMachine\WebHosting -Exportable | |
rmdir c:\certs | |
} | |
} | |
else | |
{ | |
Write-Output “No Remote Management Endpoints where found. Have you created a WinRmHTTPs Endpoint/firewall opening in Windows Azure?” | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment