Насчет политики не совсем понял: нужно только выполнить команду в консольном окне 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!
}