February 10, 2011
$SQLServerName="10.11.12.13"                        
$SQLDatabase="Inventory"             
            
$DBConnection=New-Object System.Data.SQLClient.SQLConnection             
$DBConnection.ConnectionString="Server=$SQLServerName;Database=$SQLDatabase;`
Trusted_Connection=False;User ID='sa';Password='password'"                       
$DBConnection.Open()                                   
$DBCommand=New-Object System.Data.SQLClient.SQLCommand            
$DBCommand.Connection = $DBConnection            
$SelectStatement="SELECT *, Server AS Expr1 FROM tblServer"                        
$DBCommand.CommandText=$SelectStatement                        
$DBResult=$DBCommand.ExecuteReader()                        
$ServerTable=New-Object system.data.datatable                        
$ServerTable.load($DBResult)                         
$list = $ServerTable | Where-Object {$_.Synlig -eq 'True'} | `
Select-Object Server,IP_adress | Sort-Object Server
foreach ($item in  $list) {$item}            

0 kommentarer: