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

            string resourceGroupName;
            string name;

            if (ParameterSetName.Contains("SetByResource"))
            {
                resourceGroupName = this.NetworkWatcher.ResourceGroupName;
                name = this.NetworkWatcher.Name;
            }
            else
            {
                resourceGroupName = this.ResourceGroupName;
                name = this.NetworkWatcherName;
            }

            if (!string.IsNullOrEmpty(this.PacketCaptureName))
            {
                PSPacketCaptureResult psPacketCapture = new PSPacketCaptureResult();
                psPacketCapture = this.GetPacketCapture(resourceGroupName, name, this.PacketCaptureName);

                var packetCaptureStatus = this.PacketCaptures.GetStatus(resourceGroupName, name, this.PacketCaptureName);

                PSGetPacketCaptureResult pcResult = new PSGetPacketCaptureResult();

                pcResult.BytesToCapturePerPacket = psPacketCapture.BytesToCapturePerPacket;
                pcResult.TotalBytesPerSession    = psPacketCapture.TotalBytesPerSession;
                pcResult.CaptureStartTime        = packetCaptureStatus.CaptureStartTime;
                pcResult.Etag    = psPacketCapture.Etag;
                pcResult.Filters = psPacketCapture.Filters;
                pcResult.Id      = psPacketCapture.Id;
                pcResult.Name    = psPacketCapture.Name;

                pcResult.PacketCaptureError = new List <string>();

                if (packetCaptureStatus.PacketCaptureError != null)
                {
                    foreach (var error in packetCaptureStatus.PacketCaptureError)
                    {
                        pcResult.PacketCaptureError.Add(error);
                    }
                }
                pcResult.PacketCaptureStatus = packetCaptureStatus.PacketCaptureStatus;
                pcResult.ProvisioningState   = psPacketCapture.ProvisioningState;
                pcResult.StopReason          = packetCaptureStatus.StopReason;
                pcResult.StorageLocation     = psPacketCapture.StorageLocation;
                pcResult.Target             = psPacketCapture.Target;
                pcResult.TimeLimitInSeconds = psPacketCapture.TimeLimitInSeconds;

                WriteObject(pcResult);
            }
            else
            {
                List <PSPacketCaptureResult> psPacketCaptureList = new List <PSPacketCaptureResult>();

                var packetCaptureList = this.PacketCaptures.List(resourceGroupName, name);
                var pcResultList      = new List <PSGetPacketCaptureResult>();

                foreach (var pc in packetCaptureList)
                {
                    PSPacketCaptureResult psPacketCapture = Mapper.Map <PSPacketCaptureResult>(pc);
                    psPacketCaptureList.Add(psPacketCapture);

                    var packetCaptureStatus   = this.PacketCaptures.GetStatus(resourceGroupName, name, psPacketCapture.Name);
                    var psPacketCaptureStatus = Mapper.Map <PSPacketCaptureStatus>(packetCaptureStatus);

                    PSGetPacketCaptureResult pcResult = new PSGetPacketCaptureResult();

                    pcResult.BytesToCapturePerPacket = psPacketCapture.BytesToCapturePerPacket;
                    pcResult.TotalBytesPerSession    = psPacketCapture.TotalBytesPerSession;
                    pcResult.CaptureStartTime        = psPacketCaptureStatus.CaptureStartTime;
                    pcResult.Etag               = psPacketCapture.Etag;
                    pcResult.Filters            = psPacketCapture.Filters;
                    pcResult.Id                 = psPacketCapture.Id;
                    pcResult.Name               = psPacketCapture.Name;
                    pcResult.PacketCaptureError = new List <string>();

                    if (packetCaptureStatus.PacketCaptureError != null)
                    {
                        foreach (var error in packetCaptureStatus.PacketCaptureError)
                        {
                            pcResult.PacketCaptureError.Add(error);
                        }
                    }
                    pcResult.PacketCaptureStatus = psPacketCaptureStatus.PacketCaptureStatus;
                    pcResult.ProvisioningState   = psPacketCapture.ProvisioningState;
                    pcResult.StopReason          = psPacketCaptureStatus.StopReason;
                    pcResult.StorageLocation     = psPacketCapture.StorageLocation;
                    pcResult.Target             = psPacketCapture.Target;
                    pcResult.TimeLimitInSeconds = psPacketCapture.TimeLimitInSeconds;

                    pcResultList.Add(pcResult);
                }

                WriteObject(pcResultList, true);
            }
        }
        public override void Execute()
        {
            base.Execute();

            string resourceGroupName;
            string name;

            if (string.Equals(this.ParameterSetName, "SetByLocation", StringComparison.OrdinalIgnoreCase))
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

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

                resourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                name = networkWatcher.Name;
            }
            else if (string.Equals(this.ParameterSetName, "SetByResource", StringComparison.OrdinalIgnoreCase))
            {
                resourceGroupName = this.NetworkWatcher.ResourceGroupName;
                name = this.NetworkWatcher.Name;
            }
            else
            {
                resourceGroupName = this.ResourceGroupName;
                name = this.NetworkWatcherName;
            }

            if (ShouldGetByName(resourceGroupName, PacketCaptureName))
            {
                PSPacketCaptureResult psPacketCapture = new PSPacketCaptureResult();
                psPacketCapture = this.GetPacketCapture(resourceGroupName, name, this.PacketCaptureName);

                PSGetPacketCaptureResult pcResult = new PSGetPacketCaptureResult();

                try
                {
                    var packetCaptureStatus = this.PacketCaptures.GetStatus(resourceGroupName, name, this.PacketCaptureName);
                    pcResult.CaptureStartTime = packetCaptureStatus.CaptureStartTime;

                    pcResult.PacketCaptureError = new List <string>();

                    if (packetCaptureStatus.PacketCaptureError != null)
                    {
                        foreach (var error in packetCaptureStatus.PacketCaptureError)
                        {
                            pcResult.PacketCaptureError.Add(error);
                        }
                    }
                    pcResult.PacketCaptureStatus = packetCaptureStatus.PacketCaptureStatus;
                    pcResult.StopReason          = packetCaptureStatus.StopReason;
                }
                catch
                {
                    pcResult.CaptureStartTime    = null;
                    pcResult.PacketCaptureError  = null;
                    pcResult.PacketCaptureStatus = null;
                    pcResult.StopReason          = null;
                }
                finally
                {
                    pcResult.BytesToCapturePerPacket = psPacketCapture.BytesToCapturePerPacket;
                    pcResult.TotalBytesPerSession    = psPacketCapture.TotalBytesPerSession;
                    pcResult.Etag               = psPacketCapture.Etag;
                    pcResult.Filters            = psPacketCapture.Filters;
                    pcResult.Id                 = psPacketCapture.Id;
                    pcResult.Name               = psPacketCapture.Name;
                    pcResult.ProvisioningState  = psPacketCapture.ProvisioningState;
                    pcResult.StorageLocation    = psPacketCapture.StorageLocation;
                    pcResult.Target             = psPacketCapture.Target;
                    pcResult.TimeLimitInSeconds = psPacketCapture.TimeLimitInSeconds;
                }

                WriteObject(pcResult);
            }
            else
            {
                List <PSPacketCaptureResult> psPacketCaptureList = new List <PSPacketCaptureResult>();

                var packetCaptureList = this.PacketCaptures.List(resourceGroupName, name);
                var pcResultList      = new List <PSGetPacketCaptureResult>();

                foreach (var pc in packetCaptureList)
                {
                    PSPacketCaptureResult psPacketCapture = NetworkResourceManagerProfile.Mapper.Map <PSPacketCaptureResult>(pc);
                    psPacketCaptureList.Add(psPacketCapture);

                    PSGetPacketCaptureResult pcResult = new PSGetPacketCaptureResult();

                    try
                    {
                        var packetCaptureStatus   = this.PacketCaptures.GetStatus(resourceGroupName, name, psPacketCapture.Name);
                        var psPacketCaptureStatus = NetworkResourceManagerProfile.Mapper.Map <PSPacketCaptureStatus>(packetCaptureStatus);

                        pcResult.CaptureStartTime   = psPacketCaptureStatus.CaptureStartTime;
                        pcResult.PacketCaptureError = new List <string>();

                        if (packetCaptureStatus.PacketCaptureError != null)
                        {
                            foreach (var error in packetCaptureStatus.PacketCaptureError)
                            {
                                pcResult.PacketCaptureError.Add(error);
                            }
                        }
                        pcResult.PacketCaptureStatus = psPacketCaptureStatus.PacketCaptureStatus;
                        pcResult.StopReason          = psPacketCaptureStatus.StopReason;
                    }
                    catch
                    {
                        pcResult.CaptureStartTime    = null;
                        pcResult.PacketCaptureError  = null;
                        pcResult.PacketCaptureStatus = null;
                        pcResult.StopReason          = null;
                    }
                    finally
                    {
                        pcResult.BytesToCapturePerPacket = psPacketCapture.BytesToCapturePerPacket;
                        pcResult.TotalBytesPerSession    = psPacketCapture.TotalBytesPerSession;
                        pcResult.Etag               = psPacketCapture.Etag;
                        pcResult.Filters            = psPacketCapture.Filters;
                        pcResult.Id                 = psPacketCapture.Id;
                        pcResult.Name               = psPacketCapture.Name;
                        pcResult.StorageLocation    = psPacketCapture.StorageLocation;
                        pcResult.Target             = psPacketCapture.Target;
                        pcResult.TimeLimitInSeconds = psPacketCapture.TimeLimitInSeconds;
                        pcResult.ProvisioningState  = psPacketCapture.ProvisioningState;
                    }

                    pcResultList.Add(pcResult);
                }

                WriteObject(SubResourceWildcardFilter(PacketCaptureName, pcResultList), true);
            }
        }