コード例 #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListProductsRequest request;

            try
            {
                request = new ListProductsRequest
                {
                    TenancyId      = TenancyId,
                    SubscriptionId = SubscriptionId,
                    UsagePeriodKey = UsagePeriodKey,
                    OpcRequestId   = OpcRequestId,
                    Page           = Page,
                    Limit          = Limit,
                    SortOrder      = SortOrder,
                    SortBy         = SortBy,
                    Producttype    = Producttype
                };
                IEnumerable <ListProductsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.ProductCollection, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #2
0
        public override void Execute()
        {
            PSVpnGateway existingVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnGatewayObject))
            {
                existingVpnGateway     = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnGatewayResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingVpnGateway = this.GetVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.VpnGatewayNotFound);
            }
            string shouldProcessMessage = string.Format("Execute {0}VpnGateway for ResourceGroupName {1} VpnGateway {2}", ResourceManager.Common.AzureRMConstants.AzureRMPrefix, this.ResourceGroupName, this.Name);

            if (ShouldProcess(shouldProcessMessage, VerbsCommon.Reset))
            {
                this.VpnGatewayClient.Reset(this.ResourceGroupName, this.Name);

                var getVpnGateway = this.GetVpnGateway(this.ResourceGroupName, this.Name);
                WriteObject(getVpnGateway);
            }
        }
コード例 #3
0
        public override void ExecuteCmdlet()
        {
            PSSharedAccessAuthorizationRuleAttributes sasRule = new PSSharedAccessAuthorizationRuleAttributes();

            sasRule.Rights = new List <string>();

            foreach (string right in Rights)
            {
                sasRule.Rights.Add(right);
            }

            try
            {
                //Create a new Namespace Authorization Rule
                if (ParameterSetName.Equals(NamespaceAuthoRuleParameterSet))
                {
                    if (ShouldProcess(target: sasRule.Name, action: string.Format(Resources.CreateNamespaceAuthorizationrule, Name, Namespace)))
                    {
                        WriteObject(Client.CreateOrUpdateNamespaceAuthorizationRules(ResourceGroupName, Namespace, Name, sasRule));
                    }
                }

                // Create a new EventHub authorizationRule
                if (ParameterSetName.Equals(EventhubAuthoRuleParameterSet))
                {
                    if (ShouldProcess(target: sasRule.Name, action: string.Format(Resources.CreateEventHubAuthorizationrule, Name, EventHub)))
                    {
                        WriteObject(Client.CreateOrUpdateEventHubAuthorizationRules(ResourceGroupName, Namespace, EventHub, Name, sasRule));
                    }
                }
            }
            catch (Management.EventHub.Models.ErrorResponseException ex)
            {
                WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
            }
        }
コード例 #4
0
        public override void ExecuteCmdlet()
        {
            try
            {
                // Generate new Namespace List Keys for the specified AuthorizationRule
                if (ParameterSetName.Equals(NamespaceAuthoRuleParameterSet))
                {
                    if (ShouldProcess(target: RegenerateKey, action: string.Format(Resources.RegenerateKeyNamesapce, Name, Namespace)))
                    {
                        WriteObject(Client.SetRegenerateKeys(ResourceGroupName, Namespace, Name, RegenerateKey, KeyValue));
                    }
                }

                // Generate new Queue List Keys for the specified AuthorizationRule
                if (ParameterSetName.Equals(QueueAuthoRuleParameterSet))
                {
                    if (ShouldProcess(target: RegenerateKey, action: string.Format(Resources.RegenerateKeyQueue, Name, Queue)))
                    {
                        WriteObject(Client.NewQueueKey(ResourceGroupName, Namespace, Queue, Name, RegenerateKey, KeyValue));
                    }
                }

                // Generate new Topic List Keys for the specified AuthorizationRule
                if (ParameterSetName.Equals(TopicAuthoRuleParameterSet))
                {
                    if (ShouldProcess(target: RegenerateKey, action: string.Format(Resources.RegenerateKeyTopic, Name, Topic)))
                    {
                        WriteObject(Client.NewTopicKey(ResourceGroupName, Namespace, Topic, Name, RegenerateKey, KeyValue));
                    }
                }
            }
            catch (ErrorResponseException ex)
            {
                WriteError(ServiceBusClient.WriteErrorforBadrequest(ex));
            }
        }
