public static List <string> GetDomainList()
        {
            var fileName = ApplicationDetails.ConfigurationFiles.EmailsDomain;

            if (!File.Exists(fileName))
            {
                //generate file
                var ps1    = new PowerShellCommands();
                var emails = ps1.GetDomainEmailAddresses();
                if (!emails.Any())
                {
                    throw new FileNotFoundException("Email list could not be generated");
                }

                //save to local disk
                using (var file = File.CreateText(fileName))
                {
                    var serializer = new JsonSerializer();
                    serializer.Formatting = Formatting.Indented;
                    serializer.Serialize(file, emails);
                    return(emails);
                }
            }

            var list = JsonConvert.DeserializeObject <List <string> >(File.ReadAllText(fileName));

            return(list);
        }
Esempio n. 2
0
        public IEnumerable <Site> GetSitesByAppPool(string server, string appPoolName)
        {
            var sb = new StringBuilder();

            sb.Append("$password = ConvertTo-SecureString Sp@cecow22@ -AsPlainText -Force; $Cred = New-Object System.Management.Automation.PSCredential (\"adminteddyh\", $password);");
            sb.Append($"invoke-command -Credential $Cred -computername {server} -scriptblock {{import-module WebAdministration; Get-WebApplication | Where-Object {{$_.ApplicationPool -eq \"{appPoolName}\"}};}};");
            return(PowerShellCommands <Site> .ExecuteScript(sb.ToString()));
        }
Esempio n. 3
0
        public IEnumerable <ApplicationPool> GetApplicationPools(string server, string username, string password)
        {
            var sb   = new StringBuilder();
            var list = new List <ApplicationPool>();

            sb.Append($"$password = ConvertTo-SecureString {password} -AsPlainText -Force; $Cred = New-Object System.Management.Automation.PSCredential (\"{username}\", $password);");
            sb.Append($"invoke-command -Credential $Cred -computername {server} -scriptblock {{import-module WebAdministration; get-childitem -Path IIS:\\AppPools | select name,state ;}};");

            list = PowerShellCommands <ApplicationPool> .ExecuteScript(sb.ToString()).ToList();

            list.ForEach(e => e.Sites = GetSitesByAppPool(server, e.Name));
            return(list);
        }