Hi,
Can you try the below C# code:
using Azure.Identity;
using Azure.ResourceManager.DesktopVirtualization;
using Azure.ResourceManager.DesktopVirtualization.Models;
using System;
class Program
{
static void Main(string[] args)
{
string subscriptionId = "your-subscription-id";
string resourceGroupName = "your-resource-group-name";
string hostPoolName = "your-host-pool-name";
string sessionHostName = "your-session-host-name";
string vmTemplateName = "your-vm-template-name";
// Authenticate using Azure.Identity
var credential = new DefaultAzureCredential();
// Create the DesktopVirtualizationManagementClient
var client = new DesktopVirtualizationManagementClient(subscriptionId, credential);
// Set the base URI if needed
// client.BaseUri = new Uri("https://management.azure.com");
// Set the resource group and host pool details
var hostPoolUri = $"{resourceGroupName}/Microsoft.DesktopVirtualization/hostPools/{hostPoolName}";
// Create the session host parameters
var sessionHostParams = new SessionHost
{
AllowNewSession = true,
Description = "My session host",
FriendlyName = sessionHostName,
HostPoolArmPath = hostPoolUri,
VmTemplate = new WvdApiReference { Reference = vmTemplateName }
};
// Add the session host to the host pool
client.SessionHosts.CreateOrUpdate(resourceGroupName, hostPoolName, sessionHostName, sessionHostParams);
Console.WriteLine("Session host added successfully!");
}
}