/// <summary>
 /// Contains the cmdlet's execution logic.
 /// </summary>
 private void RunCmdlet()
 {
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResources(),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resources => this.WriteObject(sendToPipeline: this.GetOutputObjects("PolicyDefinitionId", resources), enumerateCollection: true));
 }
示例#2
0
 /// <summary>
 /// Contains the cmdlet's execution logic.
 /// </summary>
 private void RunCmdlet()
 {
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResources(Constants.PolicyExemptionApiVersion),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resources => this.WriteObject(sendToPipeline: this.GetOutputPolicyExemptions(resources), enumerateCollection: true));
 }
示例#3
0
 /// <summary>
 /// Contains the cmdlet's execution logic.
 /// </summary>
 private void RunCmdlet()
 {
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResources(),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource => resource.ToPsObject("System.Management.Automation.PSCustomObject#DeploymentOperation")), enumerateCollection: true));
 }
 /// <summary>
 /// Contains the cmdlet's execution logic.
 /// </summary>
 private void RunCmdlet()
 {
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResourceGroups(),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resourceGroups => this.WriteObject(sendToPipeline: resourceGroups.CoalesceEnumerable().SelectArray(resourceGroup => resourceGroup.ToPsObject()), enumerateCollection: true));
 }
 /// <summary>
 /// Executes the cmdlet.
 /// </summary>
 protected override void OnProcessRecord()
 {
     base.OnProcessRecord();
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResources(),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resources => this.WriteObject(sendToPipeline: this.GetOutputObjects(resources), enumerateCollection: true));
 }
 /// <summary>
 /// Contains the cmdlet's execution logic.
 /// </summary>
 private void RunCmdlet()
 {
     WriteWarning("Find-AzureRmResourceGroup: This cmdlet will be deprecated in an upcoming breaking change release. The functionality of this cmdlet will be moved into Get-AzureRmResourceGroup.");
     PaginatedResponseHelper.ForEach(
         getFirstPage: () => this.GetResourceGroups(),
         getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
         cancellationToken: this.CancellationToken,
         action: resourceGroups => this.WriteObject(sendToPipeline: resourceGroups.CoalesceEnumerable().SelectArray(resourceGroup => resourceGroup.ToPsObject()), enumerateCollection: true));
 }
示例#7
0
        /// <summary>
        /// Contains the cmdlet's execution logic.
        /// </summary>
        private void RunCmdlet()
        {
            var listFilter = this.GetListFilter(this.Builtin, this.Custom);

            PaginatedResponseHelper.ForEach(
                getFirstPage: () => this.GetResources(listFilter),
                getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
                cancellationToken: this.CancellationToken,
                action: resources => this.WriteObject(sendToPipeline: this.GetFilteredOutputPolicySetDefinitions(listFilter, resources), enumerateCollection: true));
        }
        /// <summary>
        /// Contains the cmdlet's execution logic.
        /// </summary>
        private void RunCmdlet()
        {
            this.WriteWarning("The usability of Tag parameter in this cmdlet will be modified in a future release. This will impact creating, updating and appending tags for Azure resources. For more details about the change, please visit https://github.com/Azure/azure-powershell/issues/726#issuecomment-213545494");

            PaginatedResponseHelper.ForEach(
                getFirstPage: () => this.GetResourceGroups(),
                getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
                cancellationToken: this.CancellationToken,
                action: resourceGroups => this.WriteObject(sendToPipeline: resourceGroups.CoalesceEnumerable().SelectArray(resourceGroup => resourceGroup.ToPsObject()), enumerateCollection: true));
        }
示例#9
0
        /// <summary>
        /// Contains the cmdlet's execution logic.
        /// </summary>
        private void RunCmdlet()
        {
            if (this.OutputObjectFormat == ResourceObjectFormat.Legacy)
            {
                this.WriteWarning("This cmdlet is using the legacy properties object format. This format is being deprecated. Please use '-OutputObjectFormat New' and update your scripts.");
            }

            PaginatedResponseHelper.ForEach(
                getFirstPage: () => this.GetResources(),
                getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
                cancellationToken: this.CancellationToken,
                action: resources =>
            {
                Resource <JToken> resource;
                if (resources.CoalesceEnumerable().FirstOrDefault().TryConvertTo(out resource))
                {
                    var genericResources = resources.CoalesceEnumerable().Where(res => res != null).SelectArray(res => res.ToResource());

                    foreach (var batch in genericResources.Batch())
                    {
                        var items = batch;
                        if (this.ExpandProperties)
                        {
                            items = this.GetPopulatedResource(batch).Result;
                        }

                        var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject(this.OutputObjectFormat));
                        if (this.ExpandPermissions)
                        {
                            this.PopulatePermissions(powerShellObjects).Wait();
                        }

                        this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
                    }
                }
                else
                {
                    this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject(this.OutputObjectFormat)), enumerateCollection: true);
                }
            });

            if (this.errors.Count != 0)
            {
                foreach (var error in this.errors)
                {
                    this.WriteError(error);
                }
            }
        }
        /// <summary>
        /// Contains the cmdlet's execution logic.
        /// </summary>
        private void RunCmdlet()
        {
            WriteWarning("Find-AzureRmResource: This cmdlet will be deprecated in an upcoming breaking change release. The functionality of this cmdlet will be moved into Get-AzureRmResource.");
            this.DefaultApiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;

            if (!this.TenantLevel)
            {
                this.SubscriptionId = DefaultContext.Subscription.GetId();
            }

            PaginatedResponseHelper.ForEach(
                getFirstPage: () => this.GetResources(),
                getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
                cancellationToken: this.CancellationToken,
                action: resources =>
            {
                Resource <JToken> resource;
                if (resources.CoalesceEnumerable().FirstOrDefault().TryConvertTo(out resource))
                {
                    var genericResources = resources.CoalesceEnumerable().Where(res => res != null).SelectArray(res => res.ToResource());

                    foreach (var batch in genericResources.Batch())
                    {
                        var items = batch;
                        if (this.ExpandProperties)
                        {
                            items = this.GetPopulatedResource(batch).Result;
                        }

                        var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject());

                        this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
                    }
                }
                else
                {
                    this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject()), enumerateCollection: true);
                }
            });

            if (this.errors.Count != 0)
            {
                foreach (var error in this.errors)
                {
                    this.WriteError(error);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Contains the cmdlet's execution logic.
        /// </summary>
        private void RunCmdlet()
        {
            if (string.IsNullOrEmpty(this.ResourceId) && !this.TenantLevel)
            {
                this.SubscriptionId = DefaultContext.Subscription.Id;
            }

            PaginatedResponseHelper.ForEach(
                getFirstPage: () => this.GetResources(),
                getNextPage: nextLink => this.GetNextLink <JObject>(nextLink),
                cancellationToken: this.CancellationToken,
                action: resources =>
            {
                Resource <JToken> resource;
                if (resources.CoalesceEnumerable().FirstOrDefault().TryConvertTo(out resource))
                {
                    var genericResources = resources.CoalesceEnumerable().Where(res => res != null).SelectArray(res => res.ToResource());

                    foreach (var batch in genericResources.Batch())
                    {
                        var items = batch;
                        if (this.ExpandProperties)
                        {
                            items = this.GetPopulatedResource(batch).Result;
                        }

                        var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject());

                        this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
                    }
                }
                else
                {
                    this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject()), enumerateCollection: true);
                }
            });

            if (this.errors.Count != 0)
            {
                foreach (var error in this.errors)
                {
                    this.WriteError(error);
                }
            }
        }
        /// <summary>
        /// Populates the permissions on the resource.
        /// </summary>
        /// <param name="resource">The resource.</param>
        private async Task PopulatePermissions(PSObject resource)
        {
            try
            {
                var resourceId = resource.Properties["ResourceId"].Value.ToString();

                var resourceCollectionId = resourceId + ResourceIdUtility
                                           .GetResourceCollectionId(
                    subscriptionId: null,
                    resourceGroupName: null,
                    resourceType: null,
                    extensionResourceType: "Microsoft.Authorization/permissions");

                var apiVersion = await ApiVersionHelper
                                 .DetermineApiVersion(
                    profile : this.Profile,
                    providerNamespace : "Microsoft.Authorization",
                    resourceType : "permissions",
                    cancellationToken : this.CancellationToken.Value,
                    pre : this.Pre)
                                 .ConfigureAwait(continueOnCapturedContext: false);

                var permissions = PaginatedResponseHelper.Enumerate(
                    getFirstPage: () => this.GetPermissions(permissionCheckId: resourceCollectionId, apiVersion: apiVersion),
                    getNextPage: nextLink => this.GetNextLink <Permission>(nextLink),
                    cancellationToken: this.CancellationToken);

                resource.Properties.Add(new PSNoteProperty("Permissions", permissions));
            }
            catch (Exception ex)
            {
                if (ex.IsFatal())
                {
                    throw;
                }

                ex = (ex is AggregateException)
                    ? (ex as AggregateException).Flatten()
                    : ex;

                this.errors.Add(new ErrorRecord(ex, "ErrorExpandingPermissions", ErrorCategory.CloseError, resource));
            }
        }
        protected override void RunCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(this.Name))
            {
                if (string.IsNullOrWhiteSpace(this.ResourceGroupName))
                {
                    // If there is only web service name but no resource group name, it is invalid input.
                    throw new PSArgumentNullException(ResourceGroupName, Resources.MissingResourceGroupName);
                }

                // If this is a simple get web service by name operation, resolve it as such
                WebService service = this.WebServicesClient.GetAzureMlWebService(this.ResourceGroupName, this.Name, this.Region);
                this.WriteObject(service);
            }
            else
            {
                // This is a collection of web services get call, so determine which flavor it is
                Func <Task <ResponseWithContinuation <WebService[]> > >         getFirstServicesPageCall = () => this.WebServicesClient.GetAzureMlWebServicesBySubscriptionAsync(null, this.CancellationToken);
                Func <string, Task <ResponseWithContinuation <WebService[]> > > getNextPageCall          = nextLink => this.WebServicesClient.GetAzureMlWebServicesBySubscriptionAsync(nextLink, this.CancellationToken);

                if (!string.IsNullOrWhiteSpace(this.ResourceGroupName))
                {
                    // This is a call for resource retrieval within a resource group
                    getFirstServicesPageCall = () => this.WebServicesClient.GetAzureMlWebServicesBySubscriptionAndGroupAsync(this.ResourceGroupName, null, this.CancellationToken);
                    getNextPageCall          = nextLink => this.WebServicesClient.GetAzureMlWebServicesBySubscriptionAndGroupAsync(this.ResourceGroupName, nextLink, this.CancellationToken);
                }

                PaginatedResponseHelper.ForEach <WebService>(
                    getFirstPage: getFirstServicesPageCall,
                    getNextPage: getNextPageCall,
                    cancellationToken: this.CancellationToken,
                    action: webServices =>
                {
                    foreach (var service in webServices)
                    {
                        this.WriteObject(service, true);
                    }
                });
            }
        }