-1

I have an azure VM that I'm trying to get some properties from. I can't seem to get the Operating system of the VM. Is this possible when the VM is not running?

  • 1
    There's no difference in getting the OS to when it's a physical box. – DavidG Apr 06 '21 at 15:53
  • [Windows](https://stackoverflow.com/questions/577634/how-to-get-the-friendly-os-version-name) or Linux (or [both](https://stackoverflow.com/questions/38790802/determine-operating-system-in-net-core)?) – gunr2171 Apr 06 '21 at 16:00
  • this *should* just be `RuntimeInformation.OSDescription`, like it would be when *not* on a VM...? (there are lots of other more specific facets available in `RuntimeInformation`, note) – Marc Gravell Apr 06 '21 at 16:01
  • As for determining the OS _outside_ of the VM, have you researched using the Azure SDK? – gunr2171 Apr 06 '21 at 16:04
  • [Does this help](https://stackoverflow.com/questions/55947701/how-to-find-out-what-version-of-windows-is-azure-vm-using-with-powershell)? – Crowcoder Apr 06 '21 at 16:09
  • I will tell you directly is: windows :-) unless you are using .net core. – Juanma Feliu Apr 06 '21 at 18:00

1 Answers1

0

Just try the simple console app below:

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using System;


namespace fluentMgmtTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var AppId = "";
            var AppSecret = "";
            var tenant = "";
            var subscriptionID = "";
            var vmGroup = "";
            var vmName = "";

            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(AppId, AppSecret, tenant, AzureEnvironment.AzureGlobalCloud);
            var azure = Azure.Configure().Authenticate(credentials).WithSubscription(subscriptionID);

            var vmID = "/subscriptions/" + subscriptionID + "/resourceGroups/" + vmGroup + "/providers/Microsoft.Compute/virtualMachines/" + vmName;

            var vm = azure.VirtualMachines.GetById(vmID);

            Console.WriteLine(vm.OSType);

        }
    }
}

Result: enter image description here enter image description here

Note: Pls make sure that your Azure AD App has been at least assigned a role with read permission before you run this code.

Stanley Gong
  • 10,576
  • 1
  • 6
  • 16
  • Thanks for this. The VM I'm currently working on is a Windows 2016 Server. I only get "Windows" returned but when the VM has started, I can get the full value. Using the InstanceView. – user3192935 Apr 09 '21 at 08:14
  • @user3192935, glad to know your issue has been solved, if my post is helpful, could you pls click on the checkmark beside the answer to toggle it from greyed out to fill in to accept it as an answer, so that it will help others and close this question : ) – Stanley Gong Apr 12 '21 at 03:06