April 9, 2012 at 10:33 am
Hi All
I have a doubt about it
I have a job running on SQL Server 2008 R2 that has a step with Powershell commands but it does not works, there is a problem when I use $() to encapsule a variable, for example I want to search files with this statement
$BackupFiles=get-childItem -name -include *_$($NumberOfWeek)_*
where $NumberOfWeek is used to get all BAK files that has in their name _14_
for example it must retrieve:
20120409_1129_14_database.bak
anything_14_database.bak
In the job there is a sintax error in the statement mentioned before, but when I don use "$()"
there is no problem
someone knows how can I solve it?
Thanks in advance
April 9, 2012 at 11:31 am
Hi
It was solved with other option
Instead of using *_$($NumberOfWeek)_*
I created three variables more
$Open="*_"
$Close="_*"
$PartialName=$Open+$NumberOfWeek+$Close
and it replaced that piece of statement
If someone has other solution using $(...), it would be great
April 9, 2012 at 12:39 pm
constant strings have to be quoted out i think,
so I'm fairly sure this is the right syntax:
$BackupFiles=get-childItem -name -include "*_"+$NumberOfWeek+"_*"
Lowell
April 9, 2012 at 2:23 pm
Thanks!
You are right!, my mistake was take all as an only string.
Although it is strange that SQL Server does not accept $()
because I tried it on Powershell and it works correctly, but when it was implemented on SQL Server, it threw an error
Anyway, thanks
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply