Remoting into Azure ARM Virtual Machines - Configuration and Management

Remoting into Azure ARM Virtual Machines using Powershell

 
 
 
 
 
5 Star
(4)
2,257 times
Add to favorites
Windows Azure
5/30/2016
E-mail Twitter del.icio.us Digg Facebook
  • Possible without Public IP?
    3 Posts | Last post July 27, 2017
    • Hello
      
      Is it possible to run the script without a Public IP - we cannot assign due company restrictions.
      
      Thanks
    • No. You need to have a public endpoint if you need to remote into the machine from outside the network. However, you can look into setting up your machine as a Hybrid Worker - https://docs.microsoft.com/en-us/azure/automation/automation-hybrid-runbook-worker
    • Thank you. But I just want to run scripts due the Azure Automator on the VM itself. Nothing more. Isn't that possible somehow?
  • Help!
    11 Posts | Last post June 02, 2016
    • The connect-azurearmps works great and returns the ip address, however the automation always returns "Couldnt get the IP Address of the VM".  Have you seen this issue?
    • Could you elaborate on the exact error you are getting? I didnt quite understand what you meant by "the automation always returns..."
      
    • ERROR: Get-AzureRmNetworkInterface : The term 'Get-AzureRmNetworkInterface' is not recognized as the name of a cmdlet, 
      function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the 
      path is correct and try again.
      At Connect-AzureARMVM:50 char:50
      + 
          + CategoryInfo          : ObjectNotFound: (Get-AzureRmNetworkInterface:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
       
      
      ERROR: Get-AzureRmResource : Cannot validate argument on parameter 'ResourceId'. The argument is null or empty. Provide an 
      argument that is not null or empty, and then try the command again.
      At Connect-AzureARMVM:50 char:50
      + 
          + CategoryInfo          : InvalidData: (:) [Get-AzureRmResource], ParameterBindingValidationException
          + FullyQualifiedErrorId : 
      ParameterArgumentValidationError,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet
       
      
      ERROR: Get-AzureRmNetworkSecurityGroup : The term 'Get-AzureRmNetworkSecurityGroup' is not recognized as the name of a cmdlet, 
      function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the 
      path is correct and try again.
      At Connect-AzureARMVM:50 char:50
      + 
          + CategoryInfo          : ObjectNotFound: (Get-AzureRmNetworkSecurityGroup:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
       
      
      ERROR: Add-AzureRmNetworkSecurityRuleConfig : The term 'Add-AzureRmNetworkSecurityRuleConfig' is not recognized as the name of 
      a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify 
      that the path is correct and try again.
      At Connect-AzureARMVM:50 char:50
      + 
          + CategoryInfo          : ObjectNotFound: (Add-AzureRmNetworkSecurityRuleConfig:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
       
      
      ERROR: Get-AzureRmNetworkInterface : The t
    • I turned off the silently continue and its saying a lot of the commands cannot be found.
    • When I say always returns I mean when I test the script out it always fails and the return before turning off the error control was "couldnt get the IP Address of the VM"
    • It looks like you dont have the AzureRM.Network module imported in your automation account. Ensure you have all the following modules in your automation assets all with version 1.0.3:
      •	AzureRm.Profile
      •	AzureRm.Network
      •	Azure.Storage
      •	AzureRm.Storage
      •	AzureRm.Resources
      
      To Install AzureRM.Network v1.0.3 run this cmdlet locally:
      Save-Module -Name AzureRM.Network -Path <path> -RequiredVersion 1.0.3
      
      Zip the folder and upload it as an Azure Automation Module Asset
      
    • It appears that the issue is automation says it cannot find the following commands:
      get-azurermnetworksecuritygroup
      add-azurermnetworksecurityruleconfig
      get-azurermnetworkinterface
    • All of these cmdlets need the AzureRM.Network module. In case its not present you will get that message
    • Yep, thanks I'm new to this.  I just found I needed to import azurerm.profile and azurerm.network.  
    • No problem. Be sure to install the version 1.0.3 since thats the current Global Module version. You can do that by running the command locally, zip the folder and upload it to Azure Automation as a module asset.
      
      Save-Module -Name AzureRM.Profile -Path <path> -RequiredVersion 1.0.3
      Save-Module -Name AzureRM.Network -Path <path> -RequiredVersion 1.0.3
    • One Last thing I would update the write-output so it only shows the ipaddress and update the new-item because it needs the "-type file" hook:
      
              $IpAddress = Connect-AzureARMVM -AzureSubscriptionId $AzureSubscriptionId -AzureOrgIdCredentialName $AzureOrgIdCredentialName -ResourceGroupName $ResourceGroupName -VMName $VMName  
              Write-Output "The IP Address is $($IpAddress). Attempting to remote into the VM.."
              if($IpAddress -ne $null)
              {
                  InlineScript{       
                      $sessionOptions = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck                
                      Invoke-Command -ComputerName $using:IpAddress -Credential $using:VMCredential -UseSSL -SessionOption $sessionOptions -ScriptBlock { 
      		        #Code to be executed in the remote session goes here
      				new-item -path c:\waka\waka123.txt -type file
      				move-item -path c:\waka\*.* -destination c:\waka1\
                      $hostname = hostname
                      Write-Output "Hostname : $hostname"
      				$ip = get-netipaddress
      				write-output "$ip"