Created
November 19, 2012 23:49
-
-
Save sandrinodimattia/4114961 to your computer and use it in GitHub Desktop.
Passive FTP - Add endpoints in Windows Azure Virtual Machines
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
# Arguments. | |
param | |
( | |
[Microsoft.WindowsAzure.Management.ServiceManagement.Model.PersistentVMRoleContext]$vm = $(throw "'vm' is required."), | |
[int]$publicPort = $(throw "'publicPort' is required."), | |
[int]$dynamicPortFirst = $(throw "'dynamicPortFirst' is required."), | |
[int]$dynamicPortLast = $(throw "'dynamicPortLast' is required.") | |
) | |
Get-ChildItem "${Env:ProgramFiles(x86)}\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.dll" | ForEach-Object {[Reflection.Assembly]::LoadFile($_) | out-null } | |
$totalPorts = $dynamicPortLast - $dynamicPortFirst + 1 | |
if ($totalPorts -gt 150) | |
{ | |
$(throw "You cannot add more than 150 endpoints (this includes the Public FTP Port)") | |
} | |
# Add endpoints. | |
Write-Host -Fore Green "Adding: FTP-Public-$publicPort" | |
Add-AzureEndpoint -VM $vm -Name "FTP-Public-$publicPort" -Protocol "tcp" -PublicPort $publicPort -LocalPort $publicPort | |
for ($i = $dynamicPortFirst; $i -le $dynamicPortLast; $i++) | |
{ | |
$name = "FTP-Dynamic-" + $i | |
Write-Host -Fore Green "Adding: $name" | |
Add-AzureEndpoint -VM $vm -Name $name -Protocol "tcp" -PublicPort $i -LocalPort $i | |
} | |
# Update VM. | |
Write-Host -Fore Green "Updating VM..." | |
$vm | Update-AzureVM | |
Write-Host -Fore Green "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment