Hi all, i already googled this and tried allot but no succes yet. Perhaps i can find help here ? Here it goes:
i dont have to much expirience on powershell, i'm a DBA and i feel that powershel can help me in my daily job !
I need to restart servers via restart-computer and use a variable as the computer name. This variable comes from a select query on a database. however i always get " The RPC server is unavailable." I repeated the command and did write-host and found that my variable returns:
System.Data.DataRow
for each record in the database.
this is the code:
$BootRegime= 'TST'$RebootStatsServer = 'Dbserver01'$RebootStatsDB = 'Database01'$SelectQuery = "SELECT server FROM ServerStatus where regime ='$BootRegime'"$SqlConnection = New-Object System.Data.SqlClient.SqlConnection$SqlGetListConnection.ConnectionString = "Server=$RebootStatsServer;Database=$RebootStatsDB;Integrated Security=True"$SqlGetListConnection.open()$SqlGetListCmd = New-Object System.Data.SqlClient.SqlCommand$SqlGetlistCmd.CommandText = $SelectQuery$SqlGetListCmd.Connection = $SqlGetListConnection$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter$SqlAdapter.SelectCommand = $SqlgetlistCmd$DataSet = New-Object System.Data.DataSet$SqlAdapter.Fill($DataSet)$srv=$dataset.tables[0] Foreach ($server in $srv){write-host "$server"}$SqlGetListConnection.close()
ty in advance!
Kristof
I found that adding
| select -exp server
To the
$srv=$dataset.tables[0]
The servernames showed up.
But if i issue
Restart-compter -computername $server -force
i still get an rpc error , guessing that the value that is parsed tot the restart-computer comandlet is not the servername but something else.
Solved! I needed to TRIM the result not in the query but like this
$srv=($srv).trim()
case closed.