Пример #1
0
 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();
 }
Пример #2
0
        public void LoadFileRunScript()
        {
            var path   = $"{AppDomain.CurrentDomain.BaseDirectory}\\test.ps1";
            var result = PowerShellUtil.RunFileScript(path);

            Console.WriteLine(result);
        }
Пример #3
0
        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));
        }
Пример #4
0
        public void StartIISSite()
        {
            var scripts = new List <string>
            {
                "Start-IISSite -Name 'Default Web Site'"
            };

            PowerShellUtil.RunScript(scripts);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        public void LoadRunScript()
        {
            var result = PowerShellUtil.RunScript("Write-Host '本机站点列表';Get-IISSite;");

            Console.WriteLine(result);
        }