Example #1
0
        public static void TestCredentails()
        {
            if (Program.doSPCredentialCheck)
            {
                //foreach of the site in the list
                foreach (string site in Program.SPSiteCollectionList)

                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    Helper.Log(string.Format("Checking Permissions on site: {0}", site));

                    //create client context
                    string Status = "";

                    try
                    {
                        ClientContext ctx = new ClientContext(site);
                        SharePointComponent.GetCreds(ref ctx);
                        ctx.Load(ctx.Web, w => w.Title);
                        ctx.ExecuteQuery();
                        Status = "Permission Check Passed !";
                        Helper.Log(Status);
                    }
                    catch (Exception e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Status = string.Format("Permission Check Failed ! error:{0}", e.Message);
                        Helper.Log(Status);
                    }
                }
            }

            Console.ResetColor();
        }
        public static string LogParserOutFolder = "";        // this is where the log parser will ouput the csv file with hits
        public static void Startup()
        {
            //this class will run all the one-time jobs at startup of application

            // 1. set the log file location at global
            GlobalLogFilepath = Helper.SetFilePath();

            // 2. is logging ON ?
            isLoggingOn = Helper.SetLogging();

            // 3. user will give all the list of site collection under which all the webs has to be detected
            SPSiteCollectionList = System.IO.File.ReadAllLines(ConfigurationManager.AppSettings["SPSiteCollectionFileLocation"]);

            //4. after detecting all the webs, we will flush it to a text file, for IIS module to pickup
            SPWeboutputFileWithPath = ConfigurationManager.AppSettings["SPWeboutputFileWithPath"];
            //empty the file
            Helper.ClearFileContents(SPWeboutputFileWithPath);

            // 5. sp username password
            SPUsername         = ConfigurationManager.AppSettings["SPUsername"];
            SPPasswordasString = ConfigurationManager.AppSettings["SPPassword"];
            SPPassword         = Helper.ConvertToSecureString(Program.SPPasswordasString);

            //6. should we check if the credentials are right?
            doSPCredentialCheck = bool.Parse(ConfigurationManager.AppSettings["doSPCredentialCheck"]);

            //run the sharepoint permissions test
            SharePointComponent.TestCredentails();

            // are we running for sharepoint online ?
            isSPO = bool.Parse(ConfigurationManager.AppSettings["isSPO"]);

            //whats the folder location where we want to save the .sql file?
            PSSQLFileLocation = ConfigurationManager.AppSettings["PSSQLFileLocation"];
            Helper.TestFolderExist(Program.PSScriptLocation);

            //where should the resulting .ps1 file be created?
            PSScriptLocation = ConfigurationManager.AppSettings["PSScriptLocation"];
            Helper.TestFolderExist(Program.PSScriptLocation);

            //where is the IIS logs folder, we assume that in this folder there are subfolders for each IIS website, each folders name has site's ID ( as in IIS)
            IISLogsFolder = ConfigurationManager.AppSettings["IISLogsFolder"];
            Helper.TestFolderExist(Program.IISLogsFolder);

            //where should the Log parser output its file ?
            LogParserOutFolder = ConfigurationManager.AppSettings["LogParserOutFolder"];
            Helper.TestFolderExist(Program.LogParserOutFolder);
        }
        static void Main(string[] args)
        {
            //initalise all variables for execution
            Startup();

            Helper.Log(".Starting application");

            Helper.Log("..Starting Step1- Querying SharePoint for All Webs/Nested Webs in SiteCollections");
            SharePointComponent.StartWork();

            Helper.Log("..Starting Step2- Quering IIS Logs for All the Webs");
            IISComponent.StartWork();

            Helper.Log(".Ending Application");
            Console.Read();
        }