PowerShell function to enable WinRM over HTTPS on an Azure Resource Manager VM

You may have seen my previous posts detailing how to enable WinRM over HTTPS on an Azure Resource Manager VM. I have now collated all the different bits of script and creates a single PowerShell function. The function is called Configure-WinRMHTTPS, and is as follows:

Once the function is loaded you must login to Azure. Then the function can be executed:

Login-AzureRmAccount
 Configure-AzureWinRMHTTPS -ResourceGroupName "TestGroup" -VMName "TestVM"

My next post will cover submitting the function to the PowerShell Gallery.

9 Comments

  1. Ash

    I get the following error when I run the Enter=PSSession Enter-PSSession : Connecting to remote server publicip failed with the following error message : WinRM cannot complete the operation. Verify that the specified  computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this  computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the  about_Remote_Troubleshooting Help topic. I can see that its creaated the firewall exception in the Network Security group, the container scripts has been created with ConfigureWinRM_HTTPS.ps1. Am I missing something else? Thanks  

    Reply
  2. Marcus (Post author)

    When you ran the script did you recieve any errors?

    Reply
  3. Illes

    It is working perfectly, though you should make sure that your NIC settings match the pattern used here (i.e. there is a security group to config) so maybe for a beginner your original article is easier to follow. 

    But thanks, spared tons of hours for me.

    I

    Reply
  4. David Cobb

    Running PowerShell 5 on Windows 10 I get error:

    New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty. Provide 
    an argument that is not null or empty, and then try the command again.
    At C:\Users\david_000\Documents\scripts\Server2016AutomationPowerShell\Configure-AzureWinRMHTTPS.ps1:83 char:102
    + … ntext -StorageAccountName $storageaccountname -StorageAccountKey $key
    +                                                                      ~~~~
        + CategoryInfo          : InvalidData: (:) [New-AzureStorageContext], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet.NewAzure 
       StorageContext

    $key was not defined, I changed line 80 to (all one line):

    $key = (Get-AzureRmStorageAccountKey -Name $storageaccountname -ResourceGroupName $ResourceGroupName)[0].Value

    Reply
    1. Stephen Dillon

      I get the same. I've been digging around in the code and the URI on the StorageProfile is NULL. I cannot locate URIs for any disks nowadays. ARM is often frustrating to deal with compared to Azure Services (classic). 

      Reply
      1. Marcus (Post author)

        I’ll have a look and see if I can sort it. The storage commands have changed since I wrote the article.

        Reply
        1. Marcus (Post author)

          I've updated the script, resolved a number of issues. Let me know how you get on,

          Marcus

          Reply
          1. Stephen Dillon

            Yes, it is working now. Thanks for looking into it. 

  5. Pingback: Azure AD Connect – Setup a Test AD | irankon

Leave a Comment

Your email address will not be published. Required fields are marked *