Microsoft.PowerShell.GData.Dgc.GoogleAppService.RetrieveAllOUs C# (CSharp) Method

RetrieveAllOUs() public method

public RetrieveAllOUs ( Google.GData.Apps.AppsService UserService ) : string
UserService Google.GData.Apps.AppsService
return string
            public string RetrieveAllOUs(AppsService UserService)
            {
                var _token = UserService.Groups.QueryClientLoginToken();
                var OUService = new Dgc.GoogleAppService();
                var _custId = OUService.GetCustomerId(UserService);

                var uri = new Uri("https://apps-apis.google.com/a/feeds/orgunit/2.0/" + _custId + "?get=all");

                WebRequest WebRequest = WebRequest.Create(uri);
                WebRequest.Method = "GET";
                WebRequest.ContentType = "application/atom+xml; charset=UTF-8";
                WebRequest.Headers.Add("Authorization: GoogleLogin auth=" + _token);

                WebResponse WebResponse = WebRequest.GetResponse();

                if (WebResponse == null)
                {
                    throw new Exception("WebResponse is null");
                }
                StreamReader SR = new StreamReader(WebResponse.GetResponseStream());

                var _Result = SR.ReadToEnd().Trim();

                return _Result;
            }

Usage Example

Example #1
0
            protected override void ProcessRecord()
            {
                var OUService = new Dgc.GoogleAppService();
                string _Xml;

                if (_OuPath != null)
                {
                    _Xml = OUService.RetrieveOU(_OUService, _OuPath);
                }
                else
                {
                    _Xml = OUService.RetrieveAllOUs(_OUService);
                }

                    XmlDocument _XmlDoc = new XmlDocument();
                    _XmlDoc.InnerXml = _Xml;
                    XmlElement _Entry = _XmlDoc.DocumentElement;

                    WriteObject(_Entry);
            }