コード例 #5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListExternalDatabaseConnectorsRequest request;

            try
            {
                request = new ListExternalDatabaseConnectorsRequest
                {
                    CompartmentId      = CompartmentId,
                    ExternalDatabaseId = ExternalDatabaseId,
                    OpcRequestId       = OpcRequestId,
                    Limit          = Limit,
                    Page           = Page,
                    SortBy         = SortBy,
                    SortOrder      = SortOrder,
                    LifecycleState = LifecycleState,
                    DisplayName    = DisplayName
                };
                IEnumerable <ListExternalDatabaseConnectorsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #6
0
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess(Name, Properties.Resources.RemoveIotHubCertificate))
            {
                if (ParameterSetName.Equals(InputObjectParameterSet))
                {
                    this.ResourceGroupName = this.InputObject.ResourceGroupName;
                    this.Name            = this.InputObject.Name;
                    this.CertificateName = this.InputObject.CertificateName;
                    this.Etag            = this.InputObject.Etag;
                }

                if (ParameterSetName.Equals(ResourceIdParameterSet))
                {
                    this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId);
                    this.Name            = IotHubUtils.GetIotHubName(this.ResourceId);
                    this.CertificateName = IotHubUtils.GetIotHubCertificateName(this.ResourceId);
                }
                try
                {
                    this.IotHubClient.Certificates.Delete(this.ResourceGroupName, this.Name, this.CertificateName, this.Etag);

                    if (PassThru.IsPresent)
                    {
                        this.WriteObject(true);
                    }
                }
                catch
                {
                    if (PassThru.IsPresent)
                    {
                        this.WriteObject(false);
                    }
                }
            }
        }
コード例 #7
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name          = resourceIdentifier.ResourceName;
                AccountName   = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
                DatabaseName  = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier);
                ContainerName = ResourceIdentifierExtensions.GetSqlContainerName(resourceIdentifier);
            }

            if (ShouldProcess(Name, "Deleting CosmosDB Sql Trigger"))
            {
                CosmosDBManagementClient.SqlResources.DeleteSqlTriggerWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, ContainerName, Name).GetAwaiter().GetResult();

                if (PassThru)
                {
                    WriteObject(true);
                }
            }

            return;
        }
コード例 #8
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListResourceCategoriesRequest request;

            try
            {
                request = new ListResourceCategoriesRequest
                {
                    NamespaceName = NamespaceName,
                    Categories    = Categories,
                    ResourceTypes = ResourceTypes,
                    ResourceIds   = ResourceIds,
                    SortOrder     = SortOrder,
                    SortBy        = SortBy,
                    Limit         = Limit,
                    Page          = Page,
                    OpcRequestId  = OpcRequestId
                };
                IEnumerable <ListResourceCategoriesResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.LogAnalyticsResourceCategoryCollection, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        public override void Execute()
        {
            if (ParameterSetName.Equals(VirtualRouterPeerParameterSetNames.ByVirtualRouterPeerInputObject, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(InputObject.Id);
                PeerName          = parsedResourceId.ResourceName;
                ResourceGroupName = parsedResourceId.ResourceGroupName;
                VirtualRouterName = parsedResourceId.ParentResource;
            }
            else if (ParameterSetName.Equals(VirtualRouterPeerParameterSetNames.ByVirtualRouterPeerResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(ResourceId);
                PeerName          = parsedResourceId.ResourceName;
                ResourceGroupName = parsedResourceId.ResourceGroupName;
                VirtualRouterName = parsedResourceId.ParentResource;
            }

            base.Execute();

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.RemovingResource, PeerName),
                Properties.Resources.RemoveResourceMessage,
                PeerName,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.VirtualRouterPeerings.Delete(ResourceGroupName, VirtualRouterName, PeerName);
                var vVirtualRouter      = this.NetworkClient.NetworkManagementClient.VirtualRouters.Get(ResourceGroupName, VirtualRouterName);
                var vVirtualRouterModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSVirtualRouter>(vVirtualRouter);
                vVirtualRouterModel.ResourceGroupName = this.ResourceGroupName;
                vVirtualRouterModel.Tag = TagsConversionHelper.CreateTagHashtable(vVirtualRouter.Tags);
                AddPeeringsToPSVirtualRouter(vVirtualRouter, vVirtualRouterModel, ResourceGroupName, this.VirtualRouterName);

                WriteObject(vVirtualRouterModel, true);
            });
        }
