So I have some weird behavior going on and was wondering if someone might be able to explain it to me. In the following code I declare $dt as an array and the code works.
$datetime=Get-Date -format "MM-dd-yyyy" $SQLFilePath="\long_running_query_powershell_.sql" $dt=@() foreach($key in $DBhash.keys){ $Servervalue=$dbhash.item($key) $qDataRow=Invoke-Sqlcmd -ServerInstance $Servervalue -Database $key -InputFile $SQLFilePath #Check if data row has data to avoid trying to add properties to a null row if ($qDataRow -ne $null) { #Add the SQL server as a property to the data row $qDataRow | Add-Member -memberType noteProperty -name Server -value $Servervalue #Add the database as a property to the data row $qDataRow | Add-Member -memberType noteProperty -name Database -value $key $qDataRow | Add-Member -memberType noteProperty -name dtadded -value $datetime } $dt+=$qDataRow }#End For Loop
However if i do not decare the $dt=@() I get the following error:
Method invocation failed because [System.Data.DataRow] doesn't contain a method named 'op_Addition'.
I copied this code directly from another script that works fine. Below is the SQL query in case that helps:
select aa.Action ActionType, ar.ID, ar.ArtifactID, ar.Details, ar.UserID, ar.TimeStamp, ar.RequestOrigination, ar.RecordOrigination, ar.ExecutionTime from EDDSDBO.AuditRecord ar (nolock) INNER JOIN EDDSDBO.AuditAction AA ON AR.Action= AA.AuditActionID WHERE [TimeStamp] BETWEEN (select GETDATE () -1) and GETDATE() and ar.Action in (28,29,32,33,34,35,36,37,4,5,6) and ExecutionTime > 10000 ORDER BY [TimeStamp] DESC
I am just wondering if I am missing something. I have had 3 other people look at it and they cannot seem to figure out the difference either.