invoke-sqlcmd not outputting result of select query


this driving me nuts, possibly make invoke-sqlcmd not output result of simple select statement ? 

<#  repli rowguid renum via bcp     ############################  # must run @ subscriber #  ############################    -extrait les donnees des tables xxl pour la replication,   -zippe et envoye par bcp au subscriber  -importe dans ds tables temp et update les rowguid des tables (join par pk )     historique   2013-02-05  mbear  created   #>       ##############################################  # update/check following vars before running #  ##############################################  $local_path = "d:\temp" ; # local path storing bcp files   $dbn_pub ="arizona" #publisher dbname  $dbn_sub = "arizona" ; # subscriber db name   $script = "\\pp-sf1\devteam\dba\px428.replication\repli rowguid renum xxl\repli rowguid renum xxl.sql"   $publisher = "srv-ocmr\rec1ocm" ;  $xxl_tables = "supplier;journal;"#item_link;address_key;default_journal;item_site;item_key;item_text;item_technical_criteria;item_key;item_standard_cost;item_text;item_purchase;item_relation_info;item_inventory;item_sale;item_revision;item;fixed_price;item_criteria;item_status_history;";    $subsidiary = "162" ;  $subscriber = "srv-dev6" ;   $log_path = "c:\var\log" ;   ##############################################    if (-not (test-path $script)) {       write-output "script $script not found" ;       throw "script $script not found" ;       exit 1 ;       }    # execute extract , zip , push file @ publisher   $vararray = "publisher='$publisher'", "subsidiary='$subsidiary'", "subscriber='$subscriber'", "xxl_tables='$xxl_tables'", "local_path='$local_path'" ;   invoke-sqlcmd -variable $vararray -serverinstance $publisher -database $dbn_pub -inputfile $script -verbose -outputsqlerrors $true -querytimeout 1200 -connectiontimeout 5 -abortonerror        #proceed @ subscriber   set-location $local_path   if  (-not (test-path "bcprowguid.7z" )) {       write-output " bcprowguid.7z not found"    ;       throw "bcprowguid.7z not found"  ;       exit 1 ;       }     cmd /c 7za e -y bcprowguid.7z ;          foreach ($f in (gci "$local_path\*.bcprowguid")) {       $table_name = $f.basename ;      $temp_table_name = $f.basename +"_rowguid"  ;             #create empty tables ;      $qry = "if exists (select * sys.tables name = '$temp_table_name') drop table $temp_table_name; select top 0 $table_name" + "_id" + ", rowguid $temp_table_name dbo.$table_name;" ;      write-output $qry ;      invoke-sqlcmd -serverinstance $subscriber -database $dbn_sub -verbose -outputsqlerrors $true -query $qry -querytimeout 5 -connectiontimeout 5 -abortonerror;            #bcp temp tables       $bcp_string = "bcp $temp_table_name in $f -s $subscriber -d $dbn_sub -t -n -b 1000000 " ;      #$bcp_string = "exec master.dbo.xp_cmdshell 'bcp $temp_table_name in $f -s $subscriber -d $dbn_sub -t -n -b 1000000 ' " ;      write-output $bcp_string ;      cmd /c $bcp_string ;            #update rowguids joining temp tables       $qry = "update dbo." + $f.basename + " set rowguid = b.rowguid dbo." +$f.basename + " join dbo."  + $f.basename + "_rowguid b on a." + $f.basename + "_id = b." + $f.basename + "_id; select @@rowcount ;";      invoke-sqlcmd -serverinstance $subscriber -database $dbn_sub -verbose -outputsqlerrors $true -query $qry -querytimeout 5 -connectiontimeout 5 -abortonerror;        	#this driving me nuts   	invoke-sqlcmd -serverinstance $subscriber -database $dbn_sub -verbose -outputsqlerrors $true -query "select 'to hell it'" -querytimeout 5 -connectiontimeout 5 -abortonerror;        	      write-output "----------------------------------------------`n"            remove-item $f.fullname       }      

and getting :

7-zip (a) 9.20  copyright (c) 1999-2010 igor pavlov  2010-11-18    processing archive: bcprowguid.7z    extracting  journal.bcprowguid  extracting  supplier.bcprowguid    ok    files: 2  size:       323358  compressed: 283212  if exists (select * sys.tables name = 'journal_rowguid') drop table journal_rowguid; select top 0 journal_id, rowguid journal_rowguid dbo.journal;  bcp journal_rowguid in d:\temp\journal.bcprowguid -s srv-dev6 -d arizona -t -n -b 1000000     starting copy...    5559 rows copied.  network packet size (bytes): 4096  clock time (ms.) total     : 63     average : (88238.09 rows per sec.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ----------------------------------------------    if exists (select * sys.tables name = 'supplier_rowguid') drop table supplier_rowguid; select top 0 supplier_id, rowguid supplier_rowguid dbo.supplier;  bcp supplier_rowguid in d:\temp\supplier.bcprowguid -s srv-dev6 -d arizona -t -n -b 1000000     starting copy...    9839 rows copied.  network packet size (bytes): 4096  clock time (ms.) total     : 156    average : (63070.51 rows per sec.)                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ----------------------------------------------  

any ideas why !@#$%^&*() doing me ? 

the worst if running simple invoke-sqlcmd select 'x' query, output properly, expected.


does query trying run, work in sql?


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file