コード例 #10
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            RegisterLookupRequest request;

            if (ParameterSetName.Equals(FromFileSet))
            {
                RegisterLookupContentFileBody = System.IO.File.OpenRead(GetAbsoluteFilePath(RegisterLookupContentFileBodyFromFile));
            }


            try
            {
                request = new RegisterLookupRequest
                {
                    NamespaceName = NamespaceName,
                    Type          = Type,
                    RegisterLookupContentFileBody = RegisterLookupContentFileBody,
                    Name          = Name,
                    Description   = Description,
                    CharEncoding  = CharEncoding,
                    IsHidden      = IsHidden,
                    OpcRetryToken = OpcRetryToken,
                    OpcRequestId  = OpcRequestId,
                    Expect        = Expect
                };

                response = client.RegisterLookup(request).GetAwaiter().GetResult();
                WriteOutput(response, response.LogAnalyticsLookup);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #11
0
        public override void Execute()
        {
            base.Execute();
            string groupName          = this.ResourceGroupName;
            string networkWatcherName = this.Name;

            if (ParameterSetName.Contains("SetByResource"))
            {
                groupName          = this.NetworkWatcher.ResourceGroupName;
                networkWatcherName = this.NetworkWatcher.Name;
            }
            else if (ParameterSetName.Contains("SetByLocation"))
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

                if (networkWatcher == null)
                {
                    throw new ArgumentException("There is no network watcher in location {0}", this.Location);
                }

                groupName          = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                networkWatcherName = networkWatcher.Name;
            }

            ConfirmAction(
                Properties.Resources.RemoveResourceMessage,
                networkWatcherName,
                () =>
            {
                this.NetworkWatcherClient.Delete(groupName, networkWatcherName);
                if (PassThru)
                {
                    WriteObject(true);
                }
            });
        }
コード例 #12
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(InputObjectParameterSet))
            {
                ResourceGroupName = InputObject.ResourceGroupName;
                Name     = InputObject.Name;
                RuleName = InputObject.RuleName;
            }

            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name);

            ConfirmAction(
                string.Format(Resources.RemoveFirewallRule, RuleName, Name),
                Name,
                () =>
            {
                CacheClient.RemoveFirewallRule(ResourceGroupName, Name, RuleName);
                if (PassThru)
                {
                    WriteObject(true);
                }
            });
        }
