简体   繁体   中英

Accessing Azure Cloud Service PaaS Instances via PowerShell remoting

I have an Azure Web Role with 2 Instances (NB the PaaS Roles, *not Azure Virtual Machines ). I can connect to them via Remote Desktop, but I don't know how to do Remoting in Powershell (PowerShell Remoting), because unlike with a Azure Virtual Machine Cloud Service, there is no way to define an Endpoint and Port for each instance as there are not separate addresses for each Worker Role.

How can I connect to an individual PaaS Worker Role Instance via Powershell Remoting ? IOW how can I use:

Enter-PSSession –ComputerName PC1 –Credential User

against a Cloud Service Worker Role (PaaS) Instance?

Using PowerShell Remoting (not to be confused with RDP) looks to be perfectly possible for Azure VMs:

PowerShell Remoting needs the correct network configuration to allow for remote connectivity. Since we will be accessing the VM over the web we are required to use HTTPS to secure the communication channel. Skipping over the details of Windows Remote Management which is used by PowerShell Remoting, I will just say the default HTTPS port is 5986.

To allow connectivity to the VM this endpoint must be added to the ServiceDefinition.csdef:

<endpoints>
    <inputendpoint localport="5986" port="5986" protocol="tcp" name="WinRM" /> 
</endpoints> 

With the proper port open it is just a matter of enabling PowerShell Remoting. Two issues need to be resolved before enabling it.

The first is using the correct user account to setup Remoting. You must use the account previously created to run the script to setup Remoting[1]. With these commands the user you previously created will execute the script e:\\approot\\StartRemotingListener.ps1:

schtasks /CREATE /TN "StartRemotingListener" /SC ONCE /SD 01/01/2020 /ST 00:00:00 
               /RL HIGHEST /RU <username> /RP <password> 
               /TR "powershell -ExecutionPolicy unrestricted 
                               -Command e:\approot\StartRemotingListener.ps1 -Force" /F
schtasks /RUN /TN "StartRemotingListener"

The second issue is configuring the certificate needed for the HTTPS connection. Acquiring a certificate might not be a problem for a production environment. You might already have one for your service and could reuse it. It can be a problem if your service doesn't require a certificate for normal operation or for non-production environments.

From: http://blogs.msdn.com/b/mariok/archive/2011/08/08/command-line-access-to-azure-vms-powershell-remoting.aspx

Using Azure management portal you can download the RDP files used to connect. Edit those files you should have all the details needed for connecting (end points and ports).

btw, Azure uses port forwarding for specific instance access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM