protected override void ProcessRecord()
        {
            base.ProcessRecord();

            Enum.TryParse(Location, out _location);
            var serviceUrl = new Uri(string.Format(UrlFactory.BaseUrl, Organization, _location, UrlFactory.OrgServiceQueryPath));

            // OAuth authentication, data connection
            if (ParameterSetName == "oauthdata")
            {
                var endpoint = UrlFactory.GetDiscoveryUrl(serviceUrl, ApiType.CustomerEngagement);
                var auth     = new OAuthHelper(endpoint, ClientId, RedirectUri);
                var service  = CrmConnection.GetConnection(serviceUrl, auth.AuthResult.AccessToken);
                SessionState.PSVariable.Set(SessionVariableFactory.OAuthData, auth);
                SessionState.PSVariable.Set(SessionVariableFactory.DataConnection, service);
            }
            // Cookie authentication, data connection
            else if (ParameterSetName == "webauth")
            {
                Enum.TryParse(AuthType, out Models.AuthenticationType authType);
                var webAuthCookies = WebAuthHelper.GetAuthenticatedCookies(serviceUrl.ToString(), authType);
                var service        = CrmConnection.GetConnection(serviceUrl, webAuthCookies);
                SessionState.PSVariable.Set(SessionVariableFactory.WebCookies, webAuthCookies);
                SessionState.PSVariable.Set(SessionVariableFactory.DataConnection, service);
            }
            // OAuth authentication, admin API
            else if (ParameterSetName == "oauthadmin")
            {
                serviceUrl = UrlFactory.GetServiceUrl(_location);
                var endpoint = UrlFactory.GetDiscoveryUrl(serviceUrl, ApiType.Admin);
                var auth     = new OAuthHelper(endpoint, ClientId, RedirectUri);
                SessionState.PSVariable.Set(SessionVariableFactory.OAuthAdmin, auth);
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            Enum.TryParse(Location, out _location);
            var serviceUrl = new Uri(string.Format(UrlFactory.BaseUrl, Organization, _location, UrlFactory.OrgServiceQueryPath));

            // OAuth authentication
            if (ParameterSetName == "oauth")
            {
                var endpoint = UrlFactory.GetDiscoveryUrl(serviceUrl, ApiType.CustomerEngagement);
                var auth     = new OAuthHelper(endpoint, ClientId, RedirectUri);
                _service = CrmConnection.GetConnection(serviceUrl, auth.AuthResult.AccessToken);
            }
            // Cookie authentication
            else if (ParameterSetName == "webauth")
            {
                Enum.TryParse(AuthenticationType, out Models.AuthenticationType authType);
                var webAuthCookies = WebAuthHelper.GetAuthenticatedCookies(serviceUrl.ToString(), authType);
                _service = CrmConnection.GetConnection(new Uri(serviceUrl, UrlFactory.OrgServiceQueryPath), webAuthCookies);
            }

            WriteObject(_service);
        }