コード例 #13
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListBillingSchedulesRequest request;

            try
            {
                request = new ListBillingSchedulesRequest
                {
                    CompartmentId       = CompartmentId,
                    SubscriptionId      = SubscriptionId,
                    SubscribedServiceId = SubscribedServiceId,
                    Limit            = Limit,
                    Page             = Page,
                    SortOrder        = SortOrder,
                    SortBy           = SortBy,
                    OpcRequestId     = OpcRequestId,
                    XOneOriginRegion = XOneOriginRegion
                };
                IEnumerable <ListBillingSchedulesResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #14
0
 public override void ExecuteApiManagementCmdlet()
 {
     if (ParameterSetName.Equals(AllApis))
     {
         WriteObject(Client.ApiList(Context), true);
     }
     else if (ParameterSetName.Equals(FindById))
     {
         string id = ApiId;
         if (ApiRevision != null)
         {
             id = ApiId.ApiRevisionIdentifier(ApiRevision);
         }
         WriteObject(Client.ApiById(Context.ResourceGroupName, Context.ServiceName, id));
     }
     else if (ParameterSetName.Equals(FindByName))
     {
         WriteObject(Client.ApiByName(Context, Name), true);
     }
     else if (ParameterSetName.Equals(FindByProductId))
     {
         WriteObject(Client.ApiByProductId(Context, ProductId), true);
     }
 }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListProfileLevelsRequest request;

            try
            {
                request = new ListProfileLevelsRequest
                {
                    CompartmentId          = CompartmentId,
                    CompartmentIdInSubtree = CompartmentIdInSubtree,
                    Name = Name,
                    RecommendationName = RecommendationName,
                    Limit        = Limit,
                    Page         = Page,
                    SortOrder    = SortOrder,
                    SortBy       = SortBy,
                    OpcRequestId = OpcRequestId
                };
                IEnumerable <ListProfileLevelsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.ProfileLevelCollection, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #16
0
        public override void ExecuteCmdlet()
        {
            var regenKey = new RegenerateAccessKeyParameters {
                Key = RegenerateKey
            };

            // Generate new Namespace List Keys for the specified AuthorizationRule
            if (ParameterSetName.Equals(NamespaceAuthoRuleParameterSet))
            {
                if (ShouldProcess(target: RegenerateKey, action: string.Format(Resources.RegenerateKeyNamesapce, Name, Namespace)))
                {
                    WriteObject(Client.SetRegenerateKeys(ResourceGroupName, Namespace, Name, RegenerateKey));
                }
            }

            // Generate new EventHub List Keys for the specified AuthorizationRule
            if (ParameterSetName.Equals(EventhubAuthoRuleParameterSet))
            {
                if (ShouldProcess(target: RegenerateKey, action: string.Format(Resources.RegenerateKeyEventHub, Name, EventHub)))
                {
                    WriteObject(Client.SetRegenerateKeys(ResourceGroupName, Namespace, EventHub, Name, RegenerateKey));
                }
            }
        }
コード例 #17
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListAvailableWindowsUpdatesForManagedInstanceRequest request;

            try
            {
                request = new ListAvailableWindowsUpdatesForManagedInstanceRequest
                {
                    ManagedInstanceId = ManagedInstanceId,
                    DisplayName       = DisplayName,
                    CompartmentId     = CompartmentId,
                    Limit             = Limit,
                    Page         = Page,
                    SortOrder    = SortOrder,
                    SortBy       = SortBy,
                    OpcRequestId = OpcRequestId,
                    IsEligibleForInstallation = IsEligibleForInstallation
                };
                IEnumerable <ListAvailableWindowsUpdatesForManagedInstanceResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #18
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(NamespaceInputObjectParameterSet))
            {
                ResourceGroupName = InputObject.ResourceGroup;
                Name = InputObject.Name;
            }
            else if (ParameterSetName.Equals(NamespaceResourceIdParameterSet))
            {
                LocalResourceIdentifier identifier = new LocalResourceIdentifier(InputObject.Id);
                ResourceGroupName = identifier.ResourceGroupName;
                Name = identifier.ResourceName;
            }

            // delete a namespace
            if (ShouldProcess(target: Name, action: string.Format(Resources.RemoveNamespace, Name, ResourceGroupName)))
            {
                var result = Client.BeginDeleteNamespace(ResourceGroupName, Name);
                if (PassThru)
                {
                    WriteObject(result);
                }
            }
        }
コード例 #19
0
        protected override void ProcessRecord()
        {
            var aclSpec = ParameterSetName.Equals(BaseParameterSetName)
                ? Acl.GetAclSpec()
                : string.Format("{0}{1}:{2}:{3}", Default ? "default:" : string.Empty, AceType, Id,
                                DataLakeStoreItemPermissionInstance.GetPermissionString(Permissions)).ToLowerInvariant();

            if (!Force.IsPresent)
            {
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(Resources.SettingDataLakeStoreItemAcl, Path.FullyQualifiedPath),
                    string.Format(Resources.SetDataLakeStoreItemAcl, Path.FullyQualifiedPath),
                    Path.FullyQualifiedPath,
                    () =>
                    DataLakeStoreFileSystemClient.ModifyAcl(Path.Path, Account,
                                                            aclSpec));
            }
            else
            {
                DataLakeStoreFileSystemClient.ModifyAcl(Path.Path, Account,
                                                        aclSpec);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess(Name, DPSResources.RemoveDeviceProvisioningService))
            {
                if (ParameterSetName.Equals(InputObjectParameterSet))
                {
                    this.ResourceGroupName = this.InputObject.ResourceGroupName;
                    this.Name = this.InputObject.Name;
                }

                if (ParameterSetName.Equals(ResourceIdParameterSet))
                {
                    this.ResourceGroupName = IotDpsUtils.GetResourceGroupName(this.ResourceId);
                    this.Name = IotDpsUtils.GetIotDpsName(this.ResourceId);
                }

                this.IotDpsClient.IotDpsResource.Delete(this.Name, this.ResourceGroupName);

                if (PassThru)
                {
                    this.WriteObject(true);
                }
            }
        }
コード例 #21
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListSchemasRequest request;

            try
            {
                request = new ListSchemasRequest
                {
                    TargetDatabaseId   = TargetDatabaseId,
                    OpcRequestId       = OpcRequestId,
                    Limit              = Limit,
                    Page               = Page,
                    SchemaName         = SchemaName,
                    SortOrder          = SortOrder,
                    SortBy             = SortBy,
                    IsOracleMaintained = IsOracleMaintained,
                    SchemaNameContains = SchemaNameContains
                };
                IEnumerable <ListSchemasResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #22
0
        public override void ExecuteApiManagementCmdlet()
        {
            byte[] rawBytes;
            if (ParameterSetName.Equals(FromFile))
            {
                FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxFilePath));
                if (!localFile.Exists)
                {
                    throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.PfxFilePath));
                }

                using (var certStream = File.OpenRead(localFile.FullName))
                {
                    rawBytes = new byte[certStream.Length];
                    certStream.Read(rawBytes, 0, rawBytes.Length);
                }
            }
            else if (ParameterSetName.Equals(Raw))
            {
                rawBytes = PfxBytes;
            }
            else
            {
                throw new InvalidOperationException(string.Format("Parameter set name '{0}' is not supported.", ParameterSetName));
            }

            // check for valid certificate file/bytes
            new X509Certificate2(rawBytes, PfxPassword);

            var certificate = Client.CertificateSet(Context, CertificateId, rawBytes, PfxPassword);

            if (PassThru)
            {
                WriteObject(certificate);
            }
        }
