public static ResourceGroup GetHostResourceGroup(String accessToken, ComputeVm thisVm)
        {
            string vmId = thisVm.id;
            var SplitUrl = vmId.Split('/');
            var rgName = SplitUrl[4];
            var subscriptionName = SplitUrl[2];

            string authToken = "Bearer" + " " + accessToken;
            var client = new WebClient();
            client.Headers.Add("Authorization", authToken);
            client.Headers.Add("Content-Type", "application/json");

            string singleRgUrl = String.Format("https://management.azure.com/subscriptions/{0}/resourcegroups/{1}?api-version=2015-01-01 ", subscriptionName, rgName);

            String text = "";

            text = client.DownloadString(singleRgUrl);
            ResourceGroup thisRg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResourceGroup>(text);
            return thisRg;
        }
        public static bool GetVmPowerStatus(String accessToken, ComputeVm thisVm)
        {
            bool returnResult = false;

            string vmId = thisVm.id;
            var SplitUrl = vmId.Split('/');
            var rgName = SplitUrl[4];
            var subscriptionName = SplitUrl[2];

            string authToken = "Bearer" + " " + accessToken;
            var client = new WebClient();
            client.Headers.Add("Authorization", authToken);
            client.Headers.Add("Content-Type", "application/json");

            string vmStatusUrl = string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}?$expand=instanceView&api-version=2015-06-15", subscriptionName, rgName, thisVm.name);
            String text = "";
            text = client.DownloadString(vmStatusUrl);
            var vmStatus = Newtonsoft.Json.JsonConvert.DeserializeObject<ComputeVm>(text);
            var InstanceView = vmStatus.properties.instanceView.statuses;
            var ThisInstanceviewPowerState = InstanceView.Where(p => p.code.Contains("PowerState")).FirstOrDefault();
            var ThisInstanceviewProvisioningState = InstanceView.Where(p => p.code.Contains("ProvisioningState")).FirstOrDefault();
            if ((ThisInstanceviewPowerState.code == "PowerState/running") && (ThisInstanceviewProvisioningState.code == "ProvisioningState/succeeded"))
            {

                returnResult = true;
            }

            System.Diagnostics.Debug.WriteLine(string.Format("VM {0} in RG {1} has power state {2}", thisVm.name, rgName, ThisInstanceviewPowerState.code));
            return returnResult;
        }
        public static SimplifiedNic GetNicDetails(String accessToken, ComputeVm Vm)
        {
            string authToken = "Bearer" + " " + accessToken;
            var client = new WebClient();
            client.Headers.Add("Authorization", authToken);
            client.Headers.Add("Content-Type", "application/json");

            var nic = Vm.properties.networkProfile.networkInterfaces.FirstOrDefault();
            string nicLink = nic.id;
            String nicUrl = String.Format("https://management.azure.com{0}{1}", nicLink, "?api-version=2015-05-01-preview");
            String nicText = client.DownloadString(nicUrl);
            //ComputeVms rgCompVms = JsonConvert.DeserializeObject<ComputeVms>(rgVmsText);
            ArmRest.Models.NetworkInterfaceDetails.RootObject nicObj = JsonConvert.DeserializeObject<ArmRest.Models.NetworkInterfaceDetails.RootObject>(nicText);

            String InternalIpAddress = nicObj.properties.ipConfigurations.FirstOrDefault().properties.privateIPAddress;

            String PublicIpLink = nicObj.properties.ipConfigurations.FirstOrDefault().properties.publicIPAddress.id;
            String publicIpUrl = String.Format("https://management.azure.com{0}{1}", PublicIpLink, "?api-version=2015-05-01-preview");
            String publicIpText = client.DownloadString(publicIpUrl);

            ArmRest.Models.PublicIpAddress.RootObject publicIpAddressObj = JsonConvert.DeserializeObject<ArmRest.Models.PublicIpAddress.RootObject>(publicIpText);

            SimplifiedNic thisSimplifiedNic = new SimplifiedNic();
            thisSimplifiedNic.InternalIpAddress = InternalIpAddress;

            String PublicIpAddress = null;
            try
            {
                PublicIpAddress = publicIpAddressObj.properties.ipAddress;
                thisSimplifiedNic.PublicIpAddress = PublicIpAddress;
            }
            catch
            { }

            try
            {
                thisSimplifiedNic.PublicHostName = publicIpAddressObj.properties.dnsSettings.fqdn;
            }
            catch
            { }

            return thisSimplifiedNic;
        }