Microsoft.Azure.Commands.Network.NetworkBaseCmdlet.GetResourceGroup C# (CSharp) Method

GetResourceGroup() public static method

public static GetResourceGroup ( string resourceId ) : string
resourceId string
return string
        public static string GetResourceGroup(string resourceId)
        {
            const string resourceGroup = "resourceGroups";

            var startIndex = resourceId.IndexOf(resourceGroup, StringComparison.OrdinalIgnoreCase) + resourceGroup.Length + 1;
            var endIndex = resourceId.IndexOf("/", startIndex, StringComparison.OrdinalIgnoreCase);

            return resourceId.Substring(startIndex, endIndex - startIndex);
        }
    }

Usage Example

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

            if (!string.IsNullOrEmpty(this.Name))
            {
                PSNetworkInterface networkInterface;

                if (ParameterSetName.Equals("ScaleSetNic"))
                {
                    networkInterface = this.GetScaleSetNetworkInterface(this.ResourceGroupName, this.VirtualMachineScaleSetName, this.VirtualMachineIndex, this.Name);
                }
                else
                {
                    networkInterface = this.GetNetworkInterface(this.ResourceGroupName, this.Name);
                }

                WriteObject(networkInterface);
            }
            else if (!string.IsNullOrEmpty(this.ResourceGroupName))
            {
                IEnumerable <MNM.NetworkInterface> nicList;

                if (ParameterSetName.Equals("ScaleSetNic"))
                {
                    nicList = this.NetworkInterfaceClient.ListVirtualMachineScaleSetNetworkInterfaces(this.ResourceGroupName, this.VirtualMachineScaleSetName);
                }
                else
                {
                    nicList = this.NetworkInterfaceClient.List(this.ResourceGroupName);
                }

                var psNetworkInterfaces = new List <PSNetworkInterface>();

                foreach (var nic in nicList)
                {
                    var psNic = this.ToPsNetworkInterface(nic);
                    psNic.ResourceGroupName = this.ResourceGroupName;
                    psNetworkInterfaces.Add(psNic);
                }

                WriteObject(psNetworkInterfaces, true);
            }

            else
            {
                var nicList = this.NetworkInterfaceClient.ListAll();

                var psNetworkInterfaces = new List <PSNetworkInterface>();

                foreach (var nic in nicList)
                {
                    var psNic = this.ToPsNetworkInterface(nic);
                    psNic.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(psNic.Id);
                    psNetworkInterfaces.Add(psNic);
                }

                WriteObject(psNetworkInterfaces, true);
            }
        }
All Usage Examples Of Microsoft.Azure.Commands.Network.NetworkBaseCmdlet::GetResourceGroup