コード例 #23
0
        public override void ExecuteCmdlet()
        {
            if (this.ShouldProcess(Name, VerbsLifecycle.Start))
            {
                base.ExecuteCmdlet();
                ExecuteClientAction(() =>
                {
                    if (ParameterSetName.Equals(IdParameterSet) && string.IsNullOrEmpty(Name))
                    {
                        ResourceIdentifier parsedId = new ResourceIdentifier(Id);
                        this.ResourceGroupName      = parsedId.ResourceGroupName;
                        this.Name = parsedId.ResourceName;
                    }

                    var op = this.VirtualMachineClient.StartWithHttpMessagesAsync(
                        this.ResourceGroupName,
                        this.Name).GetAwaiter().GetResult();
                    var result       = ComputeAutoMapperProfile.Mapper.Map <PSComputeLongRunningOperation>(op);
                    result.StartTime = this.StartTime;
                    result.EndTime   = DateTime.Now;
                    WriteObject(result);
                });
            }
        }
コード例 #24
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListWorkRequestsRequest request;

            try
            {
                request = new ListWorkRequestsRequest
                {
                    CompartmentId = CompartmentId,
                    AgentId       = AgentId,
                    OpcRequestId  = OpcRequestId,
                    Page          = Page,
                    Limit         = Limit,
                    Status        = Status,
                    TimeCreatedGreaterThanOrEqualTo = TimeCreatedGreaterThanOrEqualTo,
                    SortOrder = SortOrder,
                    SortBy    = SortBy
                };
                IEnumerable <ListWorkRequestsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #25
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListAwrSnapshotsRequest request;

            try
            {
                request = new ListAwrSnapshotsRequest
                {
                    AwrHubId = AwrHubId,
                    AwrSourceDatabaseIdentifier = AwrSourceDatabaseIdentifier,
                    TimeGreaterThanOrEqualTo    = TimeGreaterThanOrEqualTo,
                    TimeLessThanOrEqualTo       = TimeLessThanOrEqualTo,
                    Limit        = Limit,
                    Page         = Page,
                    SortOrder    = SortOrder,
                    SortBy       = SortBy,
                    OpcRequestId = OpcRequestId
                };
                IEnumerable <ListAwrSnapshotsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.AwrSnapshotCollection, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #26
0
        public override void Execute()
        {
            base.Execute();
            if (!string.IsNullOrEmpty(this.Name))
            {
                PSPublicIpAddress publicIp;
                if (ParameterSetName.Contains("ScaleSetIp"))
                {
                    var publicIpVmss = PublicIpAddressClient.GetVirtualMachineScaleSetPublicIPAddress(
                        this.ResourceGroupName, this.VirtualMachineScaleSetName, this.VirtualMachineIndex, this.NetworkInterfaceName, this.IpConfigurationName, this.Name, this.ExpandResource);
                    publicIp = ToPsPublicIpAddress(publicIpVmss);
                    publicIp.ResourceGroupName = this.ResourceGroupName;
                    publicIp.Tag = TagsConversionHelper.CreateTagHashtable(publicIpVmss.Tags);
                }
                else
                {
                    publicIp = this.GetPublicIpAddress(this.ResourceGroupName, this.Name, this.ExpandResource);
                }

                WriteObject(publicIp);
            }
            else
            {
                IPage <PublicIPAddress> publicipPage;
                if (!string.IsNullOrEmpty(this.ResourceGroupName))
                {
                    if (ParameterSetName.Contains("ScaleSetIp"))
                    {
                        if (string.IsNullOrEmpty(this.VirtualMachineIndex))
                        {
                            publicipPage =
                                this.PublicIpAddressClient.ListVirtualMachineScaleSetPublicIPAddresses(
                                    this.ResourceGroupName,
                                    this.VirtualMachineScaleSetName);
                        }
                        else
                        {
                            publicipPage =
                                this.PublicIpAddressClient.ListVirtualMachineScaleSetVMPublicIPAddresses(
                                    this.ResourceGroupName,
                                    this.VirtualMachineScaleSetName,
                                    this.VirtualMachineIndex,
                                    this.NetworkInterfaceName,
                                    this.IpConfigurationName);
                        }
                    }
                    else
                    {
                        publicipPage = this.PublicIpAddressClient.List(this.ResourceGroupName);
                    }
                }
                else
                {
                    publicipPage = this.PublicIpAddressClient.ListAll();
                }

                // Get all resources by polling on next page link
                List <PublicIPAddress> publicIPList;
                if (ParameterSetName.Contains("ScaleSetIp"))
                {
                    if (string.IsNullOrEmpty(this.VirtualMachineIndex))
                    {
                        publicIPList = ListNextLink <PublicIPAddress> .GetAllResourcesByPollingNextLink(publicipPage, this.PublicIpAddressClient.ListVirtualMachineScaleSetPublicIPAddressesNext);
                    }
                    else
                    {
                        publicIPList = ListNextLink <PublicIPAddress> .GetAllResourcesByPollingNextLink(publicipPage, this.PublicIpAddressClient.ListVirtualMachineScaleSetVMPublicIPAddressesNext);
                    }
                }
                else
                {
                    publicIPList = ListNextLink <PublicIPAddress> .GetAllResourcesByPollingNextLink(publicipPage, this.PublicIpAddressClient.ListNext);
                }

                var psPublicIps = new List <PSPublicIpAddress>();

                // populate the publicIpAddresses with the ResourceGroupName
                foreach (var publicIp in publicIPList)
                {
                    var psPublicIp = this.ToPsPublicIpAddress(publicIp);
                    psPublicIp.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(publicIp.Id);
                    psPublicIps.Add(psPublicIp);
                }

                WriteObject(psPublicIps, true);
            }
        }
コード例 #27
0
        private PSExpressRouteConnection CreateExpressRouteConnection()
        {
            base.Execute();
            PSExpressRouteGateway expressRouteGateway = null;

            //// Resolve the ExpressRouteGateway
            if (ParameterSetName.Contains(CortexParameterSetNames.ByExpressRouteGatewayObject))
            {
                this.ResourceGroupName       = this.ExpressRouteGatewayObject.ResourceGroupName;
                this.ExpressRouteGatewayName = this.ExpressRouteGatewayObject.Name;
            }
            else if (ParameterSetName.Contains(CortexParameterSetNames.ByExpressRouteGatewayResourceId))
            {
                var parsedResourceId = new ResourceIdentifier(this.ParentResourceId);
                this.ResourceGroupName       = parsedResourceId.ResourceGroupName;
                this.ExpressRouteGatewayName = parsedResourceId.ResourceName;
            }

            if (string.IsNullOrWhiteSpace(this.ResourceGroupName) || string.IsNullOrWhiteSpace(this.ExpressRouteGatewayName))
            {
                throw new PSArgumentException(Properties.Resources.ExpressRouteGatewayRequiredToCreateExpressRouteConnection);
            }

            if (this.IsExpressRouteConnectionPresent(this.ResourceGroupName, this.ExpressRouteGatewayName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ChildResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName, this.ExpressRouteGatewayName));
            }

            //// At this point, we should have the resource name and the resource group for the parent ExpressRouteGateway resolved.
            //// This will throw not found exception if the ExpressRouteGateway does not exist
            expressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);
            if (expressRouteGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.ParentExpressRouteGatewayNotFound);
            }

            var peeringResourceId = new PSExpressRouteCircuitPeeringId()
            {
                Id = this.ExpressRouteCircuitPeeringId
            };

            PSExpressRouteConnection expressRouteConnection = new PSExpressRouteConnection
            {
                Name = this.Name,
                ExpressRouteCircuitPeering = peeringResourceId,
                EnableInternetSecurity     = this.EnableInternetSecurity.IsPresent
            };

            if (this.RoutingConfiguration != null)
            {
                if (this.RoutingConfiguration.VnetRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes.Any())
                {
                    throw new PSArgumentException(Properties.Resources.StaticRoutesNotSupportedForThisRoutingConfiguration);
                }

                expressRouteConnection.RoutingConfiguration = RoutingConfiguration;
            }

            // Set the auth key, if specified
            if (!string.IsNullOrWhiteSpace(this.AuthorizationKey))
            {
                expressRouteConnection.AuthorizationKey = this.AuthorizationKey;
            }

            // Set routing weight, if specified
            if (this.RoutingWeight > 0)
            {
                expressRouteConnection.RoutingWeight = this.RoutingWeight;
            }

            WriteVerbose(string.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));

            PSExpressRouteConnection connectionToReturn = null;

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                this.CreateOrUpdateExpressRouteConnection(this.ResourceGroupName, this.ExpressRouteGatewayName, expressRouteConnection, expressRouteGateway.Tag);

                var createdOrUpdatedExpressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);
                connectionToReturn = createdOrUpdatedExpressRouteGateway.ExpressRouteConnections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase));
            });

            return(connectionToReturn);
        }
