Users

All Posts (3)

avatar

niklashenningsson

Using personal/multiple credentials to each connection

avatar
avatar
avatar

We are an MSP connecting to different customers machines with RDM.

Sometimes we're required to use personal credentials for each admin agent for the connection to our customers.

How can I create an RDP Entry in RDM and when I connect to the machine it will use my credentials to that customer, but when my colleague connects it will use his credentials instead?

We're using Keeper Password Manager to store our credentials and we want to connect each admins personal entry in Keeper to the same RDP connection.

We're connecting to the data source with personal Entra ID credentials.

RDP via Azure Bastion (native client)

avatar
avatar
avatar
avatar
avatar

Thank you.

This script by itself did not work but I got it working by adding the end of your other script.

This is the script I use that works fine

# edit these variables

$VMName = "VM Name"
$VMResourceGroupName = "VM RG"
$BastionName = "Bastion Name"
$BastionResourceGroupName = "Bastion RG"

# generic portion of the script

@('Az.Accounts', 'Az.Network') | Import-Module
$SubscriptionId = (Get-AzContext).Subscription.Id
$VMResourceID = "/subscriptions/$SubscriptionId/resourceGroups/$VMResourceGroupName/providers/Microsoft.Compute/virtualMachines/$VMName"
$BastionDnsName = (Get-AzBastion -ResourceGroupName $BastionResourceGroupName -Name $BastionName).DnsName

$Params = @{
    Method  = 'GET'
    Uri     = "https://$BastionDnsName/api/rdpfile?resourceId=$VMResourceId&format=rdp"
    Headers = @{
        'Content-Type'  = 'application/json'
        'Authorization' = "Bearer $((Get-AzAccessToken).Token)"
    }
}

$RdpExclude = @('use multimon','signscope','signature')
$RdpFile = (Invoke-RestMethod @Params).Split("`n") | Where-Object {
    if (-Not [string]::IsNullOrEmpty($_)) {
        ($Name, $Type, $Value) = $_.Split(':', 3, [System.StringSplitOptions]::TrimEntries)
        (-Not $RdpExclude.Contains($Name))
    }
}


$RdpFile | ForEach-Object {
    ($Name, $Type, $Value) = $_.Split(':', 3, [System.StringSplitOptions]::TrimEntries)
    switch ($Name) {
        "full address" {
            $RDM.Connection.Host = $Value
            break;
        }
        "serverport" {
            $RDM.Connection.HostPort = $Value
            break;
        }
        "alternate full address" {
            $RDM.Connection.RDP.AlternateFullAddress = $Value
            break;
        }
        "gatewayhostname" {
            $RDM.Connection.RDP.GatewayHostname = $Value
            break;
        }
        "gatewayaccesstoken" {
            $RDM.Connection.RDP.GatewayAccessToken = $Value
            break;
        }
        "gatewaycredentialssource" {
            $RDM.Connection.RDP.GatewayCredentialsSource = $Value
            break;
        }
        "gatewayusagemethod" {
            $RDM.Connection.RDP.GatewayUsageMethod = $Value
            break;
        }
        "gatewayprofileusagemethod" {
            $RDM.Connection.RDP.GatewayProfileUsageMethod = $Value
            break;
        }
    }
}
$RDM.Save();

Hi,

I have done some testing with a simplified script that doesn't assume the same resource group for both the Azure VM and Azure Bastion resources:

# edit these variables

$VMName = "RDM-WOA"

$VMResourceGroupName = "TestWoa"

$BastionName = "TestWoA-vnet-bastion"

$BastionResourceGroupName = "TestWoa"

# generic portion of the script

@('Az.Accounts', 'Az.Network') | Import-Module

$SubscriptionId = (Get-AzContext).Subscription.Id

$VMResourceID = "/subscriptions/$SubscriptionId/resourceGroups/$VMResourceGroupName/providers/Microsoft.Compute/virtualMachines/$VMName"

$BastionDnsName = (Get-AzBastion -ResourceGroupName $BastionResourceGroupName -Name $BastionName).DnsName

$Params = @{

    Method  = 'GET'

    Uri     = "https://$BastionDnsName/api/rdpfile?resourceId=$VMResourceId&format=rdp"

    Headers = @{

        'Content-Type'  = 'application/json'

        'Authorization' = "Bearer $((Get-AzAccessToken).Token)"

    }

}

Invoke-RestMethod @Params

I can reproduce the "403 - Forbiddenbody" issue when I disable the Azure Bastion native client access feature, so I suspect this is the problem others have encountered so far:

Please make sure that the Azure Bastion is configured to use the Standard SKU *and* that "native client support" is enabled:

Please let me know if you still encounter the problem after confirming that native client support is enabled for an Azure Bastion using the Standard SKU

RDP via Azure Bastion (native client)

avatar
avatar
avatar
avatar
avatar

Were anyone able to make it work?

I am ending on error "HTTP Status 403 - Forbiddenbody" when calling Invoke-RestMethod with @Params.

Thank you for help

I get the same error as you in this part of the script

$RdpExclude = @('use multimon','signscope','signature')

$RdpFile = (Invoke-RestMethod @Params).Split("`n") | Where-Object {

if (-Not [string]::IsNullOrEmpty($_)) {

($Name, $Type, $Value) = $_.Split(':', 3, [System.StringSplitOptions]::TrimEntries)

(-Not $RdpExclude.Contains($Name))

}

}

1 - 3 of 3 items