davidu davidu - 2 months ago 10
PowerShell Question

.NET API for DirectAcces status

we are currently developing a .NET application that needs to know the Microsoft DirectAccess connection state. I know it is possible to query the status via the PowerShell command


But is it also possibly to query this DirectAccess status via a managed .NET library/API? A workaround would be to run a PowerShell script from C# but I don't think this is ideal from a performance perspective (we need to check this status regularly).



I could imagine the following (not testet yet though):

You can query the same information via

Get-CimInstance -Namespace "root/StandardCimv2" MSFT_DAConnectionStatus

and you can query CIM instances by C# via the assembly Microsoft.Management.Infrastructure of the Windows SDK as explained here