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

RetrieveOU() public method

public RetrieveOU ( Google.GData.Apps.AppsService UserService, string OuPath ) : string
UserService Google.GData.Apps.AppsService
OuPath string
return string
            public string RetrieveOU(AppsService UserService, string OuPath)
            {
                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 + "/"+OuPath);

                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);
            }