If you are from the instance, the IP Address is assigned at boot time. So by the time a start-up task is executed (PaaS / Cloud Service) you can determine the IP Address by just enumerating the network cards. Or getting en IP Endpoint.
A sample powershell (which has never been tested) would look something like this:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")
$ipEndpoint = [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint
Now you have the $ipEndpoint
variable which is of .NET type IPEndpoint
and holds the local IP Address of the VM.