Posts

Showing posts from May, 2016

Pass array from cmd.exe batch to powershell script

Consider the following script: array as parameter.ps1 #requires -version 2.0 [CmdletBinding()] param ( [parameter(Mandatory=$false)] [string[]] $data ) write-host "items in data array:" $data.count write-host "first item in data array:" $data[0] When calling from command line cmd.exe using the following command powershell -file ".\array as parameter.ps1" -data "data1","data2" outputs items in data array: 1 first item in data array: data1,data2 But when calling using the folloing command powershell -command "&{.\'array as parameter.ps1' -data 'data1','data2'}" outputs items in data array: 2 first item in data array: data1

Demo: Create a custom sql plan guide with maxdop 1 hint

create   table   dbo . PlanGuideTest (   Id   int   identity ( 1 , 1 )   primary   key ,    Data   varchar ( 100 )   not   null ) insert   dbo . PlanGuideTest   ( data )   values   ( 'a' ) , ( 'b' ) , ( 'c' ) , ( 'd' ) /* run this a couple of times and verify in execution plan that  QueryPlan DegreeOfParallelism="" is greater than 1 (this will not be the case if your server is not set up for paralellism)*/ exec   sp_executesql   N'select * from PlanGuideTest where Id between @p0 and @p1' , N'@p0 int,@p1 int' , 2 , 4 /* check which plan is used, remember that your original query might be altered before stored in cache, so check usecounts column. */ select   st . te...