Search code examples
azurevirtual-machineazure-virtual-machinerdphardening

Can I create a generalized vm image with RDP disabled


How can we create windows VM image with RDP disabled for VMs created from that image? I want publish an RDP hardened image.


Solution

  • You can do this with a Custom Script Extension for Windows

    Create a PowerShell scripts which disables RDP and reference it:

    {
      "fileUris": ["https://mystorage.blob.core.windows.net/privatecontainer/script1.ps1"],
      "commandToExecute": "powershell.exe script1.ps1",
      "managedIdentity" : {}
    }
    

    Powershell script to disable RDP in registry:

    Invoke-Command –Computername "customname" –ScriptBlock {Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value 1}