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