文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Restart IIS With Powershell

Restart IIS With Powershell

时间:2011-03-25  来源:chunchill

 

 
[system.Reflection.Assembly]::LoadWithPartialName("System.ServiceProcess") | out-Null
 function Get-ServiceStartupMode
 {
     param([string]$servicename,[string]$serverName)
     $startMode= gwmi win32_service -filter "NAME = '$servicename'" -computername $serverName  | Select -Property StartMode
     $startMode
 }

function Get-DependentServices{
     Param([System.ServiceProcess.ServiceController]$MasterService)
     foreach($dependent in $MasterService.DependentServices)
     {
         $dependent
         Get-DependentServices $dependent
     }
 }
 
 
 function Restart-MainServices
 {
    Param($ServiceName = $(throw ‘$ServiceName is Required’))
     process
     {
         $Service = New-Object System.ServiceProcess.ServiceController($ServiceName,$_)
         $DependentServices = Get-DependentServices $Service
         
         if($Service.CanStop)
         {
            $Service.Stop()
            $Service.WaitForStatus("Stopped",(new-object system.TimeSpan(0,0,20)))
         }
         
         if($Service.status -eq "Stopped")
         { 
             Write-Host "===Main Service:$($Service.name) start==="
             $Service.Start()
             $Service.WaitForStatus("Running",(new-object system.TimeSpan(0,0,30)))
         }
         
         foreach($dependent in $DependentServices )
         {
             $dependent.Refresh()
             $startMode= Get-ServiceStartupMode -servicename $dependent.name -serverName $_
             if($startMode.StartMode -eq "Auto")
             {
                 Write-Host "===dependent Service:$($dependent.name) start==="+ $startMode.StartMode
                 if($dependent.status -ne "Running")
                 {
                     $dependent.Start()
                     $dependent.WaitForStatus("Running",(new-object system.TimeSpan(0,0,30)))
                 }
             }
             
         }
         $Service.Refresh()
         $Service
         $Service.DependentServices
      }
   
 }
 

 

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载