static void Main(string[] args) { try { var path = ConfigurationManager.AppSettings["dirPath"] ?? "C:\\1.0.1"; var loop = Convert.ToInt32(ConfigurationManager.AppSettings["loop"] ?? "0"); Console.WriteLine("path=>" + path); Console.WriteLine("loop=>" + loop); for (int i = 0; i < loop; i++) { var temp = path + "\\" + i; CompressUtil.DecompressFile($"{path}.zip", temp); var stopiis = @"get-website 'Default Web Site' | where-object { if ($_.Name -ne ''){stop-website $_.Name; get-website $_.Name;}};"; var script = $"Copy-Item -Path \"{temp + "\\1.0.1"}\" -Destination \"{temp + "\\copy"}\" -Recurse -Force"; PowerShellUtil.RunScript(new List <string> { "Get-ExecutionPolicy | Where-Object { if ($_ -nq 'Unrestricted') { set-executionpolicy Unrestricted -confirm:$false -force } };", stopiis, script }); } Console.WriteLine("执行完毕。"); } catch (Exception ex) { Logger.Error(ex.Message, ex); Console.WriteLine(ex.ToString()); } Console.ReadKey(); }
public void LoadFileRunScript() { var path = $"{AppDomain.CurrentDomain.BaseDirectory}\\test.ps1"; var result = PowerShellUtil.RunFileScript(path); Console.WriteLine(result); }
private void OpenPowerShellConsole() { SiteAuth site = Globals.SiteCollections.SingleOrDefault(s => s.Url.OriginalString.Equals(((SPClient.Site)_selectedContextMenuNode.Tag).Url, StringComparison.InvariantCultureIgnoreCase)); string psFile = PowerShellUtil.CreatePowerShellScript(site); System.Diagnostics.Process.Start("powershell.exe", string.Format("-NoExit -File \"{0}\"", psFile)); }
public void StartIISSite() { var scripts = new List <string> { "Start-IISSite -Name 'Default Web Site'" }; PowerShellUtil.RunScript(scripts); }
public void RunPowerShell() { var scripts = new List <string> { //"Get-IISSite -Name 'Default Web Site'" "Stop-IISSite -Name 'Default Web Site' -Confirm:$false" }; PowerShellUtil.RunScript(scripts); }
public void CopyItem_Test() { var path = "E:\\1.0.1"; for (int i = 0; i < 2; i++) { var temp = path + "\\" + i; CompressUtil.DecompressFile(@"E:\\1.0.1.zip", temp); var script = $"Copy-Item -Path \"{temp + "\\1.0.1"}\" -Destination \"{temp + "\\copy"}\" -Recurse -Force"; PowerShellUtil.RunScript(script); } }
public void CopyItem_SiteInfo_Success() { var dict = new Dictionary <string, object> { { "Path", @"E:\PublishOutput\*" }, { "Destination", @"E:\03_ReleaseWebSite\PowerShellSite" }, { "Recurse", true }, { "Force", true } }; PowerShellUtil.Run("Copy-Item", dict); }
public void LoadRunScript() { var result = PowerShellUtil.RunScript("Write-Host '本机站点列表';Get-IISSite;"); Console.WriteLine(result); }