0

我有以下 Powershell 脚本:

$a = Get-Content C:\users\diana\desktop\names.txt

snmpwalk -v 2c -c root $a .1.3.6.1.2.1.25.3.3.1.2 > c:\users\diana\desktop\cpu.txt
snmpwalk -v 2c -c root $a .1.3.6.1.2.1.25.5.1.1.2 > c:\users\diana\desktop\ramvid.txt
snmpwalk -v 2c -c root $a .1.3.6.1.2.1.25.2.2 > c:\users\diana\desktop\ram.txt

get-content C:\users\diana\desktop\ramvid.txt | %{ [int]$used+=$_.split(' ')[3]; } ;     echo $used > C:\users\diana\desktop\naujas.txt
get-content C:\users\diana\desktop\ram.txt | %{ [int]$total=$_.split(' ')[3]; } ; echo     $total > C:\users\diana\desktop\ramfiltruotas.txt

[decimal]$b=($used*100)/$total
[math]::floor($b) > C:\users\diana\desktop\naujas2.txt


get-content C:\users\diana\desktop\cpu.txt | %{ [int]$array=$_.split(' ')[3]; }
$c=($array | Measure-Object -Average).average
echo $c > C:\users\diana\desktop\naujas3.txt

[void][system.reflection.Assembly]::LoadWithPartialName(“MySQL.Data”)

$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "database=db;server=localhost;Persist Security Info=false;user id=root;pwd= "
$myconnection.Open()
$command = $myconnection.CreateCommand()
$command.CommandText = "UPDATE db.server SET (cpu='$c',ram='$b') WHERE server_name like '192.168.95.139'";
$myconnection.Close()

代码的上半部分工作得很好,但是当涉及到 MySQL 时,什么也没有发生。没有一个错误,什么都没有,表没有更新。有人可以指出我的问题在哪里吗?

4

1 回答 1

0

看起来你没有执行命令,也许:

$command.ExecuteNonQuery()

我认为您还应该处理:

$command.Dispose()
于 2013-05-30T20:12:08.443 回答