powershell v2.0 - Not able to connect to a remote SQL Server instance -
i trying find solution problem online no luck yet. hence posting question:
i running powershell
script fetch backup details sql servers
mentioned in notepad. script working fine sql servers
till 2008r2
. getting error while connecting sql server 2012/2014
. script running on windows server 2008
having sql server 2008r2
installed on it. request me troubleshoot it.
input file:e:\sachin\sql_servers2.txt
servername,servername,1433
$servers = get-content 'e:\sachin\sql_servers2.txt' #create new excel object using com $excel = new-object -comobject excel.application $excel.visible = $true $excel = $excel.workbooks.add() $sheet = $excel.worksheets.item(1) #counter variable rows $global:introw = 1 foreach ($sv in $servers) { # separate server , instance names $srvr = $sv.split(",") $server = $srvr[0] $instance = $srvr[1] $port = $srvr[2] getsqlinfo $server $instance $port function getsqlinfo { param ( [string]$svr, [string]$inst, [string]$port ) foreach ($instancename in $inst) { #create column headers $sheet.cells.item($introw,1) = "instance name:" $sheet.cells.item($introw,2) = $instancename $sheet.cells.item($introw,1).font.bold = $true $sheet.cells.item($introw,2).font.bold = $true $global:introw++ $sheet.cells.item($introw,1) = "database name" $sheet.cells.item($introw,2) = "last full backup" $sheet.cells.item($introw,3) = "last differential backup" $sheet.cells.item($introw,4) = "full backup age(days)" #format column headers ($col = 1; $col -le 4; $col++) { $sheet.cells.item($introw,$col).font.bold = $true $sheet.cells.item($introw,$col).interior.colorindex = 48 $sheet.cells.item($introw,$col).font.colorindex = 34 } $global:introw++ ####################################################### #this script gets sql server database information using powershell $connectionstring = "data source = $inst,$port; initial catalog = master; trusted_connection = true;" [system.reflection.assembly]::loadwithpartialname('microsoft.sqlserver.smo') | out-null # create smo connection instance $s = new-object ('microsoft.sqlserver.management.smo.server') $s.connectioncontext.connectionstring = $connectionstring $dbs = $s.databases #formatting using excel foreach ($db in $dbs)
error msg:
the following exception thrown when trying enumerate collection: "failed connect server .". @ e:\sachin\backupdetailsversion7.ps1:51 char:8 + foreach <<<< ($db in $dbs) + categoryinfo : notspecified: (:) [], extendedtypesystemexception + fullyqualifiederrorid : exceptioningetenumerator
pre-checks done:
- i able telnet target sql server server running script.
- i having access target sql server well.
- microsoft® windows powershell extensions microsoft® sql server® 2012 sp2,microsoft® sql server® 2012 sp2 shared management objects , microsoft® system clr types microsoft® sql server® 2012 sp2 installed on target server.
- execution policy set unrestricted on target server.
i able sql server details on target machine when checking locally, not able details other machine.
i suspecting whether there restriction/limitation connect between different sql server versions through powershell
(any kind of compatibility issue).
any help/suggestions highly appreciated. in advance. :)
Comments
Post a Comment