コード例 #28
0
        public override void ExecuteCmdlet()
        {
            try
            {
                //Get Namespace Authorization Rule
                if (ParameterSetName.Equals(NamespaceAuthoRuleParameterSet))
                {
                    if (!string.IsNullOrEmpty(Name))
                    {
                        // Get a Namespace AuthorizationRule
                        PSSharedAccessAuthorizationRuleAttributes authRule = Client.GetNamespaceAuthorizationRules(ResourceGroupName, Namespace, Name);
                        WriteObject(authRule);
                    }
                    else
                    {
                        // Get all Namespace AuthorizationRules
                        IEnumerable <PSSharedAccessAuthorizationRuleAttributes> authRuleList = Client.ListNamespaceAuthorizationRules(ResourceGroupName, Namespace);
                        WriteObject(authRuleList, true);
                    }
                }


                // Get Queue authorizationRule
                if (ParameterSetName.Equals(QueueAuthoRuleParameterSet))
                {
                    if (!string.IsNullOrEmpty(Name))
                    {
                        // Get a Queue AuthorizationRule
                        PSSharedAccessAuthorizationRuleAttributes authRule = Client.GetServiceBusQueueAuthorizationRules(ResourceGroupName, Namespace, Queue, Name);
                        WriteObject(authRule);
                    }
                    else
                    {
                        // Get all Queue AuthorizationRules
                        IEnumerable <PSSharedAccessAuthorizationRuleAttributes> authRuleList = Client.ListServiceBusQueueAuthorizationRules(ResourceGroupName, Namespace, Queue);
                        WriteObject(authRuleList, true);
                    }
                }

                // Get Topic authorizationRule
                if (ParameterSetName.Equals(TopicAuthoRuleParameterSet))
                {
                    if (!string.IsNullOrEmpty(Name))
                    {
                        // Get a Topic AuthorizationRule
                        PSSharedAccessAuthorizationRuleAttributes authRule = Client.GetServiceBusTopicAuthorizationRules(ResourceGroupName, Namespace, Topic, Name);
                        WriteObject(authRule);
                    }
                    else
                    {
                        // Get all Topic AuthorizationRules
                        IEnumerable <PSSharedAccessAuthorizationRuleAttributes> authRuleList = Client.ListServiceBusTopicAuthorizationRules(ResourceGroupName, Namespace, Topic);
                        WriteObject(authRuleList, true);
                    }
                }

                // Get Alias authorizationRule
                if (ParameterSetName.Equals(AliasAuthoRuleParameterSet))
                {
                    if (!string.IsNullOrEmpty(Name))
                    {
                        // Get a Topic AuthorizationRule
                        PSSharedAccessAuthorizationRuleAttributes authRule = Client.GetAliasAuthorizationRules(ResourceGroupName, Namespace, AliasName, Name);
                        WriteObject(authRule);
                    }
                    else
                    {
                        // Get all Topic AuthorizationRules
                        IEnumerable <PSSharedAccessAuthorizationRuleAttributes> authRuleList = Client.ListAliasAuthorizationRules(ResourceGroupName, Namespace, AliasName);
                        WriteObject(authRuleList, true);
                    }
                }
            }
            catch (ErrorResponseException ex)
            {
                WriteError(ServiceBusClient.WriteErrorforBadrequest(ex));
            }
        }
