Hi EveryoneI am writing a very basic scripts which pulls info from one DB and pushes it to another. I wont go into reasons for doing this etc.The pulling is working correctly and I am building an array of the results.When I do the following is when i run into issues:$data | ForEach-Object {Invoke-Sqlcmd -Database $database -ServerInstance $server -Query "insert into $table (SessionIdTime, SessionIdSeq) VALUES ('$_.SessionIdTime', '$_.SessionIdSeq')"}The results in the table come out as follows:SessionIdTime SessionIdSeqSystem.Data.DataRow.SessionIdTime System.Data.DataRow.SessionIdSeqSo it is recognising the $_ part but then it looks to me like the period (.) is causing the next part to be text. I have tried various ways of escaping it with no luck.I can get it to work by creating a variable for each one in the foreach loop but this seems inefficient i.e:$data | ForEach-Object {$SessionIDTime = $_.SessionIDTime ; $SessionIdSeq = $_.SessionIdSeq ; Invoke-Sqlcmd -Database $database -ServerInstance $server -Query "insert into $table (SessionIdTime, SessionIdSeq) VALUES ('$SessionIdTime', '$SessionIdSeq')"}Your assistance with this would be highly appreciated. RegardsBrendon
↧