public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var parameters = new VirtualMachineExtensionImageListVersionsParameters
            {
                Location = Location.Canonicalize(),
                PublisherName = PublisherName,
                Type = Type,
                FilterExpression = FilterExpression
            };

            VirtualMachineImageResourceList result = this.VirtualMachineExtensionImageClient.ListVersions(parameters);

            var images = from r in result.Resources
                         select new PSVirtualMachineExtensionImage
                         {
                             RequestId = result.RequestId,
                             StatusCode = result.StatusCode,
                             Id = r.Id,
                             Location = r.Location,
                             Version = r.Name,
                             PublisherName = this.PublisherName,
                             Type = this.Type,
                             FilterExpression = this.FilterExpression
                         };

            WriteObject(images, true);
        }
        public void TestExtImgListVersionsFilters()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();
                ComputeManagementClient _pirClient =
                    ComputeManagementTestUtilities.GetComputeManagementClient(new RDFETestEnvironmentFactory(),
                        new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK });

                VirtualMachineExtensionImageListVersionsParameters listVersionsParamers = new VirtualMachineExtensionImageListVersionsParameters()
                {
                    Location = parameters.Location,
                    Type = parameters.Type,
                    PublisherName = parameters.PublisherName,
                };

                // Filter: startswith - Positive Test
                listVersionsParamers.FilterExpression = "$filter=startswith(name,'1.1')";
                var vmextimg = _pirClient.VirtualMachineExtensionImages.ListVersions(listVersionsParamers);
                Assert.True(vmextimg.Resources.Count > 0);
                Assert.True(vmextimg.Resources.Count(vmi => vmi.Name == "1.1.0") != 0);

                // Filter: startswith - Negative Test
                listVersionsParamers.FilterExpression = "$filter=startswith(name,'1.0')";
                vmextimg = _pirClient.VirtualMachineExtensionImages.ListVersions(listVersionsParamers);
                Assert.True(vmextimg.Resources.Count == 0);
                Assert.True(vmextimg.Resources.Count(vmi => vmi.Name == "1.1.0") == 0);

                // Filter: top - Positive Test
                listVersionsParamers.FilterExpression = "$top=1";
                vmextimg = _pirClient.VirtualMachineExtensionImages.ListVersions(listVersionsParamers);
                Assert.True(vmextimg.Resources.Count == 1);
                Assert.True(vmextimg.Resources.Count(vmi => vmi.Name == "1.1.0") != 0);

                // Filter: top - Negative Test
                listVersionsParamers.FilterExpression = "$top=0";
                vmextimg = _pirClient.VirtualMachineExtensionImages.ListVersions(listVersionsParamers);
                Assert.True(vmextimg.Resources.Count == 0);
            }
        }
 /// <summary>
 /// Gets a list of virtual machine extension image versions.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Compute.IVirtualMachineExtensionImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <returns>
 /// A list of virtual machine image resource information.
 /// </returns>
 public static Task<VirtualMachineImageResourceList> ListVersionsAsync(this IVirtualMachineExtensionImageOperations operations, VirtualMachineExtensionImageListVersionsParameters parameters)
 {
     return operations.ListVersionsAsync(parameters, CancellationToken.None);
 }
 /// <summary>
 /// Gets a list of virtual machine extension image versions.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Compute.IVirtualMachineExtensionImageOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <returns>
 /// A list of virtual machine image resource information.
 /// </returns>
 public static VirtualMachineImageResourceList ListVersions(this IVirtualMachineExtensionImageOperations operations, VirtualMachineExtensionImageListVersionsParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVirtualMachineExtensionImageOperations)s).ListVersionsAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (string.IsNullOrEmpty(this.Version))
            {
                var parameters = new VirtualMachineExtensionImageListVersionsParameters
                {
                    Location = Location.Canonicalize(),
                    PublisherName = PublisherName,
                    Type = Type,
                    FilterExpression = FilterExpression
                };

                VirtualMachineImageResourceList result = this.VirtualMachineExtensionImageClient.ListVersions(parameters);

                var images = from r in result.Resources
                             select new PSVirtualMachineExtensionImage
                             {
                                 RequestId = result.RequestId,
                                 StatusCode = result.StatusCode,
                                 Id = r.Id,
                                 Location = r.Location,
                                 Version = r.Name,
                                 PublisherName = this.PublisherName,
                                 Type = this.Type,
                                 FilterExpression = this.FilterExpression
                             };

                WriteObject(images, true);
            }
            else
            {

                var parameters = new VirtualMachineExtensionImageGetParameters
                {
                    Location = Location.Canonicalize(),
                    PublisherName = PublisherName,
                    Type = Type,
                    FilterExpression = FilterExpression,
                    Version = Version
                };

                VirtualMachineExtensionImageGetResponse result = this.VirtualMachineExtensionImageClient.Get(parameters);

                var image = new PSVirtualMachineExtensionImageDetails
                {
                    RequestId = result.RequestId,
                    StatusCode = result.StatusCode,
                    Id = result.VirtualMachineExtensionImage.Id,
                    Location = result.VirtualMachineExtensionImage.Location,
                    Name = result.VirtualMachineExtensionImage.Name,
                    HandlerSchema = result.VirtualMachineExtensionImage.HandlerSchema,
                    OperatingSystem = result.VirtualMachineExtensionImage.OperatingSystem,
                    ComputeRole = result.VirtualMachineExtensionImage.ComputeRole,
                    SupportsMultipleExtensions = result.VirtualMachineExtensionImage.SupportsMultipleExtensions,
                    VMScaleSetEnabled = result.VirtualMachineExtensionImage.VMScaleSetEnabled,
                    PublisherName = this.PublisherName,
                    Type = this.Type,
                    Version = this.Version
                };

                WriteObject(image);
            }
        }