s_admin
23-03-2009, 11:47
Здрастье!
Вобщем есть такая проблема...написал тут простенький скрипт, и столкнулся вот с чем.
trap { write-host "Error connecting to $computer" -fore red
"$computer" | out-file c:\errors.txt -append continue }
$computers = Get-Content "D:\PC.txt"
foreach ( $computer in $computers ) {
get-wmiobject win32_operatingsystem -comp $computer -ea stop }
В файлике PC.txt есть имена машин: comp1, comp2, comp3. comp1 и comp3 существуют в сети, comp2 - нет. По идее, скрипт должен выдать ошибку на втором, записать ее в лог и продолжить скрипт с comp3. Но после comp2, выполнение скрипта завершается.... чего не так я сделал?
Если делать вот так:
trap { write-host "Error connecting to $computer" -fore red
"$computer" | out-file c:\errors.txt -append continue }
$computer = "comp1" get-wmiobject win32_operatingsystem -comp $computer -ea stop
$computer = "comp2" get-wmiobject win32_operatingsystem -comp $computer -ea stop
$computer = "comp3" get-wmiobject win32_operatingsystem -comp $computer -ea stop
то все работает. А вот с условием foreach нет.
Заранее спасибо.
Вобщем есть такая проблема...написал тут простенький скрипт, и столкнулся вот с чем.
trap { write-host "Error connecting to $computer" -fore red
"$computer" | out-file c:\errors.txt -append continue }
$computers = Get-Content "D:\PC.txt"
foreach ( $computer in $computers ) {
get-wmiobject win32_operatingsystem -comp $computer -ea stop }
В файлике PC.txt есть имена машин: comp1, comp2, comp3. comp1 и comp3 существуют в сети, comp2 - нет. По идее, скрипт должен выдать ошибку на втором, записать ее в лог и продолжить скрипт с comp3. Но после comp2, выполнение скрипта завершается.... чего не так я сделал?
Если делать вот так:
trap { write-host "Error connecting to $computer" -fore red
"$computer" | out-file c:\errors.txt -append continue }
$computer = "comp1" get-wmiobject win32_operatingsystem -comp $computer -ea stop
$computer = "comp2" get-wmiobject win32_operatingsystem -comp $computer -ea stop
$computer = "comp3" get-wmiobject win32_operatingsystem -comp $computer -ea stop
то все работает. А вот с условием foreach нет.
Заранее спасибо.