Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Ikari

Новый участник


Сообщения: 18
Благодарности: 0

Профиль | Отправить PM | Цитировать


Изображения
Тип файла: jpg Снимок1.JPG
(56.1 Kb, 17 просмотров)
Тип файла: jpg Снимок2.JPG
(44.3 Kb, 16 просмотров)
Тип файла: jpg Снимок3.JPG
(68.9 Kb, 12 просмотров)
Тип файла: jpg Снимок4.JPG
(61.6 Kb, 12 просмотров)
Тип файла: jpg Снимок5.JPG
(71.7 Kb, 13 просмотров)
Тип файла: jpg Снимок6.JPG
(75.8 Kb, 14 просмотров)

Насчет политики не совсем понял: нужно только выполнить команду в консольном окне PS в %WINDIR%\system32\windowspowershell\v1.0\powershell.exe или %WINDIR%\SysWOW64\windowspowershell\v1.0\powershell.exe ?
=======
Вот что получилось у меня:
читать дальше »
Код: Выделить весь код
############################################################################# 
#Script to ping remote and reboot modem (zyxel) 
#Original name: QRS_modemReboot.ps1
#
#Parameters: not required
#Version: 0.0
#
#Author: as QRS
############################################################################## 


new-eventlog -source QRS_shutdown -logname Application -ea SilentlyContinue

  function Ping-Address {
    PROCESS {
      $ping = $false
      $results = Get-WmiObject -query `
      "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
      foreach ($result in $results) {
        if ($results.StatusCode -eq 0) {
          $ping = $true
        }
      }
      if ($ping -eq $true) {
        Write-Output $_
      }
    }
  }


## Read output from a remote host 
function GetOutput 
{ 
    ## Create a buffer to receive the response 
    $buffer = new-object System.Byte[] 1024 
    $encoding = new-object System.Text.AsciiEncoding 

    $outputBuffer = "" 
    $foundMore = $false 

    ## Read all the data available from the stream, writing it to the 
    ## output buffer when done. 
    do 
    { 
        ## Allow data to buffer for a bit 
        start-sleep -m 1000 

        ## Read what data is available 
        $foundmore = $false 
        $stream.ReadTimeout = 1000 

        do 
        { 
            try 
            { 
                $read = $stream.Read($buffer, 0, 1024) 

                if($read -gt 0) 
                { 
                    $foundmore = $true 
                    $outputBuffer += ($encoding.GetString($buffer, 0, $read)) 
                } 
            } catch { $foundMore = $false; $read = 0 } 
        } while($read -gt 0) 
    } while($foundmore) 

    $outputBuffer 
} 


function execTelnet{

 [string] $output = "" 
 $remoteHost = '192.168.1.1'
 $port = 23;
 $currentInput = @"
admin

sys reboot
"@

 $commandDelay = 500

 write-host "Connecting to $remoteHost on port $port" 
 trap { Write-Error "Could not connect to remote computer: $_"; exit } 

 $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) 

 $stream = $socket.GetStream() 
    
 $writer = new-object System.IO.StreamWriter $stream 

 ## Receive the output that has buffered so far 
 $SCRIPT:output += GetOutput 
 foreach($line in $currentInput) 
 { 
   $writer.WriteLine($line) 
   $writer.Flush() 
   Start-Sleep -m $commandDelay 
   $SCRIPT:output += GetOutput 
 } 

 ## Close the streams 
 $writer.Close() 
 $stream.Close() 
 $output
}

$ping = (('ya.ru','google.com') | Ping-Address)
if($ping -eq $null) {
 $noping = (Get-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart").noPing
 if($noping -eq 1){
   write-eventlog -logname Application -source QRS_shutdown -eventID 03 -entrytype Information -message "Ping lost." -category 1
   . execTelnet
   Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 0
 }else{
   Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 1
   write-eventlog -logname Application -source QRS_shutdown -eventID 03 -entrytype Information -message "Ping lost first time." -category 1
 }
}else{
 New-Item -path "HKCU:\Software\" -name "QRS" -type directory -ea 0
 New-Item -path "HKCU:\Software\QRS\" -name "ADSLrestart" -type directory -ea 0
 Set-ItemProperty -path "HKCU:\Software\QRS\ADSLrestart" -name "noPing" -value 0
 write-host Ping is ok!
}

-------
Нужный человек в нужном месте может изменить мир (hl2)


Отправлено: 10:23, 07-06-2010 | #7