2016-12-01 3 views
0

clustername、nodename、stateのようないくつかのサーバーから情報を取得しています。インポートされたSQLテーブルを使用したGet-ClusterGroupとforeach

私はこのようなforeachループに名前をハードコーディングするとき、私は正しい出力に含まを取得することができます:

$clusters = "Cluster1", "Cluster2" 
foreach ($cluster in $clusters) { 
    Get-ClusterGroup -Cluster $cluster 
} 

が、私はその下のエラーを考え出すSQLテーブルから情報を引き出し、このバージョンを実行すると。

$clusters = $SQLServer = "DatawarehouseServer" #use Server\Instance for named SQL instances! 
$SQLDBName = "Datawarehouse" 
$SqlQuery = "SELECT clusters FROM dbo.clusters" 

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
$SqlConnection.ConnectionString = "Server=$SQLServer;Database=$SQLDBName;Integrated Security=True" 

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
$SqlCmd.CommandText = $SqlQuery 
$SqlCmd.Connection = $SqlConnection 

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter 
$SqlAdapter.SelectCommand = $SqlCmd 

$DataSet = New-Object System.Data.DataSet 
$SqlAdapter.Fill($DataSet) 

$SqlConnection.Close() 

clear 

$DataSet.Tables[0] 

foreach ($cluster in $clusters) { 
    Get-ClusterGroup -Cluster $cluster 
} 
WARNING: If you are running Windows PowerShell remotely, note that some failover 
clustering cmdlets do not work remotely. When possible, run the cmdlet locally 
and specify a remote computer as the target. To run the cmdlet remotely, try 
using the Credential Security Service Provider (CredSSP). All additional errors 
or warnings from this cmdlet might be caused by running it remotely. 
Get-ClusterGroup : The cluster service is not running. Make sure that the 
service is running on all nodes in the cluster. There are no more endpoints 
available from the endpoint mapper 
At line:26 char:2 
+ {Get-ClusterGroup -Cluster $cluster} 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ConnectionError: (:) [Get-ClusterGroup], ClusterCmdletException 
    + FullyQualifiedErrorId : ClusterEndpointNotRegistered,Microsoft.FailoverClusters.PowerShell.GetClusterGroupCommand.

私は今、これをしようとしているが、私はあなたがそれを見てどのように戻って近づいたりステップdepedantをステップになっているようです。これは、正しい情報を引き出すが、1つのクラスタのみのために:私はこれと逆方向にさらなるステップまたはステップを得るために管理しているコメントへの

ありがとう:

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
$SqlConnection.ConnectionString = "Server=Datawarehouseserver;Database=Datawarehouse;Integrated Security=True" 
$SqlConnection.Open() 
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
$SqlCmd.CommandText = "SELECT clusters FROM dbo.clusters" 
$SqlCmd.Connection = $SqlConnection 
$clustername = $SqlCmd.ExecuteScalar() 
$SqlConnection.Close() 
#Write-Output "Cluster is " $dbname 
clear 
foreach ($cluster in $clustername) { 
    Get-ClusterGroup -Cluster $cluster 
} 
+0

'$ clusters'は内容が" DatawarehouseServer "の単一の文字列であるため、ループはその名前のクラスタに接続しようとして失敗しています。 '$ DataSet'をループする必要があるように見えますが、私はSQLデータを頻繁にテストしなくてもうまく動作せず、私の前に適切なenvがありません。 –

+0

おかげさまで、これ以上の一歩を踏み出しました。 それは私がこのコメントビットを追加することはできません悪い試して、メインのポストを編集してください。 – GrumGrum

+0

'foreach($ DataSet.Tables [0] .clustersの$ cluster)' –

答えて

0

クラスタを反復処理する必要がありますSQLクエリによって返された名前ですが、変数$clusterにはその名前のリストが割り当てられません。

関連する問題