コード例 #29
0
ファイル: RemoveAccess.cs プロジェクト: vevedh/NTFSSecurity
        protected override void ProcessRecord()
        {
            if (ParameterSetName.EndsWith("Simple"))
            {
                FileSystemSecurity2.ConvertToFileSystemFlags(appliesTo, out inheritanceFlags, out propagationFlags);
            }

            if (ParameterSetName.StartsWith("Path"))
            {
                foreach (var path in paths)
                {
                    FileSystemInfo item = null;

                    try
                    {
                        item = GetFileSystemInfo2(path);
                    }
                    catch (Exception ex)
                    {
                        WriteError(new ErrorRecord(ex, "ReadFileError", ErrorCategory.OpenError, path));
                    }

                    if (ParameterSetName == "PathSimple")
                    {
                        FileSystemSecurity2.ConvertToFileSystemFlags(appliesTo, out inheritanceFlags, out propagationFlags);
                    }

                    try
                    {
                        FileSystemAccessRule2.RemoveFileSystemAccessRule(item, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        try
                        {
                            var ownerInfo     = FileSystemOwner.GetOwner(item);
                            var previousOwner = ownerInfo.Owner;

                            FileSystemOwner.SetOwner(item, System.Security.Principal.WindowsIdentity.GetCurrent().User);

                            FileSystemAccessRule2.RemoveFileSystemAccessRule(item, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);

                            FileSystemOwner.SetOwner(item, previousOwner);
                        }
                        catch (Exception ex2)
                        {
                            WriteError(new ErrorRecord(ex2, "RemoveAceError", ErrorCategory.WriteError, path));
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteError(new ErrorRecord(ex, "RemoveAceError", ErrorCategory.WriteError, path));
                    }

                    if (passThru == true)
                    {
                        FileSystemAccessRule2.GetFileSystemAccessRules(item, true, true).ForEach(ace => WriteObject(ace));
                    }
                }
            }
            else
            {
                foreach (var sd in securityDescriptors)
                {
                    FileSystemAccessRule2.RemoveFileSystemAccessRule(sd, account.ToList(), accessRights, accessType, inheritanceFlags, propagationFlags);

                    if (passThru == true)
                    {
                        FileSystemAccessRule2.GetFileSystemAccessRules(sd, true, true).ForEach(ace => WriteObject(ace));
                    }
                }
            }
        }
コード例 #30
0
        public override void Execute()
        {
            base.Execute();

            PSVpnSite vpnSiteToCreate = new PSVpnSite();

            vpnSiteToCreate.ResourceGroupName = this.ResourceGroupName;
            vpnSiteToCreate.Name     = this.Name;
            vpnSiteToCreate.Location = this.Location;

            if (this.IsVpnSitePresent(this.ResourceGroupName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName));
            }

            //// Resolve the virtual wan
            if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
            {
                this.VirtualWanResourceGroupName = this.VirtualWan.ResourceGroupName;
                this.VirtualWanName = this.VirtualWan.Name;
            }
            else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanResourceId))
            {
                var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId);
                this.VirtualWanResourceGroupName = parsedWanResourceId.ResourceGroupName;
                this.VirtualWanName = parsedWanResourceId.ResourceName;
            }

            PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(this.VirtualWanResourceGroupName, this.VirtualWanName);

            if (resolvedVirtualWan == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanNotFound);
            }

            vpnSiteToCreate.VirtualWan = new PSResourceId()
            {
                Id = resolvedVirtualWan.Id
            };

            //// VpnSite device settings
            if (!string.IsNullOrWhiteSpace(this.DeviceModel) || !string.IsNullOrWhiteSpace(this.DeviceVendor))
            {
                vpnSiteToCreate.DeviceProperties = this.ValidateAndCreateVpnSiteDeviceProperties(
                    this.DeviceModel ?? string.Empty,
                    this.DeviceVendor ?? string.Empty,
                    this.LinkSpeedInMbps);
            }

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteIpAddress))
            {
                //// IpAddress
                System.Net.IPAddress ipAddress;
                if (!System.Net.IPAddress.TryParse(this.IpAddress, out ipAddress))
                {
                    throw new PSArgumentException(Properties.Resources.InvalidIPAddress);
                }

                vpnSiteToCreate.IpAddress = this.IpAddress;

                //// Bgp Settings
                if (this.BgpAsn > 0 || this.BgpPeeringWeight > 0 || !string.IsNullOrWhiteSpace(this.BgpPeeringAddress))
                {
                    vpnSiteToCreate.BgpSettings = this.ValidateAndCreatePSBgpSettings(this.BgpAsn, this.BgpPeeringWeight, this.BgpPeeringAddress);
                }
            }

            //// Address spaces
            if (this.AddressSpace != null && this.AddressSpace.Any())
            {
                vpnSiteToCreate.AddressSpace = new PSAddressSpace();
                vpnSiteToCreate.AddressSpace.AddressPrefixes = new List <string>();
                vpnSiteToCreate.AddressSpace.AddressPrefixes.AddRange(this.AddressSpace);
            }

            if (this.VpnSiteLink != null)
            {
                //// Use only link properties instead of Site properties.
                if (this.BgpAsn > 0 || this.BgpPeeringWeight > 0 || !string.IsNullOrWhiteSpace(this.BgpPeeringAddress) || this.LinkSpeedInMbps > 0 || !string.IsNullOrWhiteSpace(this.IpAddress))
                {
                    throw new PSArgumentException(Properties.Resources.VpnSitePropertyIsDeprecated);
                }

                vpnSiteToCreate.VpnSiteLinks = new List <PSVpnSiteLink>();
                vpnSiteToCreate.VpnSiteLinks.AddRange(this.VpnSiteLink);
            }

            if (this.O365Policy != null)
            {
                vpnSiteToCreate.O365Policy = this.O365Policy;
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateVpnSite(this.ResourceGroupName, this.Name, vpnSiteToCreate, this.Tag));
            });
        }